<?php  namespace samson\core{ interface iCore { const RENDER_STANDART = 1; const RENDER_ARRAY = 2; const RENDER_VARIABLE = 3; public function resources( & $path, & $ls = array(), & $files = null ); public function render( $view_path, $view_data = array() ); public function async( $async = NULL ); public function template( $template = NULL ); public function path( $path = NULL ); public function & active( iModule & $module = NULL ); public function & module( & $module = NULL ); public function load( $path = NULL ); public function unload( $id ); public function start( $default ); } interface iModule { const VD_POINTER_DEF = ''; const VD_HTML = '__html__'; const CTR_BASE = '__base'; const CTR_UNI = '__handler'; const CTR_POST = '__post'; const CTR_PUT = '__put'; const CTR_DELETE = '__delete'; const PROC_PREFIX = '_'; const OBJ_PREFIX = '__'; const ASYNC_PREFIX = 'async_'; public function title( $title = NULL ); public function id(); public function path( $value = NULL ); public function output( $view_path = null ); public function render( $controller = NULL ); public function action( $method_name = NULL ); public function view( $view_path ); public function html( $value = NULL ); public function set( $field, $value = NULL ); } interface iModuleViewable { function toView( $prefix = NULL, array $restricted = array() ); } interface iExternalModule { public function prepare(); public function init( array $params = array() ); public function & copy(); } interface iModuleCompressable { function beforeCompress( & $obj = null, array & $code = null ); function afterCompress( & $obj = null, array & $code = null ); } interface iURL { const S_BOOKMARK_KEY = '_url_bookmark'; const S_PREVIOUS_KEY = '_url_previous'; const S_PREVIOUS_SIZE = 10; public function bookmark( $name = NULL, $return = false ); public function build( $url = '' ); public function base( $url_base = NULL ); public function redirect( $url = NULL ); public function history( $number = 0 ); } class AutoLoader { const NS_SEPARATOR = '\\'; public static $moduleMap = array(); protected static $fileCache = array(); protected static $nameSpaces = array(); public static function oldClassName($className) { if ($className{0} == self::NS_SEPARATOR) { $className = substr($className, 1); } return strtolower(str_replace(self::NS_SEPARATOR, '_', $className)); } public static function className($className, $namespace = null) { if (class_exists($className, false)) { return $className; } else if (strpos($className, '\\') === false) { $className = $namespace.'\\'.$className; } return __SAMSON_PHP_OLD ? self::oldClassName($className) : $className; } public static function getOnlyClass($className) { if (($p = strrpos( $className, self::NS_SEPARATOR )) !== false) { $className = substr($className, $p + 1); } return $className; } public static function getOnlyNameSpace($className) { if (($p = strrpos( $className, self::NS_SEPARATOR )) !== false ) { $className = substr( $className, 0, $p); } return $className; } protected static function oldModule($className, $nameSpace, & $file = null) { $ns = str_replace(self::NS_SEPARATOR, '/', $nameSpace); if (isset(self::$moduleMap[$nameSpace])) { $path = self::$moduleMap[$nameSpace]; } else { $locations = null; $path = null; foreach (array('php', 'js', 'cms', 'social', 'commerce') as $type) { $locations = array( __SAMSON_VENDOR_PATH.str_replace('samson/', 'samsonos/', $ns).'/'.strtolower($className), __SAMSON_VENDOR_PATH.str_replace('samson/', 'samsonos/', $ns), __SAMSON_VENDOR_PATH.str_replace('samson/', 'samsonos/'.$type.'/', $ns), __SAMSON_VENDOR_PATH.str_replace('samson/', 'samsonos/'.$type.'/', $ns).'/api', __SAMSON_VENDOR_PATH.str_replace('samson/', 'samsonos/'.$type.'_', $ns), strpos($ns, 'cms') !== false ? __SAMSON_VENDOR_PATH.'samsonos/cms_api' : '_', strpos($ns, 'cms') !== false ? __SAMSON_VENDOR_PATH.'samsonos/cms/api' : '_', __SAMSON_CWD__.__SAMSON_MODEL_PATH, ); foreach ($locations as $location) { if (file_exists($location)) { $path = $location; break 2; } } } } if (!isset($path)) { return e('Class location ## not found by namespace ##', E_SAMSON_CORE_ERROR, array($className, $ns)); } $path .= '/'; if (!isset(self::$fileCache[$nameSpace])) { self::$fileCache[$nameSpace] = File::dir($path, 'php'); } if (sizeof($files = preg_grep('/\/'.$className.'\.php/i', self::$fileCache[$nameSpace]))) { if (sizeof($files) > 1) { return e('Cannot autoload class(##), too many files matched ##', E_SAMSON_CORE_ERROR, array($className,$files)); } $file = end($files); return true; } return e('Cannot autoload class(##), class file not found in ##', E_SAMSON_CORE_ERROR, array($className,$path)); } public static function load($class) { $className = self::getOnlyClass($class); $nameSpace = self::getOnlyNameSpace($class ); if ($nameSpace != __NAMESPACE__) { $path = __SAMSON_VENDOR_PATH.str_replace('\\', DIRECTORY_SEPARATOR, $nameSpace).DIRECTORY_SEPARATOR.$className.'.php'; if (file_exists($path)) { ($path); } else if(self::oldModule($className, $nameSpace, $path)) { ($path); } else { return e('Class name ## not found', E_SAMSON_CORE_ERROR, $class); } } else { (__DIR__.'/'.$className.'.php'); } return true; } } define('CONFIG_ALL', 0); define('CONFIG_DEV', 1); define('CONFIG_TEST', 2); define('CONFIG_PROD', 3); class Config { public static $type = CONFIG_ALL; public static $data = array(); public static function implement($moduleID, & $module) { $configuration = & self::$data[$moduleID]; if (isset($configuration)) { foreach ($configuration as $k => $v) { if (property_exists(get_class($module), $k)) { $module->$k = $v; } } } } public static function load(\samson\core\iCore & $core, $type = NULL) { foreach(\samson\core\File::dir($core->path().__SAMSON_CONFIG_PATH) as $configFile) { if(stripos($configFile, 'Config.php') !== false) { ($configFile); } } if( isset( $type ) ) self::$type = $type; foreach (get_declared_classes() as $class ) { if( in_array( 'samson\core\Config', class_parents($class))) { $o = new $class(); $config = & self::$data[$o->__module]; if ($o->__type === self::$type) { $config = array_merge( get_object_vars($o), array( '__path' => $o->__path ) ); } else if($o->__type === CONFIG_ALL) { $config = array_merge( get_object_vars($o), isset($config) ? $config : array(), array( '__path' => $o->__path ) ); } } } } public static function init(\samson\core\iCore & $core = NULL) { if (sizeof(self::$data) === 0) { self::load($core); } foreach (self::$data as $module => $cfg) { if (isset($cfg['__path']) && isset($cfg['__path']{0})) { $path = normalizepath(__DIR__.'/'.$cfg['__path']); if (!file_exists($path)) { $path = normalizepath( getcwd().'/'.$cfg['__path']); } if (file_exists($path)) { $core->load($path); } } } } protected $__type = CONFIG_ALL; protected $__module; protected $__path; } class Event { protected static $listeners = array(); public static function listeners() { return self::$listeners; } public static function fire($key, $params = array(), $signal = false) { $key = strtolower($key); $pointer = & self::$listeners[$key]; if (isset($pointer)) { if (isset($params)) { $params = is_array($params) ? $params : array(&$params); } if ($signal === false) { foreach ($pointer as $handler) { $args = array_merge($params, $handler[1]); call_user_func_array($handler[0], $args); } } else { return call_user_func_array($pointer[0][0], array_merge($params, $pointer[0][1])); } } return null; } public static function subscribe($key, $handler, $params = array()) { $key = strtolower($key); $pointer = & self::$listeners[$key]; if (!isset($pointer)) { $pointer = array(); } if (isset($params)) { $params = is_array($params) ? $params : array(&$params); } $pointer[] = array($handler, & $params); } } define( 'E_SAMSON_FATAL_ERROR', 900 ); define( 'E_SAMSON_SRC_ERROR', 901 ); define( 'E_SAMSON_CORE_ERROR', 999 ); define( 'E_SAMSON_ACTIVERECORD_ERROR', 998 ); define( 'E_SAMSON_SQL_ERROR', 997 ); define( 'E_SAMSON_CMS_ERROR', 996 ); define( 'E_SAMSON_AUTH_ERROR', 995 ); define( 'E_SAMSON_SNAPSHOT_ERROR', 994 ); define( 'E_SAMSON_RENDER_ERROR', 993 ); define( 'D_SAMSON_DEBUG', 10000 ); define( 'D_SAMSON_ACTIVERECORD_DEBUG', 10001 ); define( 'D_SAMSON_CMS_DEBUG', 10002 ); define( 'D_SAMSON_AUTH_DEBUG', 10003 ); class Error { public static $OUTPUT = TRUE; private $errors = array(); public static $css = NULL; public static $shutdown_handler; public function __construct() { error_reporting( false ); set_error_handler( array( $this, 'handler' ) ); register_shutdown_function( array( $this, 'shutdown' ) ); if( file_exists(__SAMSON_PATH__.'css/error.css') ) self::$css = file_get_contents( __SAMSON_PATH__.'css/error.css'); } public function shutdown() { if( isset( self::$shutdown_handler ) && ( call_user_func( self::$shutdown_handler ) === false )) return null; $this->output(); } public function output() { $lerror = error_get_last(); $fatal_codes = array( 1, 4, 16, 64 ); if( isset($lerror) && in_array( $lerror['type'], $fatal_codes ) ) { $this->handler( $lerror['type'], $lerror['message'], $lerror['file'], $lerror['line'], null, debug_backtrace(FALSE) ); } $html = ''; if( sizeof($this->errors) && isset( self::$css{0})) $html .= '<style>'.self::$css.'</style>'; $index = 0; foreach ($this->errors as & $error) { if( $error['class'] == '_core_debug') $html .= '<div class="_core_error _core_debug">'.$error['message'].'</div>'; else { $id = rand(0, 999999999).rand(0,9999999999); $html .= '<div class="_core_error '.$error['class'].'">
						<input type="checkbox" id="eb_'.$id.'" class="_core_error_check_box">
						<label for="eb_'.$id.'" class="_core_error_label">
					    <span class="_core_error_type">'.$error['type'].'</span>
					    <span class="_core_error_file">'.$error['file'].'</span>
					    <span class="_core_error_line">, стр. '.$error['line'].'</span>
					    '.$error['message'].'</label>
					</div>'; } unset($this->errors[ $index++ ]); } if( $index ) $html .= '<div style="clear:both;"></div>'; if( self::$OUTPUT ) echo $html; } public function handler( $errno , $error_msg, $errfile = NULL, $errline = NULL, $errcontext = NULL, $backtrace = NULL ) { if( ! self::$OUTPUT ) return NULL; if( ! isset( $backtrace ) ) $backtrace = debug_backtrace( FALSE ); if( !isset($error_msg) || ($error_msg == 'Undefined') || (!isset($error_msg{0})) ) return FALSE; if( isset($backtrace[ 1 ]) ) $callee = & $backtrace[ 1 ]; if( isset( $callee['function'] ) ) $error_msg = '<u>' . $callee['function'] . '()</u>&nbsp;' . $error_msg; if( isset( $callee['class'] ) ) $error_msg = '<u>' . $callee['class'] . '</u>::' . $error_msg; if( ! isset( $errfile ) ) $errfile = isset($callee['file']) ? $callee['file'] : ''; if( ! isset( $errline ) ) $errline = isset($callee['line']) ? $callee['line'] : ''; $error_msg = debug_backtrace_html( $error_msg, $backtrace ); $error_type = ''; $error_css = ''; switch ( $errno ) { case E_ERROR: $error_type = 'Фатальная ошибка'; $error_css='_core_fatal_error'; break; case E_CORE_ERROR: $error_type = 'Ошибка ядра PHP'; $error_css='_core_fatal_error'; break; case E_SAMSON_FATAL_ERROR: $error_type = 'Фатальная ошибка SamsonPHP'; $error_css='_core_fatal_error'; break; case E_SAMSON_SNAPSHOT_ERROR: $error_type = 'Ошибка создания отпечатка SamsonPHP'; break; case E_SAMSON_RENDER_ERROR: $error_type = 'SamsonPHP rendering error'; break; case E_PARSE: $error_type = 'Ошибка парсинга'; $error_css='_core_fatal_error'; break; case E_COMPILE_ERROR: $error_type = 'Ошибка компиляции'; $error_css='_core_fatal_error'; break; case E_USER_ERROR: $error_type = 'Пользовательская ошибка'; break; case E_WARNING: $error_type = 'Предупреждение'; break; case E_CORE_WARNING: $error_type = 'Предупреждение ядра PHP'; break; case E_COMPILE_WARNING: $error_type = 'Предупреждение компиляции';break; case E_USER_WARNING: $error_type = 'Пользовательское предупреждение'; break; case E_NOTICE: $error_type = 'Замечание'; break; case E_USER_NOTICE: $error_type = 'Пользовательское замечание'; break; case E_STRICT: $error_type = 'Строгая ошибка'; break; case E_RECOVERABLE_ERROR: $error_type = 'Востанавливаемая ошибка'; break; case E_DEPRECATED: $error_type = 'Использование устаревших данных'; break; case E_USER_DEPRECATED: $error_type = 'Старая функция'; break; case E_SAMSON_CORE_ERROR: $error_type = 'Ошибка SamsonPHP'; break; case E_SAMSON_ACTIVERECORD_ERROR: $error_type = 'Ошибка ActiveRecord'; break; case E_SAMSON_CMS_ERROR: $error_type = 'Ошибка SamsonCMS'; break; case D_SAMSON_DEBUG: $error_type = 'Отладка SamsonPHP'; $error_css='_core_debug'; break; case D_SAMSON_CMS_DEBUG: $error_type = 'Отладка SamsonCMS'; $error_css='_core_debug'; break; case D_SAMSON_ACTIVERECORD_DEBUG: $error_type = 'Отладка ActiveRecord'; $error_css='_core_debug'; break; default: $error_type = 'Неизвестная ошибка'; } $this->errors[] = $this->toError( $errno, $error_type.':', $error_msg, $errfile, $errline, $error_css ); if( $errno == E_SAMSON_FATAL_ERROR ) die(); } private function toError( $errno , $desc, $error_msg, $errfile = NULL, $errline = NULL, $class = NULL ) { return array( 'code' => $errno, 'type' => $desc, 'file' => $errfile, 'line' => $errline, 'message' => $error_msg, 'class' => $class ); } } class Core implements iCore { public static $resourceIgnorePath = array( '.git', '.svn', '.settings', '.idea', 'vendor', 'upload', 'out', 'i18n', __SAMSON_CACHE_PATH, __SAMSON_TEST_PATH, ); public $load_path_stack = array(); public $load_stack = array(); public $load_module_stack = array(); public $render_stack = array(); public $map; public $module_stack = array(); protected $active = null; protected $async = FALSE; protected $template_path = __SAMSON_DEFAULT_TEMPLATE; protected $system_path = __SAMSON_CWD__; protected $view_path = ''; public $render_mode = self::RENDER_STANDART; public function resources( & $path, & $ls = array(), & $files = null ) { if (!isset( $this->load_path_stack[$path])) { $resourceMap = ResourceMap::get($path); $ls['resources'] = $resourceMap->resources; $ls['controllers'] = $resourceMap->controllers; $ls['models'] = $resourceMap->models; $ls['views'] = $resourceMap->views; $ls['php'] = $resourceMap->php; $this->load_path_stack[ $path ] = & $ls; return true; } else { $ls = $this->load_path_stack[ $path ]; } return false; } public function load($path = NULL, $module_id = null) { $resourceMap = ResourceMap::get($path); if (isset($resourceMap->module[0])) { $controllerPath = $resourceMap->module[1]; $moduleClass = $resourceMap->module[0]; $module_id = isset($module_id) ? $module_id : AutoLoader::oldClassName($moduleClass); if (file_exists($controllerPath)) { ($controllerPath); } foreach ($resourceMap->controllers as $controller) { ($controller); } $connector = new $moduleClass($path, $module_id, $ls = $resourceMap->toLoadStackFormat()); $module_id = $connector->id(); ; if (!$connector->prepare()) { } $ns = AutoLoader::getOnlyNameSpace($moduleClass); $this->load_module_stack[$module_id] = $ls; if( !isset($this->load_stack[ $ns ])) $this->load_stack[ $ns ] = & $ls; else $this->load_stack[ $ns ] = array_merge_recursive ( $this->load_stack[ $ns ], $ls ); $parent_class = get_parent_class( $connector ); if ($parent_class !== AutoLoader::className('samson\core\ExternalModule')) { foreach ($this->module_stack as & $m){ if (get_class($m) == $parent_class) { $connector->parent = & $m; } } } } else { e('Cannot load module from: "##"', D_SAMSON_DEBUG, $path); } return $this; } public function render( $__view, $__data = array() ) { if( is_array( $__data ))extract( $__data ); ob_start(); $__template_view = $__view; if (locale() != SamsonLocale::DEF) { $__template_view = str_replace( __SAMSON_VIEW_PATH, __SAMSON_VIEW_PATH.locale().'/', $__template_view ); } switch ( $this->render_mode ) { case self::RENDER_STANDART: if( file_exists( $__template_view ) ) include( $__template_view ); else if( file_exists( $__view ) ) include( $__view ); else e('Cannot render view(##,##) - file doesn\'t exists', E_SAMSON_RENDER_ERROR, array( $__view, $this->view_path ) ); break; case self::RENDER_ARRAY: $views = & $GLOBALS['__compressor_files']; if( isset($views[ $__template_view ]) && file_exists( $views[ $__template_view ] ) ) include( $views[ $__template_view ] ); else if( isset($views[ $__view ]) && file_exists( $views[ $__view ] ) ) include( $views[ $__view ] ); else e('Cannot render view(##,##) - file doesn\'t exists', E_SAMSON_RENDER_ERROR, array( $views[ $__view ], $this->view_path ) ); break; case self::RENDER_VARIABLE: $views = & $GLOBALS['__compressor_files']; if( isset($views[ $__template_view ])) eval(' ?>'.$views[ $__template_view ].'<?php '); else if( isset($views[ $__view ])) eval(' ?>'.$views[ $__view ].'<?php '); else e('Cannot render view(##,##) - view variable not found', E_SAMSON_RENDER_ERROR, array( $__view, $this->view_path ) ); break; } $html = ob_get_contents(); ob_end_clean(); ; foreach ( $this->render_stack as & $renderer ) { $html = call_user_func( $renderer, $html, $__data, $this->active ); } return $html ; } public function async( $async = NULL ) { if( func_num_args() ){$this->async = $async; return $this;} else return $this->async; } public function template( $template = NULL ) { if( func_num_args() ){ $this->template_path = $this->active->path().$template; } return $this->template_path; } public function path( $path = NULL ) { if (func_num_args()) { $this->template_path = $path.$this->template_path; $this->system_path = $path; return $this; } return $this->system_path; } public function & active(iModule & $module = null) { $old = & $this->active; if (isset($module)) { $this->active = & $module; } return $old; } public function & module( & $_module = NULL ) { $ret_val = null; if( !isset($_module) && isset( $this->active ) ) $ret_val = & $this->active; else if( is_object( $_module ) ) $ret_val = & $_module; else if( is_string( $_module ) && isset( $this->module_stack[ $_module ] ) ) $ret_val = & $this->module_stack[ $_module ]; if( $ret_val === null ) e('Не возможно получить модуль(##) системы', E_SAMSON_CORE_ERROR, array( $_module ) ); return $ret_val; } public function unload( $_id ) { if( isset($this->module_stack[ $_id ]) ) { $m = & $this->module_stack[ $_id ]; $ns = nsname( get_class($m) ); if( isset( $this->load_stack[ $ns ] )) unset($this->load_stack[ $ns ]); unset( $this->module_stack[ $_id ] ); } } public function start($default) { m("core")->init(); m("activerecord")->init(); m("samsonjs")->init(); m("cmsapi")->init();; $this->template($this->template_path); $result = A_FAILED; url()->router($this, $result, $default);; if (!isset($result) || $result == A_FAILED) { $result = e404(url()->module, url()->method);; } $output = ''; if (!$this->async && ($result !== A_FAILED)) { $data = $this->active->toView(); $output = $this->render($this->template_path, $data); ; } echo $output; ; } public function __wakeup() { $this->active = & $this->module_stack['local']; } public function __sleep() { return array( 'module_stack', 'render_mode', 'view_path' ); } } class ResourceMap { const CLASS_FILE_LINES_LIMIT = 50; public static $moduleAncestors = array( '\samson\core\CompressableExternalModule' => 'CompressableExternalModule', '\samson\core\ExternalModule' => 'ExternalModule', '\samson\core\Service' => 'Service', '\samson\core\CompressableService' => 'CompressableService' ); public static $gathered = array(); public static function find($entryPoint, & $pointer = null) { $tempPointer = & self::$gathered[$entryPoint]; if (isset($tempPointer)) { $pointer = $tempPointer; return true; } return false; } public static function & get($entryPoint, $force = false, $ignoreFolders = array()) { $resourceMap = null; if (!self::find($entryPoint, $resourceMap)) { $resourceMap = new ResourceMap($entryPoint, $ignoreFolders); $resourceMap->build($entryPoint); } elseif ($force) { $resourceMap->build($entryPoint); } return $resourceMap; } public $entryPoint; public $resources = array(); public $controllers = array(); public $module = array(); public $globals = array(); public $models = array(); public $views = array(); public $classes = array(); public $css = array(); public $less = array(); public $sass = array(); public $js = array(); public $php = array(); public $coffee = array(); public $ignoreFolders = array( '.svn/', '.git/', '.idea/', __SAMSON_CACHE_PATH, __SAMSON_TEST_PATH, __SAMSON_VENDOR_PATH, __SAMSON_CONFIG_PATH, __SAMSON_CONTRIB_PATH, 'cms/', 'out/' ); public $ignoreFiles = array( 'phpunit.php', '.travis.yml', 'phpunit.xml', 'composer.lock', 'license.md', '.gitignore', '.readme.md', ); public function __construct($entryPoint, array $ignoreFolders = array(), array $ignoreFiles = array()) { $this->entryPoint = realpath($entryPoint).'/'; $ignoreFolders = array_merge($this->ignoreFolders, $ignoreFolders); $this->ignoreFolders = array(); foreach ($ignoreFolders as $folder) { $folder = realpath($this->entryPoint.$folder); if (isset($folder{0}) && is_dir($folder)) { $this->ignoreFolders[] = $folder; } } $publicPath = $this->entryPoint.__SAMSON_PUBLIC_PATH; $files = array(); foreach (\samson\core\File::dir($publicPath, 'htaccess', '', $files, 1) as $file) { $folder = dirname($file); if ($folder.'/' !== $publicPath && !in_array($folder, $this->ignoreFolders)) { $this->ignoreFolders[] = $folder; } } $this->ignoreFiles = array_merge($this->ignoreFiles, $ignoreFiles); self::$gathered[$this->entryPoint] = & $this; } public function isClass($path, & $class = '') { $namespace = '\\'; $file = fopen($path, 'r'); for ($i = 0; $i<self::CLASS_FILE_LINES_LIMIT; $i++) { $line = fgets($file); $matches = array(); if ($namespace == '\\' && preg_match('/^\s*namespace\s+(?<namespace>[^;]+)/iu', $line, $matches)) { $namespace .= $matches['namespace'].'\\'; } elseif (preg_match('/^\s*class\s+(?<class>[a-z0-9]+)\s+extends\s+(?<parent>[a-z0-9\\\]+)/iu', $line, $matches)) { $class = $namespace.$matches['class']; if (isset(self::$moduleAncestors[$matches['parent']]) || in_array($matches['parent'], self::$moduleAncestors)) { self::$moduleAncestors[$namespace.$matches['class']] = $matches['class']; return true; } $this->classes[] = $class; return false; } } return false; } public function isView($path) { return strpos($path, __SAMSON_VIEW_PATH) !== false || strpos($path, '.vphp') !== false; } public function isModule($path, & $class = '') { if (strpos($path, '.php') !== false && $this->isClass($path, $class)) { if (strpos('CompressableExternalModule, ExternalModule, Service, CompressableService', str_replace('\samson\core\\', '', $class)) === false) { return true; } else { return false; } } return false; } public function isModel($path) { return strpos($path, __SAMSON_MODEL_PATH) !== false; } public function isPHP($path) { return strpos($path, '.php') !== false; } public function isGlobal($path) { return basename($path, '.php') == 'global'; } public function isController($path) { return strpos($path, __SAMSON_CONTROLLER_PATH) !== false || basename($path, '.php') == 'controller'; } public function toLoadStackFormat() { return array( 'resources' => $this->resources, 'modules' => $this->module, 'controllers' => $this->controllers, 'models' => $this->models, 'views' => $this->views, 'php' => array_merge($this->php, $this->globals) ); } public function build($path = null) { $path = isset($path) ? realpath(normalizepath($path)).'/' : $this->entryPoint; $this->entryPoint = $path; if (file_exists($path)) { $files = array(); foreach (File::dir($this->entryPoint, null, '', $files, null, 0, $this->ignoreFolders) as $file) { $file = realpath($file); if (!in_array(basename($file), $this->ignoreFiles)) { $class = ''; if ($this->isView($file)) { $this->views[] = $file; } elseif ($this->isGlobal($file)) { $this->globals[] = $file; } elseif ($this->isModel($file)) { $this->models[] = $file; } elseif ($this->isController($file)) { $this->controllers[] = $file; } elseif ($this->isModule($file, $class)) { $this->module = array($class, $file); } elseif ($this->isPHP($file)) { $this->php[] = $file; } else { $rt = pathinfo($file, PATHINFO_EXTENSION); if (!isset($this->resources[$rt])) { $this->resources[$rt] = array(); } $this->resources[$rt][] = $file; } } } foreach (get_object_vars($this) as $var => $value) { if (isset($this->resources[$var])) { $this->$var = & $this->resources[$var]; } } return true; } else { return e('Cannot build ResourceMap from ## - path does not exists', E_SAMSON_CORE_ERROR, $path); } } } class File { public static $MIMEExtension = array ( 'text/css' => 'css', 'application/x-font-woff' => 'woff', 'application/x-javascript' => 'js', 'text/html;charset=utf-8' =>'htm', 'text/x-component' => 'htc', 'image/jpeg' => 'jpg', 'image/pjpeg' => 'jpg', 'image/png' => 'png', 'image/x-png' => 'png', 'image/jpg' => 'jpg', 'image/gif' => 'gif', 'text/plain' => 'txt', 'application/pdf' => 'pdf', 'application/zip' => 'zip', 'application/rtf' => 'rtf', 'application/msword' => 'doc', 'application/msexcel' => 'xls', 'application/vnd.ms-excel' => 'xls', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' => 'xlsx', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' => 'docx', 'application/octet-stream' => 'sql', 'audio/mpeg' => 'mp3' ); public static $ExtensionMIME = array(); public static $ImageExtension = array ( 'jpg' => 'jpg', 'jpeg' => 'jpeg', 'png' => 'png', 'jpg' => 'jpg', 'gif' => 'gif' ); public static function find( $path, $file ){ return file_exists( $path.'/'.$file); } public static function copy( $path, $dest ) { if( is_dir($path) ) { if( ! file_exists( $dest ) ) mkdir( $dest, 0755, TRUE ); $files = scandir( $path ); $files_count = sizeof( $files ); for ($i = 2; $i < $files_count; $i++) { $file = & $files[ $i ]; $source_path = $path.'/'.$file; $dest_path = $dest.'/'.$file; self::copy( $source_path, $dest_path ); } return TRUE; } else if( is_file( $path ) ) { if( is_dir( $dest ) ) $dest .= pathinfo( $path, PATHINFO_FILENAME ).'.'.pathinfo( $path, PATHINFO_EXTENSION ); return copy( $path, $dest ); } else return FALSE; } public static function dir($path, $type = null, $modifier = '', & $result = array(), $max_level = NULL, $level = 0, $restrict = array('.git','.svn','.hg', '.settings')) { if( isset( $max_level ) && $level > $max_level ) return $result; if (isset($type) && !is_array($type)) { $type = array($type); } if (file_exists($path) && $handle = opendir($path)) { while (false !== ( $entry = readdir($handle))) { if ($entry == '..' || $entry == '.') { continue; } $full_path = realpath($path . '/' . $entry); if (is_file($full_path)) { if (!isset($type) || in_array(pathinfo($full_path, PATHINFO_EXTENSION), $type)) { $result[] = normalizepath($modifier . $full_path); } } else if (is_dir($full_path)) { $ignored = false; foreach ($restrict as $ignore) { if (($ignored = ($ignore == $full_path)) !== false) { break; } } if ($ignored === false) { self::dir($full_path, $type, $modifier, $result, $max_level, ++$level, $restrict); } } } closedir($handle); } if( sizeof( $result )) sort( $result ); return $result; } public static function clear($path, $type = NULL, $ignoreFolders = array()) { if (is_dir($path)) { $files = array(); foreach (self::dir($path, $type, '', $files, null, 0, $ignoreFolders) as $file) { unlink($file); } return TRUE; } else if (file_exists($path)) { unlink($path); return TRUE; } return FALSE; } public static function mkdir($path, $group = 'www-data', $mode = 0775) { if (!file_exists($path)) { if (mkdir($path, $mode, true)) { chgrp($path, $group); return true; } else { return -1; } } return false; } public static function getExtension( $mime_type ) { if( isset( self::$MIMEExtension[ $mime_type ] ) ) return self::$MIMEExtension[ $mime_type ]; return FALSE; } public static function getMIME( $path ) { $file_ext = pathinfo( $path, PATHINFO_EXTENSION ); if( isset( self::$ExtensionMIME[ $file_ext ] ) ) return self::$ExtensionMIME[ $file_ext ]; return 'application/octet-stream'; } public static function isImage( $path ) { $file_ext = trim( substr( pathinfo( $path, PATHINFO_EXTENSION ), 0, 3 )); return isset( self::$ImageExtension[ $file_ext ] ); } } File::$ExtensionMIME = array_flip( File::$MIMEExtension ); class Module implements iModule, \ArrayAccess, iModuleViewable { public static $instances = array(); public $uid; protected $controllers = array(); protected $views = array(); protected $path = ''; protected $id = ''; protected $version = '0.0.1'; protected $view_path = self::VD_POINTER_DEF; protected $data = array( self::VD_POINTER_DEF => array( self::VD_HTML => '' ) ); protected $view_data = array( self::VD_POINTER_DEF => array( self::VD_HTML => '' ) ); protected $view_context = self::VD_POINTER_DEF; protected $cache_path; protected function viewContext( $view_path ) { $new = & $this->view_data[ $view_path ]; $old = & $this->view_data[ $this->view_context ]; if( $this->view_context !== $view_path ) { if( ! isset( $this->view_data[ $view_path ] ) ) { $new = array(); if( isset( $old ) ) { $new = array_merge( $new, $old ); } $new[ self::VD_HTML ] = ''; } $this->data = & $new; $this->view_context = $view_path; } } protected function sortStrings( $a, $b ){ return strlen($b) - strlen($a); } public function findView( $view_path ) { $view_path = str_replace( array('.php','.vphp'), '', $view_path ); if( sizeof($view = preg_grep('/'.addcslashes($view_path,'/\\').'(\.php|\.vphp)/ui', $this->views )) ) { usort( $view, array( $this, 'sortStrings') ); return end( $view ); } else return false; { } } public function title( $title = NULL ) { return $this->set( 'title', $title ); } public function id(){ return $this->id; } public function set( $field, $value = NULL ) { $this->__set($field, $value); return $this; } public function toView( $prefix = NULL, array $restricted = array() ) { $view_data = array_merge($this->data, get_object_vars($this)); unset($view_data[ self::VD_HTML ]); return $view_data; } public function path( $value = NULL ) { if( func_num_args() ) { $this->path = isset($value{0}) ? rtrim(normalizepath($value), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : ''; return $this; } else return $this->path; } public function html( $value = NULL ) { if( func_num_args() ) $this->data[ self::VD_HTML ] = $value; else return $this->data[ 'html' ]; return $this; } public function view( $view_path ) { $view_path = $this->findView( $view_path ); $this->viewContext( $view_path ); $this->view_path = $view_path; return $this; } public function output( $view_path = null ) { if( !isset( $view_path ) ) $view_path = $this->view_path; else if( isset( $view_path{0} ) ) $view_path = $this->findView( $view_path ); $this->viewContext( $view_path ); $out = $this->data[ self::VD_HTML ]; if( isset( $view_path {0}) ) { $old = s()->active( $this ); $out .= s()->render( $this->path.$view_path, $this->data ); s()->active( $old ); } else if( !isset($out{0}) ) { return e('Cannot render view for module ## - No view path or data has been set', E_SAMSON_CORE_ERROR, $this->id ); } unset($this->view_data[ $view_path ]); end( $this->view_data ); $this->view_context = key( $this->view_data ); $this->data = & $this->view_data[ $this->view_context ]; $this->view_path = $this->view_context; return $out; } public function render( $controller = NULL ) { $old = & s()->active( $this ); if( isset( $controller ) ) { $this->action( $controller == '' ? null : $controller ); } echo $this->output( $this->view_path ); s()->active( $old ); } public function action( $method_name = NULL ) { $parameters = url()->parameters; if($_SERVER['HTTP_ACCEPT'] == '*/*' || isset($_SERVER['HTTP_SJSASYNC']) || isset($_POST['SJSASYNC'])) { $arguments = $parameters; array_unshift( $arguments, url()->method ); $event_result = array(); for ($idx = 0; $idx < sizeof($arguments); $idx++) { $controller_name = self::ASYNC_PREFIX.$arguments[ $idx ]; $callback = & $this->controllers[ $controller_name ]; if( isset( $callback ) ) { $f_args = array_slice($arguments, $idx + 1); $arguments = array_slice($arguments, $idx + 1); $idx--; $_event_result = call_user_func_array( $callback, $f_args ); if( !is_array($_event_result) ) $_event_result = array($_event_result); if( !isset($_event_result['status']) || !$_event_result['status'] ) { $_event_result['message'] = "\n".'Event failed: '.$controller_name; $event_result = array_merge( $event_result, $_event_result ); break; } else $event_result = array_merge( $event_result, $_event_result ); } } if( sizeof($event_result) ) { s()->async(true); header("HTTP/1.0 200 Ok"); echo json_encode( $event_result, JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP ); return A_SUCCESS; } } $request_type = $_SERVER['REQUEST_METHOD']; $naming = $method_name; $request = !isset($method_name{0}) ? strtolower( $request_type == 'GET' ? self::CTR_BASE : self::OBJ_PREFIX.$request_type) : ''; $universal = self::CTR_UNI; $controller = (isset( $this->controllers[ $naming ] ) ? $this->controllers[ $naming ] : (isset( $this->controllers[ $request ] ) ? $this->controllers[ $request ] : (isset( $this->controllers[ $universal ] ) ? $this->controllers[ $universal ] : null))); if( isset($this->controllers[ $universal ]) && $controller == $this->controllers[ $universal ] ) { if(isset(url()->method{0})) array_unshift( $parameters, url()->method ); } $action_result = isset( $controller ) ? call_user_func_array( $controller, $parameters ) : A_FAILED; return !isset( $action_result ) ? A_SUCCESS : $action_result; } public function __construct($id, $path = NULL, $resources = NULL) { $this->view_context = self::VD_POINTER_DEF; $this->data = & $this->view_data[ $this->view_context ]; $this->id = $id; $this->path($path); $this->uid = rand(0, 9999999).'_'.microtime(true); $this->data['id'] = $this->id; (isset($resources ) && isset($resources['views'])) ? $this->views = & $resources['views'] : ''; $this->cache_path = __SAMSON_CWD__.__SAMSON_CACHE_PATH.$this->id.'/'; !isset( self::$instances[ $this->id ] ) ? self::$instances[ $this->id ] = & $this : ''; $functions = get_defined_functions(); foreach ($functions['user'] as $method) { switch (strtolower($method)) { case $this->id.self::CTR_UNI : case $this->id.self::CTR_POST : case $this->id.self::CTR_PUT : case $this->id.self::CTR_DELETE : case $this->id.self::CTR_BASE : break; default: if( preg_match('/^'.$this->id.self::PROC_PREFIX.'(?<controller>.+)/i', $method, $matches ) ) { $this->controllers[ $matches['controller'] ] = $method; } } } foreach (get_class_methods($this) as $method) { switch(strtolower($method)) { case self::CTR_UNI: case self::CTR_POST : case self::CTR_PUT: case self::CTR_DELETE: case self::CTR_BASE : break; case '__call': case '__wakeup': case '__sleep': case '__construct': case '__destruct': case '__set': case '__get': break; default: if( preg_match('/^'.self::OBJ_PREFIX.'(?<controller>.+)/i', $method, $matches ) ) { $this->controllers[ $matches['controller'] ] = array( $this, $method ); } } } if( function_exists( $this->id )) $this->controllers[ self::CTR_BASE ] = $this->id; if( method_exists($this, self::CTR_BASE)) $this->controllers[ self::CTR_BASE ] = array( $this, self::CTR_BASE ); if( function_exists( $this->id.self::CTR_POST )) $this->controllers[ self::CTR_POST ] = $this->id.self::CTR_POST; if( method_exists($this, self::CTR_POST)) $this->controllers[ self::CTR_POST ] = array( $this, self::CTR_POST ); if( function_exists( $this->id.self::CTR_PUT )) $this->controllers[ self::CTR_PUT ] = $this->id.self::CTR_PUT; if( method_exists($this, self::CTR_PUT)) $this->controllers[ self::CTR_PUT ] = array( $this, self::CTR_PUT ); if( function_exists( $this->id.self::CTR_DELETE )) $this->controllers[ self::CTR_DELETE ] = $this->id.self::CTR_DELETE; if( method_exists($this, self::CTR_DELETE)) $this->controllers[ self::CTR_DELETE ] = array( $this, self::CTR_DELETE ); if( function_exists( $this->id.self::CTR_UNI )) $this->controllers[ self::CTR_UNI ] = $this->id.self::CTR_UNI; if( method_exists($this, self::CTR_UNI)) $this->controllers[ self::CTR_UNI ] = array( $this, self::CTR_UNI ); $this->views = str_replace( $this->path, '', $this->views ); } public function __destruct() { unset( Module::$instances[ $this->id ] ); } public function __get( $field ) { $result = NULL; if( isset( $this->data[ $field ] ) ) $result = & $this->data[ $field ]; else return e('Ошибка получения данных модуля(##) - Требуемые данные(##) не найдены', E_SAMSON_CORE_ERROR, array( $this->id, $field )); return $result; } protected function cache_refresh( & $file, $clear = true ) { if( !file_exists( $this->cache_path ) ) mkdir( $this->cache_path, 0777, TRUE ); $file = $this->cache_path.$file; if( file_exists( $file ) ) return false; else { if( $clear ) File::clear( $this->cache_path, pathinfo( $file, PATHINFO_EXTENSION ) ); return true; } } private function _setObject( $object, $viewprefix = null ) { $class_name = is_string( $viewprefix ) ? $viewprefix : ''.mb_strtolower( classname(get_class($object)), 'UTF-8' ); $this->data[ $class_name ] = $object; $class_name .= '_'; $this->data = array_merge( $this->data, $object->toView( $class_name ) ); } private function _setArray( $array, $viewprefix = null ) { $this->data[ $viewprefix ] = $array; $this->data = array_merge( $this->data, $array ); } public function __set( $field, $value = NULL ) { if( is_object( $field )) { if( in_array( ns_classname('iModuleViewable','samson\core'), class_implements($field )) ) $this->_setObject( $field, $value ); } else if( is_array( $field ) ) $this->_setArray( $field, $value ); else $this->data[ $field ] = $value; } public function __call( $method, $arguments ) { if( sizeof( $arguments ) ) { if( is_object($arguments[0]) || is_array($arguments[0]) ) $this->__set( $arguments[0], $method ); else $this->__set( $method, $arguments[0] ); } return $this; } public function __sleep(){ return array( 'id', 'path', 'version', 'data', 'controllers', 'views' ); } public function __wakeup() { self::$instances[ $this->id ] = & $this; $this->view_data[ self::VD_POINTER_DEF ] = $this->data; $this->data = & $this->view_data[ self::VD_POINTER_DEF ]; } public function offsetSet( $offset, $value ){ $this->__set( $offset, $value ); } public function offsetGet( $offset ) { return $this->__get( $offset ); } public function offsetUnset( $offset ) { $this->data[ $offset ] = ''; } public function offsetExists( $offset ) { return isset($this->data[ $offset ]); } } class ExternalModule extends Module implements iExternalModule { public $parent = NULL; protected $vid = null; protected $requirements = array(); public function __construct($path, $vid = null, $resources = NULL ) { if (!isset($this->id{0}) && !isset($vid)) { $this->id = AutoLoader::oldClassName(get_class($this)); } else if (!isset($this->id{0}) && isset($vid)) { $this->id = $vid; } $this->vid = $this->id; ; parent::__construct($this->id, $path, $resources ); } public function & copy() { $classname = get_class( $this ); $id = $this->id.'_'.rand( 0, 99999999 ); $o = new $classname( $this->path, $id ); $o->views = & $this->views; $o->parent = & $this->parent; $o->controllers = & $this->controllers; return $o; } public function __sleep() { return array_diff( array_keys( get_object_vars( $this )), array( 'view_path', 'view_html', 'view_data' )); } public function & duplicate( $id, $class_name = null ) { $m = parent::duplicate( $id, $class_name ); $m->parent = & $this->parent; return $m; } public function action( $method_name = NULL ) { $result = parent::action( $method_name ); if( $result === A_FAILED && isset($this->parent) ) { return $this->parent->action( $method_name ); } return $result; } public function output( $view_path = null ) { if( isset( $this->parent ) ) { $_view_path = $this->findView( $view_path ); if( !isset($_view_path{0}) ) { $this->parent->view_data = array_merge( $this->parent->view_data, $this->view_data ); $this->parent->data = & $this->data; return $this->parent->output( isset($view_path) ? $view_path : $this->view_path ); } } return parent::output( $view_path ); } public function prepare() { return TRUE; } public function init( array $params = array() ) { $this->set( $params ); return TRUE; } } class CompressableExternalModule extends ExternalModule implements iModuleCompressable { public function beforeCompress( & $obj = null, array & $code = null ){} public function afterCompress( & $obj = null, array & $code = null ){} } class System extends CompressableExternalModule { protected $id = 'core'; } class Service extends ExternalModule { protected static $_factory = array(); protected static $ancestorIgnoreData = array('vid'=>'', 'uid'=>'', 'cache_path'=>''); public $gatherAncestorData = true; public static function & getInstance( $class ) { $class = strtolower( isset( $class ) ? $class : e('Classname not specified', E_SAMSON_FATAL_ERROR)); if( !isset(self::$_factory[ $class ])) e('Service ## does not exists', E_SAMSON_FATAL_ERROR, $class ); else return self::$_factory[ $class ]; } protected static function gatherAncestorsData(& $baseObject, & $currentObject) { $parentClass = strtolower(get_parent_class($currentObject)); if(strtolower(__CLASS__) != $parentClass) { $parentInstance = & self::$_factory[$parentClass]; if(isset($parentInstance)) { foreach (array_diff_key(get_object_vars($parentInstance), self::$ancestorIgnoreData) as $field => $value) { if (isset($parentInstance->$field) && !isset($baseObject->$field)) { $baseObject->$field = $parentInstance->$field; } } if (isset($parentInstance->requirements)) { $baseObject->requirements = array_unique(array_merge($baseObject->requirements, $parentInstance->requirements)); } $baseObject->parent = & $parentInstance; self::gatherAncestorsData($baseObject, $parentInstance); } } } public function __construct($path = NULL, $vid = null, $resources = NULL) { $class = strtolower(get_class( $this )); if (!isset(self::$_factory[ $class ])) { self::$_factory[ $class ] = $this; if ($this->gatherAncestorData) { $this->gatherAncestorsData($this, $this); } } else e('Attempt to create another instance of Factory class: ##', E_SAMSON_FATAL_ERROR, $class ); parent::__construct($path, $vid, $resources); } public function __wakeup(){ parent::__wakeup(); self::$_factory[ strtolower(get_class($this)) ] = $this; } } class CompressableService extends Service implements iModuleCompressable { public function beforeCompress( & $obj = null, array & $code = null ){} public function afterCompress( & $obj = null, array & $code = null ){} } class LocalModule extends Module { } class CompressableLocalModule extends LocalModule implements iModuleCompressable { public function beforeCompress( & $obj = null, array & $code = null ){} public function afterCompress( & $obj = null, array & $code = null ){} } class URL implements iURL { private $base = '/'; public $last = ''; public $parameters = array(); public $module = NULL; public $method = NULL; public $text; public function __construct() { $this->parse(); } public function router(\samson\core\Core & $core, & $result, $default = 'main') { $module = isset($this->module{0}) ? mb_strtolower( $this->module, 'UTF-8') : $default; if (isset($core->module_stack[$module])) { $active = & $core->module_stack[$module]; $core->active($active); $result = $active->action(url()->method); } } public function module(){ return $this->module; } public function method(){ return $this->method; } public function last(){ return $this->last; } public function text(){ return $this->text; } public function parameters(){return $this->parameters;} public function is($modules, $output = '') { if (!is_array($modules)) { $modules = array($modules); } foreach ($modules as $module) { if (($this->module == $module) || (s()->module()->id == $module)) { echo $output; return true; } } return false; } public function bookmark( $name = NULL, $return = false ) { $stack = & $_SESSION[ self::S_BOOKMARK_KEY ]; if( $return && isset( $stack[ $name ] ) ) return unserialize( $stack[ $name ] ); if( !$return ) $stack[ $name ] = serialize($this); } public function history( $number = 0 ) { $stack = & $_SESSION[ self::S_PREVIOUS_KEY ]; if( isset( $stack[ $number ] ) ) return unserialize( $stack[ $number ] ); else return $this; } public function base( $url_base = NULL ) { if( isset( $url_base ) ) { $this->base = $url_base; $this->parse(); } return $this->base; } public function redirect( $url = NULL ) { $full_url = $this->base.locale_path().$url; header('Location: '.$full_url ); } public function build( $url = '' ) { $args = func_get_args(); $args = array_slice( $args, 1 ); $url_params = explode( '/', $url ); for ($i = 0; $i < sizeof($url_params); $i++) if( !isset($url_params[$i]{0}) ) unset($url_params[$i]); $args_count = sizeof( $args ); $m = & s()->active(); for ($i = 0; $i < $args_count; $i++) { $arg = $args[ $i ]; $url_params[] = isset( $m[$arg] ) && !is_object($m[$arg])? $m->$arg : $arg; } return __SAMSON_PROTOCOL.$_SERVER['HTTP_HOST'].$this->base.implode( '/', $url_params ); } private function parse() { $this->text = NULL; $this->parameters = array(); $this->method = NULL; $this->module = NULL; $this->last = NULL; $url = parse_url( $_SERVER["REQUEST_URI"] ); $url = $url['path']; $url = trim( urldecode( substr( $url, strlen( __SAMSON_BASE__ )))); $this->base = __SAMSON_BASE__; $url_args = explode( '/', $url ); $lidx = sizeof( $url_args ) - 1; if( !isset($url_args[ $lidx ]{0}) ) unset( $url_args[ $lidx ] ); $key = SamsonLocale::parseURL( $url_args ); foreach ( $url_args as $position => $value ) { $arg = filter_var( $value, FILTER_DEFAULT ); switch( $position ) { case 0 : $this->module = $arg; break; case 1 : $this->method = $arg; break; default : $this->parameters[] = $arg; } } $this->text = $url; $this->last = isset($position) ? $url_args[ $position ] : ''; if( !isset($_SESSION[ self::S_PREVIOUS_KEY ]) ) $_SESSION[ self::S_PREVIOUS_KEY ] = array(); if( !isset($_SESSION[ self::S_BOOKMARK_KEY ]) ) $_SESSION[ self::S_BOOKMARK_KEY ] = array(); if($_SERVER['HTTP_ACCEPT'] != '*/*') { array_unshift( $_SESSION[ self::S_PREVIOUS_KEY ], serialize($this) ); if( sizeof($_SESSION[ self::S_PREVIOUS_KEY ]) > self::S_PREVIOUS_SIZE ) { $_SESSION[ self::S_PREVIOUS_KEY ] = array_slice( $_SESSION[ self::S_PREVIOUS_KEY ], 0, self::S_PREVIOUS_SIZE ); } } } } class SamsonLocale { const DEF = DEFAULT_LOCALE; const UA = 'ua'; const EN = 'en'; const RU = 'ru'; const RO = 'ro'; const CH = 'ch'; const KO = 'ko'; private static $supported = array( SamsonLocale::DEF, SamsonLocale::EN, SamsonLocale::UA, SamsonLocale::RO, SamsonLocale::CH, SamsonLocale::RU, SamsonLocale::KO, ); public static $defaultLocale = DEFAULT_LOCALE; public static $current_locale = ''; public static $locales = array(); public static function check() { if( ! in_array( strtolower(self::$current_locale), self::$locales ) ) self::$current_locale = self::DEF; } public static function set(array $available_locales) { foreach ( $available_locales as $locale ) { $_locale = strtolower($locale); if ( in_array($_locale, self::$supported)) { if (!in_array($_locale, self::$locales)) { self::$locales[] = $_locale; } } else die('Устанавливаемая локализация "'.$locale.'" - не предусмотрена в SamsonLocale'); } self::check(); } public static function get(){ return self::$locales; } public static function current($locale = null) { $_locale = self::$current_locale; if (!isset($locale)) { return $_locale; } else { self::$current_locale = strtolower($locale); $_SESSION['__SAMSON_LOCALE__'] = self::$current_locale; return self::$current_locale; } } public static function parseURL( array & $args ) { foreach ( self::$locales as $locale ) { if( ($key = array_search( $locale, $args )) !== FALSE ) { self::current($locale); if( $locale != self::DEF ) { unset($args[ $key ]); $args = array_values($args); } return true; } } self::current(self::DEF); return false; } } class Configuration { public $environment; public function load($basePath = __SAMSON_CONFIG_PATH, $environment = null) { $this->environment = $environment; $configurationPath = $basePath.'/'.(isset($environment) ? $environment.'/' : ''); if (file_exists($configurationPath)) { return e('Environment(##) configuration path(##) does not exists', E_SAMSON_CORE_ERROR, array($environment, $configurationPath)); } foreach (get_declared_classes() as $class) { if (is_subclass_of($class, '\samson\core\Configurator')) { $className = strtolower($class); if (strpos($className, $environment) !== false) { $configurator = new $class(); } } } } } class Configurator { public $entity; public function __construct(& $entity) { $this->entity = $entity; $vars = array_filter(array_diff(get_object_vars($this), get_class_vars(__CLASS__))); foreach($vars as $var => $value) { if (property_exists($entity, $var)) { $entity->$var = $value; } } } } define('__SAMSON_T_STARTED__', microtime(TRUE)); define('__SAMSON_PHP_OLD','');; if (!defined('__DIR__')) { define('__DIR__', dirname(__FILE__)); } define('__SAMSON_PATH__', __DIR__.'/../'); define('__NS_SEPARATOR__', '\\'); define('__SAMSON_PROTOCOL', (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT']== 443)) ? "https://" : "http://" ); if (!defined('__SAMSON_PUBLIC_PATH')) { define('__SAMSON_PUBLIC_PATH', 'www/'); } if (!defined('__SAMSON_CACHE_PATH')) { define('__SAMSON_CACHE_PATH', __SAMSON_PUBLIC_PATH . 'cache/'); } if (!defined('__SAMSON_TEST_PATH')) { define('__SAMSON_TEST_PATH', 'tests/'); } if (!defined('__SAMSON_CONTRIB_PATH')) { define('__SAMSON_CONTRIB_PATH', 'contrib/'); } if (!defined('__SAMSON_VENDOR_PATH')) { define('__SAMSON_VENDOR_PATH', 'vendor/'); } if (!defined('__SAMSON_REL_PATH')) { define('__SAMSON_REL_PATH', '../'); } if (!defined('__SAMSON_APP_PATH')) { define('__SAMSON_APP_PATH', 'app/'); } if (!defined('__SAMSON_CONFIG_PATH')) { define('__SAMSON_CONFIG_PATH', __SAMSON_APP_PATH.'config/'); } if (!defined('__SAMSON_CONTROLLER_PATH')) { define('__SAMSON_CONTROLLER_PATH', __SAMSON_APP_PATH.'controller/'); } if (!defined('__SAMSON_MODEL_PATH')) { define('__SAMSON_MODEL_PATH', __SAMSON_APP_PATH.'model/'); } if (!defined('__SAMSON_VIEW_PATH')) { define('__SAMSON_VIEW_PATH', __SAMSON_APP_PATH.'view/'); } if (!defined('__SAMSON_DEFAULT_TEMPLATE')) { define('__SAMSON_DEFAULT_TEMPLATE', __SAMSON_VIEW_PATH.'index.php'); } if (!defined('__SAMSON_CWD__')) { define('__SAMSON_CWD__', realpath(str_ireplace('\\', '/', getcwd() . '/').'../').'/'); } if (strlen(__SAMSON_CWD__) - strlen($_SERVER['DOCUMENT_ROOT']) > 5) { $_SERVER['DOCUMENT_ROOT'] = dirname($_SERVER['SCRIPT_FILENAME']); } if(!defined('__SAMSON_BASE__')) { define('__SAMSON_BASE__','/');; } define('__SAMSON_REMOTE_APP', __SAMSON_BASE__ !== '/'); define( '__SAMSON_MAX_EXECUTION__', 120 ); define( 'A_SUCCESS', TRUE ); define( 'A_FAILED', FALSE ); define( '__SAMSON_GLOBAL_FILE', 'global.php' ); class ConfigType { const ALL = 0; const DEVELOPMENT = 1; const TEST = 2; const PRODUCTION = 3; } interface iCompressable { function transform($input, & $output); } define("DEFAULT_LOCALE", "ru"); } namespace samson\activerecord{ interface idbConnector { public function connect( array $params = NULL ); public function disconnect( array $params = NULL ); } interface idb { public function & simple_query( $sql ); public function & query( $sql ); public function create( $class_name, idbRecord & $object = NULL ); public function update( $class_name, idbRecord & $object ); public function & find( $class_name, dbQuery $query ); public function & find_by_id( $class_name, $id ); public function delete( $class_name, idbRecord & $object ); public function profiler(); } interface idbRecord { } class ActiveRecordConnector extends \samson\core\CompressableExternalModule { protected $id = 'activerecord'; public $prefix; public $name; public $login = 'root'; public $pwd; public $host = '127.0.0.1'; public $port = ''; public $relations = array(); public function beforeCompress( & $obj = null, array & $code = null ) { } public function afterCompress( & $obj = null, array & $code = null ) { $files = array(); foreach (\samson\core\File::dir($this->cache_path.'metadata', 'php', '', $files, 1 ) as $file) { $ns = strpos( $file, 'func') === false ? __NAMESPACE__ : ''; $obj->compress_php( $file, $this, $code, $ns ); } $files = array(); foreach (\samson\core\File::dir($this->cache_path.'relations', 'php', '', $files, 1 ) as $file) { $ns = strpos( $file, 'func') === false ? __NAMESPACE__ : ''; $obj->compress_php( $file, $this, $code, $ns ); } } public function prepare() { dbMySQLConnector::$prefix = $this->prefix; db()->connect(array( 'name' => $this->name, 'login' => $this->login, 'pwd' => $this->pwd, 'host' => $this->host, 'port' => $this->port )); foreach ( $this->relations as $args ) { switch(sizeof($args)) { case 2: new TableRelation($args[0], $args[1]); break; case 3: new TableRelation($args[0], $args[1], $args[2]); break; case 4: new TableRelation($args[0], $args[1], $args[2], $args[3]); break; case 5: new TableRelation($args[0], $args[1], $args[2], $args[3], $args[4]); break; case 6: new TableRelation($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); break; } } db()->generate(false, $this->cache_path); } public function init( array $params = array() ) { parent::init( $params ); dbMySQLConnector::$prefix = $this->prefix; db()->connect(array( 'name' => $this->name, 'login'=> $this->login, 'pwd' => $this->pwd, 'host' => $this->host )); } } class dbMySQLConnector implements idbConnector { public static $prefix = ''; protected static $tables = array(); protected static $relations = array(); protected $connected = FALSE; public $link; protected $base_name; private $created_classes = array(); private function __build_columns_map( $table_name, array & $select = array(), array & $map = array(), array & $alias = array(), $alias_table_name = null ) { $alias_table_name = isset($alias_table_name) ? $alias_table_name : $table_name; foreach ( self::$tables[ $table_name ] as $column_data ) { $column = $column_data['Field']; $column_alias = $alias_table_name.'_'.$column; $column_full = $alias_table_name.'.'.$column; $alias[ $column ] = $column_alias; $select[] = $column_full.' as '.$column_alias; $map[ $column_alias ] = $column_full; } } public function connect( array $params = NULL ) { $host = (!isset($params['host'])) ? 'localhost' : $params['host']; $login = (!isset($params['login'])) ? 'root' : $params['login']; $pwd = (!isset($params['pwd'])) ? '' : $params['pwd']; $port = (!isset($params['port'])) ? '' : ':'.$params['port']; $this->base_name =(!isset($params['pwd'])) ? '' : $params['pwd']; if( ! isset($params['name']) ) return e('Не задано имя БД для подключения', E_USER_ERROR ); else $this->base_name = $params['name']; if( ! $this->connected ) { $this->connected = true; $this->link = mysqli_connect( $host, $login, $pwd, $this->base_name ) or e( mysqli_error( $this->link ), E_SAMSON_SQL_ERROR ); mysqli_query ($this->link, "set character_set_client='utf8'" ); mysqli_query ($this->link, "set character_set_results='utf8'" ); mysqli_query ($this->link, "set collation_connection='utf8_general_ci'"); } } public function disconnect( array $params = NULL ) { mysqli_close( $this->link ); } public function __destruct() { $this->disconnect(); } } class dbMySQL extends dbMySQLConnector implements idb { private $query_count = 0; private $elapsed = 0; public function debug( $flag = true ) { if( $flag ) $_SESSION['__AR_SHOW_QUERY__'] = true; else unset($_SESSION['__AR_SHOW_QUERY__']); } public function & simple_query( $sql ) { if( ! $this->connected ) return e('Подключение к БД не было выполнено', E_SAMSON_FATAL_ERROR ); $resource = mysqli_query( $this->link, $sql ) or e( mysqli_error( $this->link ), E_SAMSON_SQL_ERROR ); if( isset($_SESSION['__AR_SHOW_QUERY__']) ) elapsed($sql); return $resource; } public function & query( $sql ) { if( !$this->connected ) return e('Подключение к БД не было выполнено', E_SAMSON_SQL_ERROR ); $rows = array(); $t_last = microtime( TRUE ); $sql_result = mysqli_query( $this->link, $sql ) or e( mysqli_error( $this->link ), E_SAMSON_SQL_ERROR ); if( isset($_SESSION['__AR_SHOW_QUERY__']) ) { elapsed($sql); trace($sql, true); } if( !is_bool($sql_result) ) { while( $row = mysqli_fetch_array( $sql_result, MYSQL_ASSOC ) ) $rows[] = $row; mysqli_free_result( $sql_result ); } $this->query_count++; $this->elapsed += microtime( TRUE ) - $t_last; return $rows; } public function create( $class_name, idbRecord & $object = NULL ) { extract($this->__get_table_data( $class_name )); $fields = $this->getQueryFields( $class_name, $object ); $this->query( 'INSERT INTO `'.$_table_name.'` (`'.implode( '`,`', array_keys( $fields ) ).'`) VALUES ('.implode( ',', $fields ).')' ); return mysqli_insert_id( $this->link ); } public function update( $class_name, idbRecord & $object ) { extract($this->__get_table_data( $class_name )); $fields = $this->getQueryFields( $class_name, $object, TRUE ); $this->query( 'UPDATE `'.$_table_name.'` SET '.implode( ',', $fields ).' WHERE '.$_table_name.'.'.$_primary.'="'.$object->id.'"' ); return TRUE; } public function delete( $class_name, idbRecord & $object ) { extract($this->__get_table_data( $class_name )); return $this->query( 'DELETE FROM `'.$_table_name.'` WHERE '.$_primary.' = "' . $object->id . '"', FALSE ); } public function createField($object, $table, $field, $type = 'INT') { if(strlen($object->$field)) { $attributes = array(); eval('$attributes = '.$table.'::$_attributes;'); $table = classname($table); $attributes = array_change_key_case_unicode($attributes); if (!isset($attributes[strtolower($object->$field)])) { $this->simple_query('ALTER TABLE  `'.$table.'` ADD  `'.$object->$field.'` '.$type.' '); } return true; } else { return e('Cannot load "'.get_class($object).'" module - no $'.$field.' is configured'); } } public function __get_table_data( $class_name ) { $class_name = str_replace(self::$prefix, '', $class_name); $class_name = ns_classname( $class_name, 'samson\activerecord'); $_table_name = '$_table_name = '.$class_name.'::$_table_name;'; $_own_group = '$_own_group = '.$class_name.'::$_own_group;'; $_table_attributes = '$_table_attributes = '.$class_name.'::$_table_attributes;'; $_primary = '$_primary = '.$class_name.'::$_primary;'; $_sql_from = '$_sql_from = '.$class_name.'::$_sql_from;'; $_sql_select = '$_sql_select = '.$class_name.'::$_sql_select;'; $_attributes = '$_attributes = '.$class_name.'::$_attributes;'; $_types = '$_types = '.$class_name.'::$_types;'; $_map = '$_map = '.$class_name.'::$_map;'; $_relations = '$_relations = '.$class_name.'::$_relations;'; $_unique = '$_unique = '.$class_name.'::$_unique;'; $_relation_type = '$_relation_type = '.$class_name.'::$_relation_type;'; $_relation_alias= '$_relation_alias = '.$class_name.'::$_relation_alias;'; eval( $_own_group.$_table_name.$_primary.$_sql_from.$_sql_select.$_map.$_attributes.$_relations.$_relation_type.$_relation_alias.$_types.$_unique.$_table_attributes ); return array ( '_table_name' => $_table_name, '_own_group' => $_own_group, '_primary' => $_primary, '_attributes' => $_attributes, '_table_attributes' => $_table_attributes, '_types' => $_types, '_map' => $_map, '_relations' => $_relations, '_relation_type' => $_relation_type, '_relation_alias' => $_relation_alias, '_sql_from' => $_sql_from, '_sql_select' => $_sql_select, '_unique' => $_unique, ); } public function count( $class_name, dbQuery $query ) { $sql = 'SELECT Count(*) as __Count FROM ('.$this->prepareSQL( $class_name, $query ).') as __table'; $db_data = $this->query( $sql ); return $db_data[0]['__Count']; } public function innerCount( $class_name, dbQuery $query ) { $params = $this->__get_table_data( $class_name ); $sql = 'SELECT Count(*) as __Count FROM ('.$this->prepareInnerSQL( $class_name, $query, $params).') as __table'; $db_data = $this->query( $sql ); return $db_data[0]['__Count']; } public function & find( $class_name, dbQuery $query ) { $sql = $this->prepareSQL($class_name, $query); $db_data = $this->query( $sql ); $result = array(); if ( ( is_array( $db_data ) ) && ( sizeof($db_data) > 0 ) ) { $result = $this->toRecords( $class_name, $db_data, $query->join, array_merge( $query->own_virtual_fields, $query->virtual_fields) ); } return $result; } public function & findFields($class_name, dbQuery $query, $field) { if (!is_array($field)) { $fields = array(); } $sql = $this->prepareSQL($class_name, $query); $sql_result = mysqli_query($this->link, $sql ) or e( mysqli_error( $this->link ), E_SAMSON_SQL_ERROR ); $result = array(); if( !is_bool($sql_result)) { while( $row = mysqli_fetch_array( $sql_result, MYSQL_ASSOC ) ) { if (isset($row[$field])) { $result[$row[$field]] = $row[$field]; } } mysqli_free_result( $sql_result ); } $result = array_values ($result); return $result; } public function & find_by_id( $class_name, $id ) { extract($this->__get_table_data( $class_name )); $record_data = $this->query('SELECT '.$_sql_select['this'].' FROM '.$_sql_from['this'].' WHERE '.$_table_name.'.'.$_primary.' = "'.$id.'"'); $db_records = $this->toRecords( $class_name, $record_data ); $ret = null; if( sizeof($db_records) >= 1 ) $ret = array_shift($db_records); return $ret; } public function migration( $classname, $version_handler ) { if( !is_callable( $version_handler ) ) return e('No version handler is passed', E_SAMSON_ACTIVERECORD_ERROR); $version = call_user_func( $version_handler ); foreach( get_class_methods( $classname ) as $m ) { if( preg_match('/^migrate_(?<from>\d+)_to_(?<to>\d+)/i', $m, $matches) ) { $from = $matches['from']; $to = $matches['to']; if( $from == $version ) { elapsed('Databse migration from version: '.$from.' -> '.$to); if( call_user_func( array($version_handler[0], $m)) !== false ) { $version = $to; call_user_func( $version_handler, $to ); } else { e('Database migration from ## -> ## - has Failed', E_SAMSON_ACTIVERECORD_ERROR, array( $from, $to)); break; } } } } } public function profiler() { $list = array(); $total_obj_count = 0; foreach ( dbRecord::$instances as $n => $v ) { if( $c = sizeof($v) ) { $total_obj_count += $c; $list[] = ''.$n.'('.$c.')'; } } return 'DB: '.round($this->elapsed,3).'с, '.$this->query_count.' запр., '.$total_obj_count.' об.('.implode($list,',').')'; } private function prepareSQL( $class_name, dbQuery $query ) { $params = $this->__get_table_data( $class_name ); extract($params); $select = '`'.$_table_name.'`.*'; if( sizeof( $query->virtual_fields ) ) $select .= ', '."\n".implode("\n".', ', $query->virtual_fields); $from = ' ( '.$this->prepareInnerSQL( $class_name, $query, $params ); $from .= ' ) as `'.$_table_name.'`'; foreach ($query->join as $relation_data ) { $c_table = self::$prefix.$relation_data->table; if( isset( $_sql_from[ $c_table ] ) ) { $select .= ','.$_sql_select[ $c_table ]; $from .= "\n".' '.$_sql_from[ $c_table ]; } else return e('Ошибка! В таблице связей для класса(##), не указана связь с классом(##)',E_SAMSON_FATAL_ERROR,array( $class_name, $c_table)); } $sql = "\n".'SELECT '.$select."\n".' FROM '.$from; $sql .= "\n".' WHERE ('.$this->getConditions( $query->condition, $class_name ).')'; if( sizeof( $query->group )) $sql .= "\n".' GROUP BY '.$query->group[0]; if( sizeof( $query->order )) { $sql .= "\n".' ORDER BY '; for ($i=0;$i<sizeof($query->order); $i++) { $item = &$query->order[$i]; if (sizeof($item)) { $sql .= $item[0].' '.$item[1]; } if ($i<(sizeof($query->order)-1)) { $sql .= ', '; } } } if( sizeof( $query->limit )) $sql .= "\n".' LIMIT '.$query->limit[0].(isset($query->limit[1])?','.$query->limit[1]:''); if( isset($GLOBALS['show_sql']) ) elapsed( $sql); return $sql; } private function prepareInnerSQL( $class_name, dbQuery $query, $params ) { $from = 'SELECT '.$params['_sql_select']['this']; if( sizeof( $query->own_virtual_fields ) ) $from .= ', '."\n".implode("\n".', ', $query->own_virtual_fields); $from .="\n".' FROM '.$params['_sql_from']['this']; if( sizeof( $query->own_condition->arguments )) $from .= "\n".' WHERE ('.$this->getConditions($query->own_condition, $class_name).')'; $query->own_group = array_merge( $params['_own_group'], is_array($query->own_group) ? $query->own_group : array() ); if( sizeof( $query->own_group )) $from .= "\n".'GROUP BY '.implode(',', $query->own_group); if( sizeof( $query->own_order )) $from .= "\n".' ORDER BY '.$query->own_order[0].' '.$query->own_order[1]; if( sizeof( $query->own_limit )) $from .= "\n".' LIMIT '.$query->own_limit[0].(isset($query->own_limit[1])?','.$query->own_limit[1]:''); return $from; } private function getConditions(Condition $cond_group, $class_name ) { $sql_condition = array(); foreach ($cond_group->arguments as $argument){ if (is_a($argument, ns_classname('Condition','samson\activerecord'))) { $sql_condition[] = $this->getConditions( $argument, $class_name); } else { $sql_condition[] = $this->parseCondition( $class_name, $argument ); } } if(sizeof($sql_condition)) return '('.implode( ') '.$cond_group->relation.' (', $sql_condition ).')'; else return '(1=1)'; } private function parseCondition( $class_name, Argument & $arg ) { extract($this->__get_table_data( $class_name )); $sql_cond_t = isset( $_map[ $arg->field ] ) ? $_map[ $arg->field ] : $arg->field; if( !is_array( $arg->value ) ) { if( $arg->relation === dbRelation::NOTNULL || $arg->relation === dbRelation::ISNULL ) return $sql_cond_t.$arg->relation; else if( $arg->relation === dbRelation::OWN) return $arg->field; else return $sql_cond_t.$arg->relation.$this->protectQueryValue( $arg->value); } else if( sizeof( $arg->value )) { switch( $arg->relation ) { case dbRelation::EQUAL: return $sql_cond_t.' IN ("'.implode( '","', $arg->value ).'")'; case dbRelation::NOT_EQUAL: return $sql_cond_t.' NOT IN ("'.implode( '","', $arg->value ).'")'; } } } private function & getQueryFields( $class_name, idbRecord & $object = NULL, $straight = FALSE ) { extract($this->__get_table_data( $class_name )); $collection = array(); $use_values = isset($object); $table = $_table_name; foreach ( $_table_attributes as $attribute => $map_attribute ) { if( $_types[ $attribute ] == 'timestamp' ) continue; if( $_primary == $attribute ) continue; $value = $use_values ? $this->protectQueryValue( $object->$map_attribute ) : ''; $collection[ $map_attribute ] = ($straight ? $table.'.'.$map_attribute.'=':'').$value; } return $collection; } private function protectQueryValue( $value ) { if( get_magic_quotes_gpc() ) $value = stripslashes( $value ); $value = mysqli_real_escape_string($this->link, $value ); return '"'.$value.'"'; } public function & createObject($className, $identifier, array & $attributes, array & $dbData, array & $virtualFields = array()) { if(!isset(dbRecord::$instances[ $className ][ $identifier ]) || isset($dbData['__Count']) || sizeof($virtualFields)) { dbRecord::$instances[ $className ][ $identifier ] = new $className(false); $object = & dbRecord::$instances[ $className ][ $identifier ]; $object->id = $identifier; $object->attached = true; foreach ($attributes as $lc_field => $field) { $object->$lc_field = $dbData[ $field ]; } foreach ($virtualFields as $alias => $virtual_field) { if (isset($dbData[ $alias ])) { $object->$alias = $dbData[ $alias ]; } } return $object; } else { return dbRecord::$instances[ $className ][ $identifier ]; } } private function & toRecords( $class_name, array & $response, array $join = array(), array $virtual_fields = array() ) { $class_name = ns_classname( $class_name, 'samson\activerecord'); $collection = array(); extract($this->__get_table_data($class_name)); $joinedTableData = array(); foreach ($join as $relationData) { $joinTable = self::$prefix.$relationData->table; $tableName = $_relation_alias[ $joinTable ]; $joinedTableData[$tableName] = $this->__get_table_data($tableName); } $main_primary = $_primary; $records_count = sizeof( $response ); $main_id = isset($response[ 0 ]) ? $response[ 0 ][ $main_primary ] : 0; $main_obj = null; for ( $i = 0; $i < $records_count; $i++ ) { $db_row = & $response[ $i ]; $collection[ $main_id ] = & $this->createObject($class_name, $main_id, $_attributes, $db_row, $virtual_fields); $main_obj = & $collection[ $main_id ]; for ($j = $i; $j < $records_count; $j++) { $db_inner_row = & $response[ $j ]; $obj_id = $db_inner_row[ $main_primary ]; if ($obj_id != $main_id) { $main_id = $obj_id; $i = $j - 1; break; } foreach ($join as $relation_data) { if (!$relation_data->ignore) { $join_name = $relation_data->relation; $join_table = self::$prefix.$relation_data->table; $_relation_name = $_relation_alias[ $join_table ]; $join_class = str_replace( self::$prefix, '', $relation_data->table); $r_data = $joinedTableData[ $_relation_name ]; if( isset($_relations[ $join_table ][ $r_data['_primary'] ]) ) $r_obj_id_field = $_relations[ $join_table ][ $r_data['_primary'] ]; else e('Cannot find related table(##) primary field(##) description', E_SAMSON_ACTIVERECORD_ERROR, array($join_table, $r_data['_primary']) ); if( isset( $db_inner_row[ $r_obj_id_field ] )) { $r_obj_id = $db_inner_row[ $r_obj_id_field ]; $r_obj = & $this->createObject($join_name, $r_obj_id, $_relations[ $join_table ], $db_inner_row); $r_obj->filled(); if( $_relation_type[ $join_table ] == 0 ) { $main_obj->onetoone[ '_'.$join_table ] = $r_obj; $main_obj->onetoone[ '_'.$join_class ] = $r_obj; } else { $main_obj->onetomany[ '_'.$join_table ][ $r_obj_id ] = $r_obj; $main_obj->onetomany[ '_'.$join_class ][ $r_obj_id ] = $r_obj; } } } } } $main_obj->filled(); if( $j == $records_count ) break; } return $collection; } private function getClassName( $class_name ) { return ($parentclass = get_parent_class( $class_name )) == ns_classname( 'dbRecord', 'samson\activerecord') ? $class_name : $parentclass; } } class Record implements \samson\core\iModuleViewable, \ArrayAccess { public static $restricted = array( 'attached', 'onetoone', 'onetomany', 'class_name' ); public $id; public function toView( $prefix = NULL, array $restricted = array() ) { $values = array( $prefix.'id' => $this->id ); $restricted = array_merge( self::$restricted, $restricted ); foreach( get_object_vars( $this ) as $var => $value ) { if( ! in_array( $var, $restricted ) ) $values[ $prefix.$var ] = $value; } return $values; } public function offsetSet( $offset, $value ){ $this->$offset = $value; } public function offsetGet($offset){ return $this->$offset; } public function offsetUnset($offset){ unset( $this->$offset ); } public function offsetExists($offset){ return property_exists( $this, $offset ); } } class dbRecord extends Record implements idbRecord { public static $instances = array(); public $id = 0; public $class_name; public $onetoone = array(); public $onetomany = array(); public $attached = FALSE; public function __construct( $id = NULL, $class_name = NULL ) { if(!isset($this->class_name)) $this->class_name = get_class($this); if( $id === FALSE ){ } else { if( ! isset( $id ) ) $this->create(); else if( NULL !== ($db_record = db()->find_by_id( $class_name, $id ))) { $this->id = $id; foreach( $db_record as $var => $value ) $this->$var = $value; $this->attached = TRUE; } self::$instances[ $class_name ][ $this->id ] = $this; } } public function create() { if( !$this->attached ) { $class_name = $this->class_name; extract(db()->__get_table_data( $class_name )); $this->id = db()->create( $class_name, $this ); $db_record = db()->find_by_id( $class_name, $this->id ); foreach ( $_attributes as $name => $r_name) $this->$name = $db_record->$name; $this->attached = TRUE; } } public function save() { if( $this->attached ) db()->update( $this->class_name, $this ); else $this->create(); self::$instances[ ns_classname(get_class($this),'') ][ $this->id ] = & $this; } public function delete() { if( $this->attached ) db()->delete( $this->class_name, $this ); } public function filled() { } public function __clone() { $this->id = db()->create( $this->class_name, $this ); $this->attached = TRUE; $this->save(); } } class cms_version extends \samson\activerecord\dbRecord { public static $_table_name = "cms_version"; public static $_own_group = array(); public static $_attributes = array( "version"=>"version", ); public static $_table_attributes = array( "version"=>"version", ); public static $_sql_from = array( "this" => "`cms_version`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "cms_version.version", ); public static $_types = array( "version"=>"varchar", ); public static $_indeces = array( ); public static $_unique = array( ); public static $_map = array( "version"=>"cms_version.version", ); public $version = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "cms_version" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["cms_version"] = array(); class field extends \samson\activerecord\dbRecord { public static $_table_name = "field"; public static $_own_group = array(); public static $_primary = "FieldID"; public static $_attributes = array( "FieldID"=>"FieldID", "ParentID"=>"ParentID", "Name"=>"Name", "Type"=>"Type", "local"=>"local", "filtered"=>"filtered", "Value"=>"Value", "Description"=>"Description", "UserID"=>"UserID", "Created"=>"Created", "Modyfied"=>"Modyfied", "Active"=>"Active", "system"=>"system", ); public static $_table_attributes = array( "FieldID"=>"FieldID", "ParentID"=>"ParentID", "Name"=>"Name", "Type"=>"Type", "local"=>"local", "filtered"=>"filtered", "Value"=>"Value", "Description"=>"Description", "UserID"=>"UserID", "Created"=>"Created", "Modyfied"=>"Modyfied", "Active"=>"Active", "system"=>"system", ); public static $_sql_from = array( "this" => "`field`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "field.FieldID,
field.ParentID,
field.Name,
field.Type,
field.local,
field.filtered,
field.Value,
field.Description,
field.UserID,
field.Created,
field.Modyfied,
field.Active,
field.system", ); public static $_types = array( "FieldID"=>"int", "ParentID"=>"int", "Name"=>"varchar", "Type"=>"int", "local"=>"int", "filtered"=>"int", "Value"=>"text", "Description"=>"text", "UserID"=>"int", "Created"=>"datetime", "Modyfied"=>"timestamp", "Active"=>"int", "system"=>"int", ); public static $_indeces = array( "ParentID", ); public static $_unique = array( ); public static $_map = array( "FieldID"=>"field.FieldID", "ParentID"=>"field.ParentID", "Name"=>"field.Name", "Type"=>"field.Type", "local"=>"field.local", "filtered"=>"field.filtered", "Value"=>"field.Value", "Description"=>"field.Description", "UserID"=>"field.UserID", "Created"=>"field.Created", "Modyfied"=>"field.Modyfied", "Active"=>"field.Active", "system"=>"field.system", ); public $FieldID = ""; public $ParentID = ""; public $Name = ""; public $Type = ""; public $local = ""; public $filtered = ""; public $Value = ""; public $Description = ""; public $UserID = ""; public $Created = ""; public $Modyfied = ""; public $Active = ""; public $system = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "field" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["field"] = array(); class filter extends \samson\activerecord\dbRecord { public static $_table_name = "filter"; public static $_own_group = array(); public static $_primary = "filter_id"; public static $_attributes = array( "filter_id"=>"filter_id", "field_id"=>"field_id", "value"=>"value", "locale"=>"locale", ); public static $_table_attributes = array( "filter_id"=>"filter_id", "field_id"=>"field_id", "value"=>"value", "locale"=>"locale", ); public static $_sql_from = array( "this" => "`filter`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "filter.filter_id,
filter.field_id,
filter.value,
filter.locale", ); public static $_types = array( "filter_id"=>"int", "field_id"=>"int", "value"=>"varchar", "locale"=>"varchar", ); public static $_indeces = array( ); public static $_unique = array( ); public static $_map = array( "filter_id"=>"filter.filter_id", "field_id"=>"filter.field_id", "value"=>"filter.value", "locale"=>"filter.locale", ); public $filter_id = ""; public $field_id = ""; public $value = ""; public $locale = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "filter" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["filter"] = array(); class gallery extends \samson\activerecord\dbRecord { public static $_table_name = "gallery"; public static $_own_group = array(); public static $_primary = "PhotoID"; public static $_attributes = array( "PhotoID"=>"PhotoID", "MaterialID"=>"MaterialID", "priority"=>"priority", "Path"=>"Path", "Src"=>"Src", "size"=>"size", "Loaded"=>"Loaded", "Description"=>"Description", "Name"=>"Name", "Active"=>"Active", ); public static $_table_attributes = array( "PhotoID"=>"PhotoID", "MaterialID"=>"MaterialID", "priority"=>"priority", "Path"=>"Path", "Src"=>"Src", "size"=>"size", "Loaded"=>"Loaded", "Description"=>"Description", "Name"=>"Name", "Active"=>"Active", ); public static $_sql_from = array( "this" => "`gallery`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "gallery.PhotoID,
gallery.MaterialID,
gallery.priority,
gallery.Path,
gallery.Src,
gallery.size,
gallery.Loaded,
gallery.Description,
gallery.Name,
gallery.Active", ); public static $_types = array( "PhotoID"=>"int", "MaterialID"=>"int", "priority"=>"int", "Path"=>"varchar", "Src"=>"varchar", "size"=>"int", "Loaded"=>"timestamp", "Description"=>"text", "Name"=>"varchar", "Active"=>"int", ); public static $_indeces = array( "MaterialID", ); public static $_unique = array( ); public static $_map = array( "PhotoID"=>"gallery.PhotoID", "MaterialID"=>"gallery.MaterialID", "priority"=>"gallery.priority", "Path"=>"gallery.Path", "Src"=>"gallery.Src", "size"=>"gallery.size", "Loaded"=>"gallery.Loaded", "Description"=>"gallery.Description", "Name"=>"gallery.Name", "Active"=>"gallery.Active", ); public $PhotoID = ""; public $MaterialID = ""; public $priority = ""; public $Path = ""; public $Src = ""; public $size = ""; public $Loaded = ""; public $Description = ""; public $Name = ""; public $Active = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "gallery" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["gallery"] = array(); class group extends \samson\activerecord\dbRecord { public static $_table_name = "group"; public static $_own_group = array(); public static $_primary = "GroupID"; public static $_attributes = array( "GroupID"=>"GroupID", "Name"=>"Name", "Active"=>"Active", ); public static $_table_attributes = array( "GroupID"=>"GroupID", "Name"=>"Name", "Active"=>"Active", ); public static $_sql_from = array( "this" => "`group`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "group.GroupID,
group.Name,
group.Active", ); public static $_types = array( "GroupID"=>"int", "Name"=>"varchar", "Active"=>"int", ); public static $_indeces = array( ); public static $_unique = array( ); public static $_map = array( "GroupID"=>"group.GroupID", "Name"=>"group.Name", "Active"=>"group.Active", ); public $GroupID = ""; public $Name = ""; public $Active = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "group" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["group"] = array(); class groupright extends \samson\activerecord\dbRecord { public static $_table_name = "groupright"; public static $_own_group = array(); public static $_primary = "GroupRightID"; public static $_attributes = array( "GroupRightID"=>"GroupRightID", "GroupID"=>"GroupID", "RightID"=>"RightID", "Entity"=>"Entity", "Key"=>"Key", "Ban"=>"Ban", "TS"=>"TS", "Active"=>"Active", ); public static $_table_attributes = array( "GroupRightID"=>"GroupRightID", "GroupID"=>"GroupID", "RightID"=>"RightID", "Entity"=>"Entity", "Key"=>"Key", "Ban"=>"Ban", "TS"=>"TS", "Active"=>"Active", ); public static $_sql_from = array( "this" => "`groupright`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "groupright.GroupRightID,
groupright.GroupID,
groupright.RightID,
groupright.Entity,
groupright.Key,
groupright.Ban,
groupright.TS,
groupright.Active", ); public static $_types = array( "GroupRightID"=>"int", "GroupID"=>"int", "RightID"=>"int", "Entity"=>"varchar", "Key"=>"varchar", "Ban"=>"int", "TS"=>"timestamp", "Active"=>"int", ); public static $_indeces = array( "GroupID", "RightID", ); public static $_unique = array( ); public static $_map = array( "GroupRightID"=>"groupright.GroupRightID", "GroupID"=>"groupright.GroupID", "RightID"=>"groupright.RightID", "Entity"=>"groupright.Entity", "Key"=>"groupright.Key", "Ban"=>"groupright.Ban", "TS"=>"groupright.TS", "Active"=>"groupright.Active", ); public $GroupRightID = ""; public $GroupID = ""; public $RightID = ""; public $Entity = ""; public $Key = ""; public $Ban = ""; public $TS = ""; public $Active = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "groupright" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["groupright"] = array(); class material extends \samson\activerecord\dbRecord { public static $_table_name = "material"; public static $_own_group = array(); public static $_primary = "MaterialID"; public static $_attributes = array( "MaterialID"=>"MaterialID", "parent_id"=>"parent_id", "Name"=>"Name", "Teaser"=>"Teaser", "Url"=>"Url", "Created"=>"Created", "Modyfied"=>"Modyfied", "UserID"=>"UserID", "Draft"=>"Draft", "type"=>"type", "Published"=>"Published", "Active"=>"Active", "system"=>"system", ); public static $_table_attributes = array( "MaterialID"=>"MaterialID", "parent_id"=>"parent_id", "Name"=>"Name", "Teaser"=>"Teaser", "Url"=>"Url", "Created"=>"Created", "Modyfied"=>"Modyfied", "UserID"=>"UserID", "Draft"=>"Draft", "type"=>"type", "Published"=>"Published", "Active"=>"Active", "system"=>"system", ); public static $_sql_from = array( "this" => "`material`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "material.MaterialID,
material.parent_id,
material.Name,
material.Teaser,
material.Url,
material.Created,
material.Modyfied,
material.UserID,
material.Draft,
material.type,
material.Published,
material.Active,
material.system", ); public static $_types = array( "MaterialID"=>"int", "parent_id"=>"int", "Name"=>"varchar", "Teaser"=>"text", "Url"=>"varchar", "Created"=>"datetime", "Modyfied"=>"timestamp", "UserID"=>"int", "Draft"=>"int", "type"=>"int", "Published"=>"int", "Active"=>"int", "system"=>"int", ); public static $_indeces = array( "Url", "UserID", ); public static $_unique = array( ); public static $_map = array( "MaterialID"=>"material.MaterialID", "parent_id"=>"material.parent_id", "Name"=>"material.Name", "Teaser"=>"material.Teaser", "Url"=>"material.Url", "Created"=>"material.Created", "Modyfied"=>"material.Modyfied", "UserID"=>"material.UserID", "Draft"=>"material.Draft", "type"=>"material.type", "Published"=>"material.Published", "Active"=>"material.Active", "system"=>"material.system", ); public $MaterialID = ""; public $parent_id = ""; public $Name = ""; public $Teaser = ""; public $Url = ""; public $Created = ""; public $Modyfied = ""; public $UserID = ""; public $Draft = ""; public $type = ""; public $Published = ""; public $Active = ""; public $system = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "material" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["material"] = array(); class materialfield extends \samson\activerecord\dbRecord { public static $_table_name = "materialfield"; public static $_own_group = array(); public static $_primary = "MaterialFieldID"; public static $_attributes = array( "MaterialFieldID"=>"MaterialFieldID", "FieldID"=>"FieldID", "MaterialID"=>"MaterialID", "Value"=>"Value", "numeric_value"=>"numeric_value", "locale"=>"locale", "Active"=>"Active", ); public static $_table_attributes = array( "MaterialFieldID"=>"MaterialFieldID", "FieldID"=>"FieldID", "MaterialID"=>"MaterialID", "Value"=>"Value", "numeric_value"=>"numeric_value", "locale"=>"locale", "Active"=>"Active", ); public static $_sql_from = array( "this" => "`materialfield`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "materialfield.MaterialFieldID,
materialfield.FieldID,
materialfield.MaterialID,
materialfield.Value,
materialfield.numeric_value,
materialfield.locale,
materialfield.Active", ); public static $_types = array( "MaterialFieldID"=>"int", "FieldID"=>"int", "MaterialID"=>"int", "Value"=>"text", "numeric_value"=>"int", "locale"=>"varchar", "Active"=>"int", ); public static $_indeces = array( "FieldID", "MaterialID", ); public static $_unique = array( ); public static $_map = array( "MaterialFieldID"=>"materialfield.MaterialFieldID", "FieldID"=>"materialfield.FieldID", "MaterialID"=>"materialfield.MaterialID", "Value"=>"materialfield.Value", "numeric_value"=>"materialfield.numeric_value", "locale"=>"materialfield.locale", "Active"=>"materialfield.Active", ); public $MaterialFieldID = ""; public $FieldID = ""; public $MaterialID = ""; public $Value = ""; public $numeric_value = ""; public $locale = ""; public $Active = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "materialfield" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["materialfield"] = array(); class related_materials extends \samson\activerecord\dbRecord { public static $_table_name = "related_materials"; public static $_own_group = array(); public static $_primary = "related_materials_id"; public static $_attributes = array( "related_materials_id"=>"related_materials_id", "first_material"=>"first_material", "first_locale"=>"first_locale", "second_material"=>"second_material", "second_locale"=>"second_locale", ); public static $_table_attributes = array( "related_materials_id"=>"related_materials_id", "first_material"=>"first_material", "first_locale"=>"first_locale", "second_material"=>"second_material", "second_locale"=>"second_locale", ); public static $_sql_from = array( "this" => "`related_materials`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "related_materials.related_materials_id,
related_materials.first_material,
related_materials.first_locale,
related_materials.second_material,
related_materials.second_locale", ); public static $_types = array( "related_materials_id"=>"int", "first_material"=>"int", "first_locale"=>"varchar", "second_material"=>"int", "second_locale"=>"varchar", ); public static $_indeces = array( ); public static $_unique = array( ); public static $_map = array( "related_materials_id"=>"related_materials.related_materials_id", "first_material"=>"related_materials.first_material", "first_locale"=>"related_materials.first_locale", "second_material"=>"related_materials.second_material", "second_locale"=>"related_materials.second_locale", ); public $related_materials_id = ""; public $first_material = ""; public $first_locale = ""; public $second_material = ""; public $second_locale = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "related_materials" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["related_materials"] = array(); class right extends \samson\activerecord\dbRecord { public static $_table_name = "right"; public static $_own_group = array(); public static $_primary = "RightID"; public static $_attributes = array( "RightID"=>"RightID", "Name"=>"Name", "Active"=>"Active", ); public static $_table_attributes = array( "RightID"=>"RightID", "Name"=>"Name", "Active"=>"Active", ); public static $_sql_from = array( "this" => "`right`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "right.RightID,
right.Name,
right.Active", ); public static $_types = array( "RightID"=>"int", "Name"=>"varchar", "Active"=>"int", ); public static $_indeces = array( ); public static $_unique = array( ); public static $_map = array( "RightID"=>"right.RightID", "Name"=>"right.Name", "Active"=>"right.Active", ); public $RightID = ""; public $Name = ""; public $Active = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "right" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["right"] = array(); class scmstable extends \samson\activerecord\dbRecord { public static $_table_name = "scmstable"; public static $_own_group = array(); public static $_primary = "RowID"; public static $_attributes = array( "RowID"=>"RowID", "Entity"=>"Entity", "EntityID"=>"EntityID", "MaterialID"=>"MaterialID", "Created"=>"Created", "TS"=>"TS", "Active"=>"Active", "Column0"=>"Column0", "Column1"=>"Column1", "Column2"=>"Column2", "Column3"=>"Column3", "Column4"=>"Column4", "Column5"=>"Column5", "Column6"=>"Column6", "Column7"=>"Column7", "Column8"=>"Column8", "Column9"=>"Column9", "Column10"=>"Column10", "Column11"=>"Column11", "Column12"=>"Column12", "Column13"=>"Column13", "Column14"=>"Column14", "Column15"=>"Column15", "Column16"=>"Column16", "Column17"=>"Column17", "Column18"=>"Column18", "Column19"=>"Column19", "Column20"=>"Column20", ); public static $_table_attributes = array( "RowID"=>"RowID", "Entity"=>"Entity", "EntityID"=>"EntityID", "MaterialID"=>"MaterialID", "Created"=>"Created", "TS"=>"TS", "Active"=>"Active", "Column0"=>"Column0", "Column1"=>"Column1", "Column2"=>"Column2", "Column3"=>"Column3", "Column4"=>"Column4", "Column5"=>"Column5", "Column6"=>"Column6", "Column7"=>"Column7", "Column8"=>"Column8", "Column9"=>"Column9", "Column10"=>"Column10", "Column11"=>"Column11", "Column12"=>"Column12", "Column13"=>"Column13", "Column14"=>"Column14", "Column15"=>"Column15", "Column16"=>"Column16", "Column17"=>"Column17", "Column18"=>"Column18", "Column19"=>"Column19", "Column20"=>"Column20", ); public static $_sql_from = array( "this" => "`scmstable`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "scmstable.RowID,
scmstable.Entity,
scmstable.EntityID,
scmstable.MaterialID,
scmstable.Created,
scmstable.TS,
scmstable.Active,
scmstable.Column0,
scmstable.Column1,
scmstable.Column2,
scmstable.Column3,
scmstable.Column4,
scmstable.Column5,
scmstable.Column6,
scmstable.Column7,
scmstable.Column8,
scmstable.Column9,
scmstable.Column10,
scmstable.Column11,
scmstable.Column12,
scmstable.Column13,
scmstable.Column14,
scmstable.Column15,
scmstable.Column16,
scmstable.Column17,
scmstable.Column18,
scmstable.Column19,
scmstable.Column20", ); public static $_types = array( "RowID"=>"int", "Entity"=>"varchar", "EntityID"=>"varchar", "MaterialID"=>"int", "Created"=>"datetime", "TS"=>"timestamp", "Active"=>"int", "Column0"=>"varchar", "Column1"=>"varchar", "Column2"=>"varchar", "Column3"=>"varchar", "Column4"=>"varchar", "Column5"=>"varchar", "Column6"=>"varchar", "Column7"=>"varchar", "Column8"=>"varchar", "Column9"=>"varchar", "Column10"=>"varchar", "Column11"=>"varchar", "Column12"=>"varchar", "Column13"=>"varchar", "Column14"=>"varchar", "Column15"=>"varchar", "Column16"=>"varchar", "Column17"=>"varchar", "Column18"=>"varchar", "Column19"=>"varchar", "Column20"=>"varchar", ); public static $_indeces = array( ); public static $_unique = array( ); public static $_map = array( "RowID"=>"scmstable.RowID", "Entity"=>"scmstable.Entity", "EntityID"=>"scmstable.EntityID", "MaterialID"=>"scmstable.MaterialID", "Created"=>"scmstable.Created", "TS"=>"scmstable.TS", "Active"=>"scmstable.Active", "Column0"=>"scmstable.Column0", "Column1"=>"scmstable.Column1", "Column2"=>"scmstable.Column2", "Column3"=>"scmstable.Column3", "Column4"=>"scmstable.Column4", "Column5"=>"scmstable.Column5", "Column6"=>"scmstable.Column6", "Column7"=>"scmstable.Column7", "Column8"=>"scmstable.Column8", "Column9"=>"scmstable.Column9", "Column10"=>"scmstable.Column10", "Column11"=>"scmstable.Column11", "Column12"=>"scmstable.Column12", "Column13"=>"scmstable.Column13", "Column14"=>"scmstable.Column14", "Column15"=>"scmstable.Column15", "Column16"=>"scmstable.Column16", "Column17"=>"scmstable.Column17", "Column18"=>"scmstable.Column18", "Column19"=>"scmstable.Column19", "Column20"=>"scmstable.Column20", ); public $RowID = ""; public $Entity = ""; public $EntityID = ""; public $MaterialID = ""; public $Created = ""; public $TS = ""; public $Active = ""; public $Column0 = ""; public $Column1 = ""; public $Column2 = ""; public $Column3 = ""; public $Column4 = ""; public $Column5 = ""; public $Column6 = ""; public $Column7 = ""; public $Column8 = ""; public $Column9 = ""; public $Column10 = ""; public $Column11 = ""; public $Column12 = ""; public $Column13 = ""; public $Column14 = ""; public $Column15 = ""; public $Column16 = ""; public $Column17 = ""; public $Column18 = ""; public $Column19 = ""; public $Column20 = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "scmstable" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["scmstable"] = array(); class structure extends \samson\activerecord\dbRecord { public static $_table_name = "structure"; public static $_own_group = array(); public static $_primary = "StructureID"; public static $_attributes = array( "StructureID"=>"StructureID", "ParentID"=>"ParentID", "Name"=>"Name", "locale"=>"locale", "Created"=>"Created", "UserID"=>"UserID", "Modyfied"=>"Modyfied", "Url"=>"Url", "MaterialID"=>"MaterialID", "PriorityNumber"=>"PriorityNumber", "type"=>"type", "Active"=>"Active", "system"=>"system", ); public static $_table_attributes = array( "StructureID"=>"StructureID", "ParentID"=>"ParentID", "Name"=>"Name", "locale"=>"locale", "Created"=>"Created", "UserID"=>"UserID", "Modyfied"=>"Modyfied", "Url"=>"Url", "MaterialID"=>"MaterialID", "PriorityNumber"=>"PriorityNumber", "type"=>"type", "Active"=>"Active", "system"=>"system", ); public static $_sql_from = array( "this" => "`structure`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "structure.StructureID,
structure.ParentID,
structure.Name,
structure.locale,
structure.Created,
structure.UserID,
structure.Modyfied,
structure.Url,
structure.MaterialID,
structure.PriorityNumber,
structure.type,
structure.Active,
structure.system", ); public static $_types = array( "StructureID"=>"int", "ParentID"=>"int", "Name"=>"varchar", "locale"=>"varchar", "Created"=>"datetime", "UserID"=>"int", "Modyfied"=>"timestamp", "Url"=>"varchar", "MaterialID"=>"int", "PriorityNumber"=>"int", "type"=>"int", "Active"=>"int", "system"=>"int", ); public static $_indeces = array( "ParentID", "UserID", "Url", "MaterialID", ); public static $_unique = array( ); public static $_map = array( "StructureID"=>"structure.StructureID", "ParentID"=>"structure.ParentID", "Name"=>"structure.Name", "locale"=>"structure.locale", "Created"=>"structure.Created", "UserID"=>"structure.UserID", "Modyfied"=>"structure.Modyfied", "Url"=>"structure.Url", "MaterialID"=>"structure.MaterialID", "PriorityNumber"=>"structure.PriorityNumber", "type"=>"structure.type", "Active"=>"structure.Active", "system"=>"structure.system", ); public $StructureID = ""; public $ParentID = ""; public $Name = ""; public $locale = ""; public $Created = ""; public $UserID = ""; public $Modyfied = ""; public $Url = ""; public $MaterialID = ""; public $PriorityNumber = ""; public $type = ""; public $Active = ""; public $system = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "structure" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["structure"] = array(); class structure_relation extends \samson\activerecord\dbRecord { public static $_table_name = "structure_relation"; public static $_own_group = array(); public static $_primary = "structure_relation_id"; public static $_attributes = array( "structure_relation_id"=>"structure_relation_id", "parent_id"=>"parent_id", "child_id"=>"child_id", ); public static $_table_attributes = array( "structure_relation_id"=>"structure_relation_id", "parent_id"=>"parent_id", "child_id"=>"child_id", ); public static $_sql_from = array( "this" => "`structure_relation`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "structure_relation.structure_relation_id,
structure_relation.parent_id,
structure_relation.child_id", ); public static $_types = array( "structure_relation_id"=>"int", "parent_id"=>"int", "child_id"=>"int", ); public static $_indeces = array( "parent_id", "child_id", ); public static $_unique = array( ); public static $_map = array( "structure_relation_id"=>"structure_relation.structure_relation_id", "parent_id"=>"structure_relation.parent_id", "child_id"=>"structure_relation.child_id", ); public $structure_relation_id = ""; public $parent_id = ""; public $child_id = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "structure_relation" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["structure_relation"] = array(); class structurefield extends \samson\activerecord\dbRecord { public static $_table_name = "structurefield"; public static $_own_group = array(); public static $_primary = "StructureFieldID"; public static $_attributes = array( "StructureFieldID"=>"StructureFieldID", "StructureID"=>"StructureID", "FieldID"=>"FieldID", "Modified"=>"Modified", "Active"=>"Active", ); public static $_table_attributes = array( "StructureFieldID"=>"StructureFieldID", "StructureID"=>"StructureID", "FieldID"=>"FieldID", "Modified"=>"Modified", "Active"=>"Active", ); public static $_sql_from = array( "this" => "`structurefield`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "structurefield.StructureFieldID,
structurefield.StructureID,
structurefield.FieldID,
structurefield.Modified,
structurefield.Active", ); public static $_types = array( "StructureFieldID"=>"int", "StructureID"=>"int", "FieldID"=>"int", "Modified"=>"timestamp", "Active"=>"int", ); public static $_indeces = array( "StructureID", "FieldID", ); public static $_unique = array( ); public static $_map = array( "StructureFieldID"=>"structurefield.StructureFieldID", "StructureID"=>"structurefield.StructureID", "FieldID"=>"structurefield.FieldID", "Modified"=>"structurefield.Modified", "Active"=>"structurefield.Active", ); public $StructureFieldID = ""; public $StructureID = ""; public $FieldID = ""; public $Modified = ""; public $Active = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "structurefield" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["structurefield"] = array(); class structurematerial extends \samson\activerecord\dbRecord { public static $_table_name = "structurematerial"; public static $_own_group = array(); public static $_primary = "StructureMaterialID"; public static $_attributes = array( "StructureMaterialID"=>"StructureMaterialID", "StructureID"=>"StructureID", "MaterialID"=>"MaterialID", "Modified"=>"Modified", "Active"=>"Active", ); public static $_table_attributes = array( "StructureMaterialID"=>"StructureMaterialID", "StructureID"=>"StructureID", "MaterialID"=>"MaterialID", "Modified"=>"Modified", "Active"=>"Active", ); public static $_sql_from = array( "this" => "`structurematerial`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "structurematerial.StructureMaterialID,
structurematerial.StructureID,
structurematerial.MaterialID,
structurematerial.Modified,
structurematerial.Active", ); public static $_types = array( "StructureMaterialID"=>"int", "StructureID"=>"int", "MaterialID"=>"int", "Modified"=>"timestamp", "Active"=>"int", ); public static $_indeces = array( "StructureID", "MaterialID", ); public static $_unique = array( ); public static $_map = array( "StructureMaterialID"=>"structurematerial.StructureMaterialID", "StructureID"=>"structurematerial.StructureID", "MaterialID"=>"structurematerial.MaterialID", "Modified"=>"structurematerial.Modified", "Active"=>"structurematerial.Active", ); public $StructureMaterialID = ""; public $StructureID = ""; public $MaterialID = ""; public $Modified = ""; public $Active = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "structurematerial" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["structurematerial"] = array(); class unitable extends \samson\activerecord\dbRecord { public static $_table_name = "unitable"; public static $_own_group = array(); public static $_primary = "row_id"; public static $_attributes = array( "row_id"=>"row_id", "entity_id"=>"entity_id", "material_id"=>"material_id", "entity"=>"entity", "active"=>"active", "created"=>"created", "ts"=>"ts", "Column0"=>"Column0", "Column1"=>"Column1", "Column2"=>"Column2", "Column3"=>"Column3", "Column4"=>"Column4", "Column5"=>"Column5", "Column6"=>"Column6", "Column7"=>"Column7", "Column8"=>"Column8", "Column9"=>"Column9", "Column10"=>"Column10", "Column11"=>"Column11", "Column12"=>"Column12", "Column13"=>"Column13", "Column14"=>"Column14", "Column15"=>"Column15", "Column16"=>"Column16", "Column17"=>"Column17", "Column18"=>"Column18", "Column19"=>"Column19", ); public static $_table_attributes = array( "row_id"=>"row_id", "entity_id"=>"entity_id", "material_id"=>"material_id", "entity"=>"entity", "active"=>"active", "created"=>"created", "ts"=>"ts", "Column0"=>"Column0", "Column1"=>"Column1", "Column2"=>"Column2", "Column3"=>"Column3", "Column4"=>"Column4", "Column5"=>"Column5", "Column6"=>"Column6", "Column7"=>"Column7", "Column8"=>"Column8", "Column9"=>"Column9", "Column10"=>"Column10", "Column11"=>"Column11", "Column12"=>"Column12", "Column13"=>"Column13", "Column14"=>"Column14", "Column15"=>"Column15", "Column16"=>"Column16", "Column17"=>"Column17", "Column18"=>"Column18", "Column19"=>"Column19", ); public static $_sql_from = array( "this" => "`unitable`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "unitable.row_id,
unitable.entity_id,
unitable.material_id,
unitable.entity,
unitable.active,
unitable.created,
unitable.ts,
unitable.Column0,
unitable.Column1,
unitable.Column2,
unitable.Column3,
unitable.Column4,
unitable.Column5,
unitable.Column6,
unitable.Column7,
unitable.Column8,
unitable.Column9,
unitable.Column10,
unitable.Column11,
unitable.Column12,
unitable.Column13,
unitable.Column14,
unitable.Column15,
unitable.Column16,
unitable.Column17,
unitable.Column18,
unitable.Column19", ); public static $_types = array( "row_id"=>"int", "entity_id"=>"varchar", "material_id"=>"int", "entity"=>"varchar", "active"=>"int", "created"=>"datetime", "ts"=>"timestamp", "Column0"=>"varchar", "Column1"=>"varchar", "Column2"=>"varchar", "Column3"=>"varchar", "Column4"=>"varchar", "Column5"=>"varchar", "Column6"=>"varchar", "Column7"=>"varchar", "Column8"=>"varchar", "Column9"=>"varchar", "Column10"=>"varchar", "Column11"=>"varchar", "Column12"=>"varchar", "Column13"=>"varchar", "Column14"=>"varchar", "Column15"=>"varchar", "Column16"=>"varchar", "Column17"=>"varchar", "Column18"=>"varchar", "Column19"=>"varchar", ); public static $_indeces = array( "entity_id", "material_id", "entity", ); public static $_unique = array( ); public static $_map = array( "row_id"=>"unitable.row_id", "entity_id"=>"unitable.entity_id", "material_id"=>"unitable.material_id", "entity"=>"unitable.entity", "active"=>"unitable.active", "created"=>"unitable.created", "ts"=>"unitable.ts", "Column0"=>"unitable.Column0", "Column1"=>"unitable.Column1", "Column2"=>"unitable.Column2", "Column3"=>"unitable.Column3", "Column4"=>"unitable.Column4", "Column5"=>"unitable.Column5", "Column6"=>"unitable.Column6", "Column7"=>"unitable.Column7", "Column8"=>"unitable.Column8", "Column9"=>"unitable.Column9", "Column10"=>"unitable.Column10", "Column11"=>"unitable.Column11", "Column12"=>"unitable.Column12", "Column13"=>"unitable.Column13", "Column14"=>"unitable.Column14", "Column15"=>"unitable.Column15", "Column16"=>"unitable.Column16", "Column17"=>"unitable.Column17", "Column18"=>"unitable.Column18", "Column19"=>"unitable.Column19", ); public $row_id = ""; public $entity_id = ""; public $material_id = ""; public $entity = ""; public $active = ""; public $created = ""; public $ts = ""; public $Column0 = ""; public $Column1 = ""; public $Column2 = ""; public $Column3 = ""; public $Column4 = ""; public $Column5 = ""; public $Column6 = ""; public $Column7 = ""; public $Column8 = ""; public $Column9 = ""; public $Column10 = ""; public $Column11 = ""; public $Column12 = ""; public $Column13 = ""; public $Column14 = ""; public $Column15 = ""; public $Column16 = ""; public $Column17 = ""; public $Column18 = ""; public $Column19 = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "unitable" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["unitable"] = array(); class user extends \samson\activerecord\dbRecord { public static $_table_name = "user"; public static $_own_group = array(); public static $_primary = "UserID"; public static $_attributes = array( "UserID"=>"UserID", "FName"=>"FName", "SName"=>"SName", "TName"=>"TName", "Email"=>"Email", "Password"=>"Password", "md5_email"=>"md5_email", "md5_password"=>"md5_password", "Created"=>"Created", "Modyfied"=>"Modyfied", "GroupID"=>"GroupID", "Active"=>"Active", "Online"=>"Online", "LastLogin"=>"LastLogin", "system"=>"system", ); public static $_table_attributes = array( "UserID"=>"UserID", "FName"=>"FName", "SName"=>"SName", "TName"=>"TName", "Email"=>"Email", "Password"=>"Password", "md5_email"=>"md5_email", "md5_password"=>"md5_password", "Created"=>"Created", "Modyfied"=>"Modyfied", "GroupID"=>"GroupID", "Active"=>"Active", "Online"=>"Online", "LastLogin"=>"LastLogin", "system"=>"system", ); public static $_sql_from = array( "this" => "`user`", ); public static $_relations = array( ); public static $_relation_alias = array( ); public static $_relation_type = array( ); public static $_sql_select = array( "this" => "user.UserID,
user.FName,
user.SName,
user.TName,
user.Email,
user.Password,
user.md5_email,
user.md5_password,
user.Created,
user.Modyfied,
user.GroupID,
user.Active,
user.Online,
user.LastLogin,
user.system", ); public static $_types = array( "UserID"=>"int", "FName"=>"varchar", "SName"=>"varchar", "TName"=>"varchar", "Email"=>"varchar", "Password"=>"varchar", "md5_email"=>"varchar", "md5_password"=>"varchar", "Created"=>"datetime", "Modyfied"=>"timestamp", "GroupID"=>"int", "Active"=>"int", "Online"=>"int", "LastLogin"=>"datetime", "system"=>"int", ); public static $_indeces = array( "GroupID", ); public static $_unique = array( ); public static $_map = array( "UserID"=>"user.UserID", "FName"=>"user.FName", "SName"=>"user.SName", "TName"=>"user.TName", "Email"=>"user.Email", "Password"=>"user.Password", "md5_email"=>"user.md5_email", "md5_password"=>"user.md5_password", "Created"=>"user.Created", "Modyfied"=>"user.Modyfied", "GroupID"=>"user.GroupID", "Active"=>"user.Active", "Online"=>"user.Online", "LastLogin"=>"user.LastLogin", "system"=>"user.system", ); public $UserID = ""; public $FName = ""; public $SName = ""; public $TName = ""; public $Email = ""; public $Password = ""; public $md5_email = ""; public $md5_password = ""; public $Created = ""; public $Modyfied = ""; public $GroupID = ""; public $Active = ""; public $Online = ""; public $LastLogin = ""; public $system = ""; public function __construct( $id = NULL, $class_name = NULL ){ if( !isset($class_name)) $class_name = "user" ; parent::__construct( $id, $class_name ); } } dbRecord::$instances["user"] = array(); class TableRelation { const T_ONE_TO_MANY = 1; const T_ONE_TO_ONE = 0; public static $instances = array(); public $parent; public $child; public $parent_field; public $child_field; public $alias; public $type; public function __construct( $p, $c, $pf = null, $rt = self::T_ONE_TO_ONE, $cf = null, $a = null ) { $this->parent = $p; $this->child = $c; $this->alias = $a; $this->type = $rt; $this->parent_field = $pf; $this->child_field = $cf; self::$instances[] = & $this; } } class QueryHandler { private $handlers = array(); private $params = array(); public function handler( $callable ) { if( is_callable( $callable ) ) { $this->handlers[] = $callable; $args = func_get_args(); array_shift( $args ); $this->params[] = & $args; } else e('Cannot set Query handler - function(##) does not exists', E_SAMSON_ACTIVERECORD_ERROR, $callable ); return $this; } protected function _callHandlers() { foreach ( $this->handlers as $i => $handler ) { $params = array( & $this ); $params = array_merge( $params, $this->params[ $i ] ); call_user_func_array( $handler, $params ); } } } class Query extends QueryHandler { protected $class_name; protected $parameters = array(); public function joins($targetClass, $parentField = null, $childField = null, $relationType = TableRelation::T_ONE_TO_ONE, $alias = null) { return $this; } public function flush(){ foreach ($this->parameters as $param) $param->flush(); return $this; } public function exec( & $return = null){ $args = func_num_args(); return $this->execute( $return, $args ); } public function first( & $return = null ){ $args = func_num_args(); return $this->execute( $return, $args, 1 ); } public function fields( $field_name, & $return = null ){ $args = func_num_args() - 1; return $this->execute( $return, $args, null, array( $this, '_toFieldArray'), array($field_name) ); } public function fieldsNew( $field_name, & $return = null ){ $args = func_num_args() - 1; $return = db()->findFields( $this->class_name, $this, $field_name); $success = is_array( $return ) && sizeof($return); if( $args > 0 ) return $success; else return $return; } protected function & execute( & $result = null, $r_type = false, $limit = null, $handler = null, $handler_args = array() ) { $this->_callHandlers(); $result = db()->find( $this->class_name, $this ); if( isset( $handler ) ) { array_unshift( $handler_args, $result ); $result = call_user_func_array( $handler, $handler_args ); } $this->flush(); $count = sizeof( $result ); $success = is_array( $result ) && $count; if( isset( $limit ) ) { if( $count < $limit ) $result = null; else if( $limit === 1 ) $result = array_shift($result); else if( $limit > 1 ) $result = array_slice( $result, 0, $limit ); } if( $r_type > 0 ) return $success; else return $result; } protected function _toFieldArray( array $records, $field_name ) { $return = array(); foreach ( $records as $record ) $return[] = $record->$field_name; return $return; } } class dbQuery extends Query { public $cConditionGroup; public $link; public $own_condition; public $own_limit; public $own_group; public $own_order; public $own_virtual_fields = array(); public $virtual_fields = array(); protected $debug = false; public $condition; public $limit = array(); public $order = array(); public $group = array(); public $join = array(); protected $stack = array(); protected $params = array(); public function own_limit( $st, $en = NULL ){ $this->own_limit = array($st, $en ); return $this; } public function own_group_by( $params ){ $this->own_group[] = $params; return $this; } public function own_order_by( $field, $direction = 'ASC' ){ $this->own_order = array($field,$direction); return $this; } public function flush() { $this->condition = array(); $this->limit = array(); $this->order = array(); $this->group = array(); $this->join = array(); $this->own_condition = new dbConditionGroup(); $this->condition = new dbConditionGroup(); $this->cConditionGroup = & $this->condition; } public function random( & $return_value = null) { $this->order_by( '', 'RAND()' ); return func_num_args() ? $this->exec( $return_value ) : $this->exec(); } public function or_( $relation = 'OR' ) { $cond_group = new dbConditionGroup( $relation ); $this->cConditionGroup = & $cond_group; $this->condition->arguments[] = $cond_group; return $this; } public function debug($value = true) { db()->debug($this->debug = $value); return $this; } public function isnull( $attribute ){ return $this->cond($attribute,'',dbRelation::ISNULL); } public function notnull( $attribute ){ return $this->cond($attribute,'',dbRelation::NOTNULL); } public function notempty( $attribute ){ return $this->cond($attribute,'',dbRelation::NOT_EQUAL); } public function like( $attribute, $value = '' ){ return $this->cond($attribute, $value,dbRelation::LIKE); } public function id( $value ) { eval( '$_primary = '.$this->class_name.'::$_primary;' ); return $this->cond( $_primary, $value ); } public function where( $condition ){ return $this->cond($condition, '', dbRelation::OWN ); } public function cond( $attribute, $value = '', $relation = dbRelation::EQUAL ) { $destination = & $this->cConditionGroup; if( is_string( $attribute ) ) { $attribute = new dbConditionArgument( $attribute, $value, $relation ); if (property_exists( $this->class_name, $attribute->field )) { $destination = & $this->own_condition; } $destination->arguments[] = $attribute; } else if( is_a( $attribute, ns_classname('Condition','samson\activerecord')) ) { foreach ( $attribute->arguments as $arg ) { $destination = & $this->cConditionGroup; if (is_a($arg, ns_classname('Argument','samson\activerecord'))) { if (property_exists($this->class_name, $arg->field)) { $destination = & $this->own_condition; } } $destination->arguments[] = $attribute; } } return $this; } public function join( $table_name, $class_name = null, $ignore = false ) { $this->join[] = new RelationData( $this->class_name, $table_name, $class_name, $ignore ); return $this; } public function group_by( $field ) { $destination = & $this->group; $destination[] = $field; return $this; } public function limit( $st, $en = NULL, $own = false ) { if($own) $this->own_limit = array( $st, $en ); else $this->limit = array( $st, $en ); return $this; } public function order_by( $field, $direction = 'ASC' ) { $this->order[] = array( $field, $direction ); return $this; } public function add_field( $field, $alias = NULL, $own = true ) { if ( isset($alias) ) $field = $field.' as '.$alias; else $alias = $field; if($own) $this->own_virtual_fields[ $alias ] = $field; else $this->virtual_fields[ $alias ] = $field; return $this; } public function count( $field = '*' ){return db()->count( $this->class_name, $this ); } public function innerCount( $field = '*' ){return db()->innerCount( $this->class_name, $this ); } public function parse( $query_text, array $args = NULL ) { $sorting_pattern = '
		/(?:^(?<method>find_by|find_all_by|all|first|last)_)
			|_order_by_  (?P<order>[a-zа-я0-9]+) _ (?P<order_dir>(?:asc|desc))
			|_limit_ (?P<limit_start>\d+) (?:_(?P<limit_end>\d+))?
			|_group_by_(?P<group>.+)
			|_join_ (?<join>.+)
		/iux'; $args_cnt = 0; if( preg_match_all( $sorting_pattern, $query_text, $global_matches ) ) { $global_matches = array_filter_recursive( $global_matches ); foreach (explode( '_or_', str_ireplace( $global_matches[0], '', $query_text) ) as $group_text ) { $this->or_('AND'); foreach (explode( '_and_', $group_text ) as $condition_text )$this->cond( $condition_text, $args[$args_cnt++] ); } if(isset($global_matches['order'])) $this->order = array( $global_matches['order'][0], $global_matches['order_dir'][0]); if(isset($global_matches['limit_start'])) $this->limit = array( $global_matches['limit_start'][0], $global_matches['limit_end'][0] ); if(isset($global_matches['group'])) $this->group = explode( '_and_', $global_matches['group'][0] ); if(isset($global_matches['join'])) foreach (explode( '_and_', $global_matches['join'][0] ) as $join) $this->join($join); } return $this; } public function __clone() { $p = $this->condition; unset($this->condition); $this->condition = $p; $this->cConditionGroup = & $this->condition; } public function __call( $method_name, array $arguments ) { if( preg_match( '/^(find_by|find_all_by|all)/iu', $method_name, $matches )) { return db()->find( $this->class_name, $this->parse( $method_name, $arguments) ); } else if( property_exists( $this->class_name, $method_name) ) { if( sizeof($arguments) > 1 ) return $this->cond( $method_name, $arguments[0], $arguments[1]); else if( isset($arguments[0]) ) return $this->cond( $method_name, $arguments[0] ); else return $this; } else return e('Не возможно определить метод(##) для создания запроса к БД', E_SAMSON_ACTIVERECORD_ERROR, $method_name ); } public function __construct( $class_name, & $link = null ) { $class_name = ns_classname( $class_name, 'samson\activerecord' ); $this->condition = new dbConditionGroup(); $this->cConditionGroup = & $this->condition; $this->own_condition = new dbConditionGroup(); $this->class_name = $class_name; $this->link = $link; } } class Condition { const REL_AND = 'AND'; const REL_OR = 'OR'; public $arguments = array(); public $relation = self::REL_AND; public function add( $argument, $value = '', $relation = dbRelation::EQUAL ) { if( is_a( $argument, ns_classname('Condition','samson\activerecord'))) { $this->arguments[] = $argument; } else if( is_a( $argument, ns_classname('Argument','samson\activerecord'))) { $this->arguments[] = $argument; } else if( is_string($argument) ) { $this->arguments[] = new Argument( $argument, $value, $relation ); } return $this; } public function __construct( $relation = NULL ){ if( isset($relation) ) $this->relation = $relation; } } class dbConditionGroup extends Condition { } class dbRelation { const EQUAL = '='; const NOT_EQUAL = '!='; const GREATER = '>'; const LOWER = '<'; const GREATER_EQ = '>='; const LOWER_EQ = '<='; const LIKE = ' LIKE '; const NOTNULL = ' IS NOT NULL '; const ISNULL = ' IS NULL '; const OWN = ' !!! '; } class Argument { public $field = ''; public $value; public $relation = dbRelation::EQUAL; public function __construct( $field, $value, $relation = dbRelation::EQUAL ) { $this->field = $field; $this->value = $value; $this->relation = !isset($relation) ? dbRelation::EQUAL : $relation; } } class dbConditionArgument extends Argument { public function __construct( $field, $value, $relation = NULL ) { parent::__construct( $field, $value, $relation ); if( preg_match('/_(?<relation>gte|lte|gt|eq|ne|lt|like)_?/iu', $field, $relation_match ) ) { $this->field = str_replace( $relation_match[0], '', $field ); switch ($relation_match['relation']) { case '>' : case 'gt' : $this->relation = dbRelation::GREATER; break; case '>=' : case 'gte' : $this->relation = dbRelation::GREATER_EQ; break; case '<' : case 'lt' : $this->relation = dbRelation::LOWER; break; case '<=' : case 'lte' : $this->relation = dbRelation::LOWER_EQ; break; case '!=' : case 'ne' : $this->relation = dbRelation::NOT_EQUAL; break; case '=' : case 'eq' : case 'like' : $this->relation = dbRelation::LIKE; break; default : $this->relation = dbRelation::EQUAL; } } } } material::$_sql_from = array_merge( material::$_sql_from, array( "user" => "LEFT JOIN `user` ON `material`.`UserID` = `user`.`UserID`", "gallery" => "LEFT JOIN `gallery` ON `material`.`MaterialID` = `gallery`.`MaterialID`", "materialfield" => "LEFT JOIN `materialfield` ON `material`.`MaterialID` = `materialfield`.`MaterialID`", "field" => "LEFT JOIN `field` ON `materialfield`.`FieldID` = `field`.`FieldID`", "structurematerial" => "LEFT JOIN `structurematerial` ON `material`.`MaterialID` = `structurematerial`.`MaterialID`", "structure" => "LEFT JOIN `structure` ON `structurematerial`.`StructureID` = `structure`.`StructureID`", )); material::$_sql_select = array_merge( material::$_sql_select, array( "user" => "user.UserID as user_UserID,user.FName as user_FName,user.SName as user_SName,user.TName as user_TName,user.Email as user_Email,user.Password as user_Password,user.md5_email as user_md5_email,user.md5_password as user_md5_password,user.Created as user_Created,user.Modyfied as user_Modyfied,user.GroupID as user_GroupID,user.Active as user_Active,user.Online as user_Online,user.LastLogin as user_LastLogin,user.system as user_system", "gallery" => "gallery.PhotoID as gallery_PhotoID,gallery.MaterialID as gallery_MaterialID,gallery.priority as gallery_priority,gallery.Path as gallery_Path,gallery.Src as gallery_Src,gallery.size as gallery_size,gallery.Loaded as gallery_Loaded,gallery.Description as gallery_Description,gallery.Name as gallery_Name,gallery.Active as gallery_Active", "materialfield" => "materialfield.MaterialFieldID as materialfield_MaterialFieldID,materialfield.FieldID as materialfield_FieldID,materialfield.MaterialID as materialfield_MaterialID,materialfield.Value as materialfield_Value,materialfield.numeric_value as materialfield_numeric_value,materialfield.locale as materialfield_locale,materialfield.Active as materialfield_Active", "field" => "field.FieldID as field_FieldID,field.ParentID as field_ParentID,field.Name as field_Name,field.Type as field_Type,field.local as field_local,field.filtered as field_filtered,field.Value as field_Value,field.Description as field_Description,field.UserID as field_UserID,field.Created as field_Created,field.Modyfied as field_Modyfied,field.Active as field_Active,field.system as field_system", "structurematerial" => "structurematerial.StructureMaterialID as structurematerial_StructureMaterialID,structurematerial.StructureID as structurematerial_StructureID,structurematerial.MaterialID as structurematerial_MaterialID,structurematerial.Modified as structurematerial_Modified,structurematerial.Active as structurematerial_Active", "structure" => "structure.StructureID as structure_StructureID,structure.ParentID as structure_ParentID,structure.Name as structure_Name,structure.locale as structure_locale,structure.Created as structure_Created,structure.UserID as structure_UserID,structure.Modyfied as structure_Modyfied,structure.Url as structure_Url,structure.MaterialID as structure_MaterialID,structure.PriorityNumber as structure_PriorityNumber,structure.type as structure_type,structure.Active as structure_Active,structure.system as structure_system", )); material::$_map = array_merge( material::$_map, array( "user_UserID" => "user.UserID", "user_FName" => "user.FName", "user_SName" => "user.SName", "user_TName" => "user.TName", "user_Email" => "user.Email", "user_Password" => "user.Password", "user_md5_email" => "user.md5_email", "user_md5_password" => "user.md5_password", "user_Created" => "user.Created", "user_Modyfied" => "user.Modyfied", "user_GroupID" => "user.GroupID", "user_Active" => "user.Active", "user_Online" => "user.Online", "user_LastLogin" => "user.LastLogin", "user_system" => "user.system", "gallery_PhotoID" => "gallery.PhotoID", "gallery_MaterialID" => "gallery.MaterialID", "gallery_priority" => "gallery.priority", "gallery_Path" => "gallery.Path", "gallery_Src" => "gallery.Src", "gallery_size" => "gallery.size", "gallery_Loaded" => "gallery.Loaded", "gallery_Description" => "gallery.Description", "gallery_Name" => "gallery.Name", "gallery_Active" => "gallery.Active", "materialfield_MaterialFieldID" => "materialfield.MaterialFieldID", "materialfield_FieldID" => "materialfield.FieldID", "materialfield_MaterialID" => "materialfield.MaterialID", "materialfield_Value" => "materialfield.Value", "materialfield_numeric_value" => "materialfield.numeric_value", "materialfield_locale" => "materialfield.locale", "materialfield_Active" => "materialfield.Active", "field_FieldID" => "field.FieldID", "field_ParentID" => "field.ParentID", "field_Name" => "field.Name", "field_Type" => "field.Type", "field_local" => "field.local", "field_filtered" => "field.filtered", "field_Value" => "field.Value", "field_Description" => "field.Description", "field_UserID" => "field.UserID", "field_Created" => "field.Created", "field_Modyfied" => "field.Modyfied", "field_Active" => "field.Active", "field_system" => "field.system", "structurematerial_StructureMaterialID" => "structurematerial.StructureMaterialID", "structurematerial_StructureID" => "structurematerial.StructureID", "structurematerial_MaterialID" => "structurematerial.MaterialID", "structurematerial_Modified" => "structurematerial.Modified", "structurematerial_Active" => "structurematerial.Active", "structure_StructureID" => "structure.StructureID", "structure_ParentID" => "structure.ParentID", "structure_Name" => "structure.Name", "structure_locale" => "structure.locale", "structure_Created" => "structure.Created", "structure_UserID" => "structure.UserID", "structure_Modyfied" => "structure.Modyfied", "structure_Url" => "structure.Url", "structure_MaterialID" => "structure.MaterialID", "structure_PriorityNumber" => "structure.PriorityNumber", "structure_type" => "structure.type", "structure_Active" => "structure.Active", "structure_system" => "structure.system", )); material::$_relation_alias = array( "user" => "user", "gallery" => "gallery", "materialfield" => "materialfield", "field" => "field", "structurematerial" => "structurematerial", "structure" => "structure", ); material::$_relation_type = array( "user" => "0", "gallery" => "1", "materialfield" => "1", "field" => "1", "structurematerial" => "1", "structure" => "1", ); material::$_relations = array( "user" =>array( "UserID" => "user_UserID", "FName" => "user_FName", "SName" => "user_SName", "TName" => "user_TName", "Email" => "user_Email", "Password" => "user_Password", "md5_email" => "user_md5_email", "md5_password" => "user_md5_password", "Created" => "user_Created", "Modyfied" => "user_Modyfied", "GroupID" => "user_GroupID", "Active" => "user_Active", "Online" => "user_Online", "LastLogin" => "user_LastLogin", "system" => "user_system", ), "gallery" =>array( "PhotoID" => "gallery_PhotoID", "MaterialID" => "gallery_MaterialID", "priority" => "gallery_priority", "Path" => "gallery_Path", "Src" => "gallery_Src", "size" => "gallery_size", "Loaded" => "gallery_Loaded", "Description" => "gallery_Description", "Name" => "gallery_Name", "Active" => "gallery_Active", ), "materialfield" =>array( "MaterialFieldID" => "materialfield_MaterialFieldID", "FieldID" => "materialfield_FieldID", "MaterialID" => "materialfield_MaterialID", "Value" => "materialfield_Value", "numeric_value" => "materialfield_numeric_value", "locale" => "materialfield_locale", "Active" => "materialfield_Active", ), "field" =>array( "FieldID" => "field_FieldID", "ParentID" => "field_ParentID", "Name" => "field_Name", "Type" => "field_Type", "local" => "field_local", "filtered" => "field_filtered", "Value" => "field_Value", "Description" => "field_Description", "UserID" => "field_UserID", "Created" => "field_Created", "Modyfied" => "field_Modyfied", "Active" => "field_Active", "system" => "field_system", ), "structurematerial" =>array( "StructureMaterialID" => "structurematerial_StructureMaterialID", "StructureID" => "structurematerial_StructureID", "MaterialID" => "structurematerial_MaterialID", "Modified" => "structurematerial_Modified", "Active" => "structurematerial_Active", ), "structure" =>array( "StructureID" => "structure_StructureID", "ParentID" => "structure_ParentID", "Name" => "structure_Name", "locale" => "structure_locale", "Created" => "structure_Created", "UserID" => "structure_UserID", "Modyfied" => "structure_Modyfied", "Url" => "structure_Url", "MaterialID" => "structure_MaterialID", "PriorityNumber" => "structure_PriorityNumber", "type" => "structure_type", "Active" => "structure_Active", "system" => "structure_system", ), ); materialfield::$_sql_from = array_merge( materialfield::$_sql_from, array( "user" => "LEFT JOIN `user` ON `material`.`UserID` = `user`.`UserID`", "gallery" => "LEFT JOIN `gallery` ON `material`.`MaterialID` = `gallery`.`MaterialID`", "materialfield" => "LEFT JOIN `materialfield` ON `material`.`MaterialID` = `materialfield`.`MaterialID`", "field" => "LEFT JOIN `field` ON `materialfield`.`FieldID` = `field`.`FieldID`", "structurematerial" => "LEFT JOIN `structurematerial` ON `material`.`MaterialID` = `structurematerial`.`MaterialID`", "structure" => "LEFT JOIN `structure` ON `structurematerial`.`StructureID` = `structure`.`StructureID`", "material" => "LEFT JOIN `material` ON `materialfield`.`MaterialID` = `material`.`MaterialID`", )); materialfield::$_sql_select = array_merge( materialfield::$_sql_select, array( "user" => "user.UserID as user_UserID,user.FName as user_FName,user.SName as user_SName,user.TName as user_TName,user.Email as user_Email,user.Password as user_Password,user.md5_email as user_md5_email,user.md5_password as user_md5_password,user.Created as user_Created,user.Modyfied as user_Modyfied,user.GroupID as user_GroupID,user.Active as user_Active,user.Online as user_Online,user.LastLogin as user_LastLogin,user.system as user_system", "gallery" => "gallery.PhotoID as gallery_PhotoID,gallery.MaterialID as gallery_MaterialID,gallery.priority as gallery_priority,gallery.Path as gallery_Path,gallery.Src as gallery_Src,gallery.size as gallery_size,gallery.Loaded as gallery_Loaded,gallery.Description as gallery_Description,gallery.Name as gallery_Name,gallery.Active as gallery_Active", "materialfield" => "materialfield.MaterialFieldID as materialfield_MaterialFieldID,materialfield.FieldID as materialfield_FieldID,materialfield.MaterialID as materialfield_MaterialID,materialfield.Value as materialfield_Value,materialfield.numeric_value as materialfield_numeric_value,materialfield.locale as materialfield_locale,materialfield.Active as materialfield_Active", "field" => "field.FieldID as field_FieldID,field.ParentID as field_ParentID,field.Name as field_Name,field.Type as field_Type,field.local as field_local,field.filtered as field_filtered,field.Value as field_Value,field.Description as field_Description,field.UserID as field_UserID,field.Created as field_Created,field.Modyfied as field_Modyfied,field.Active as field_Active,field.system as field_system", "structurematerial" => "structurematerial.StructureMaterialID as structurematerial_StructureMaterialID,structurematerial.StructureID as structurematerial_StructureID,structurematerial.MaterialID as structurematerial_MaterialID,structurematerial.Modified as structurematerial_Modified,structurematerial.Active as structurematerial_Active", "structure" => "structure.StructureID as structure_StructureID,structure.ParentID as structure_ParentID,structure.Name as structure_Name,structure.locale as structure_locale,structure.Created as structure_Created,structure.UserID as structure_UserID,structure.Modyfied as structure_Modyfied,structure.Url as structure_Url,structure.MaterialID as structure_MaterialID,structure.PriorityNumber as structure_PriorityNumber,structure.type as structure_type,structure.Active as structure_Active,structure.system as structure_system", "material" => "material.MaterialID as material_MaterialID,material.parent_id as material_parent_id,material.Name as material_Name,material.Teaser as material_Teaser,material.Url as material_Url,material.Created as material_Created,material.Modyfied as material_Modyfied,material.UserID as material_UserID,material.Draft as material_Draft,material.type as material_type,material.Published as material_Published,material.Active as material_Active,material.system as material_system", )); materialfield::$_map = array_merge( materialfield::$_map, array( "user_UserID" => "user.UserID", "user_FName" => "user.FName", "user_SName" => "user.SName", "user_TName" => "user.TName", "user_Email" => "user.Email", "user_Password" => "user.Password", "user_md5_email" => "user.md5_email", "user_md5_password" => "user.md5_password", "user_Created" => "user.Created", "user_Modyfied" => "user.Modyfied", "user_GroupID" => "user.GroupID", "user_Active" => "user.Active", "user_Online" => "user.Online", "user_LastLogin" => "user.LastLogin", "user_system" => "user.system", "gallery_PhotoID" => "gallery.PhotoID", "gallery_MaterialID" => "gallery.MaterialID", "gallery_priority" => "gallery.priority", "gallery_Path" => "gallery.Path", "gallery_Src" => "gallery.Src", "gallery_size" => "gallery.size", "gallery_Loaded" => "gallery.Loaded", "gallery_Description" => "gallery.Description", "gallery_Name" => "gallery.Name", "gallery_Active" => "gallery.Active", "materialfield_MaterialFieldID" => "materialfield.MaterialFieldID", "materialfield_FieldID" => "materialfield.FieldID", "materialfield_MaterialID" => "materialfield.MaterialID", "materialfield_Value" => "materialfield.Value", "materialfield_numeric_value" => "materialfield.numeric_value", "materialfield_locale" => "materialfield.locale", "materialfield_Active" => "materialfield.Active", "field_FieldID" => "field.FieldID", "field_ParentID" => "field.ParentID", "field_Name" => "field.Name", "field_Type" => "field.Type", "field_local" => "field.local", "field_filtered" => "field.filtered", "field_Value" => "field.Value", "field_Description" => "field.Description", "field_UserID" => "field.UserID", "field_Created" => "field.Created", "field_Modyfied" => "field.Modyfied", "field_Active" => "field.Active", "field_system" => "field.system", "structurematerial_StructureMaterialID" => "structurematerial.StructureMaterialID", "structurematerial_StructureID" => "structurematerial.StructureID", "structurematerial_MaterialID" => "structurematerial.MaterialID", "structurematerial_Modified" => "structurematerial.Modified", "structurematerial_Active" => "structurematerial.Active", "structure_StructureID" => "structure.StructureID", "structure_ParentID" => "structure.ParentID", "structure_Name" => "structure.Name", "structure_locale" => "structure.locale", "structure_Created" => "structure.Created", "structure_UserID" => "structure.UserID", "structure_Modyfied" => "structure.Modyfied", "structure_Url" => "structure.Url", "structure_MaterialID" => "structure.MaterialID", "structure_PriorityNumber" => "structure.PriorityNumber", "structure_type" => "structure.type", "structure_Active" => "structure.Active", "structure_system" => "structure.system", "material_MaterialID" => "material.MaterialID", "material_parent_id" => "material.parent_id", "material_Name" => "material.Name", "material_Teaser" => "material.Teaser", "material_Url" => "material.Url", "material_Created" => "material.Created", "material_Modyfied" => "material.Modyfied", "material_UserID" => "material.UserID", "material_Draft" => "material.Draft", "material_type" => "material.type", "material_Published" => "material.Published", "material_Active" => "material.Active", "material_system" => "material.system", )); materialfield::$_relation_alias = array( "user" => "user", "gallery" => "gallery", "materialfield" => "materialfield", "field" => "field", "structurematerial" => "structurematerial", "structure" => "structure", "material" => "material", ); materialfield::$_relation_type = array( "user" => "0", "gallery" => "1", "materialfield" => "1", "field" => "0", "structurematerial" => "1", "structure" => "1", "material" => "0", ); materialfield::$_relations = array( "user" =>array( "UserID" => "user_UserID", "FName" => "user_FName", "SName" => "user_SName", "TName" => "user_TName", "Email" => "user_Email", "Password" => "user_Password", "md5_email" => "user_md5_email", "md5_password" => "user_md5_password", "Created" => "user_Created", "Modyfied" => "user_Modyfied", "GroupID" => "user_GroupID", "Active" => "user_Active", "Online" => "user_Online", "LastLogin" => "user_LastLogin", "system" => "user_system", ), "gallery" =>array( "PhotoID" => "gallery_PhotoID", "MaterialID" => "gallery_MaterialID", "priority" => "gallery_priority", "Path" => "gallery_Path", "Src" => "gallery_Src", "size" => "gallery_size", "Loaded" => "gallery_Loaded", "Description" => "gallery_Description", "Name" => "gallery_Name", "Active" => "gallery_Active", ), "materialfield" =>array( "MaterialFieldID" => "materialfield_MaterialFieldID", "FieldID" => "materialfield_FieldID", "MaterialID" => "materialfield_MaterialID", "Value" => "materialfield_Value", "numeric_value" => "materialfield_numeric_value", "locale" => "materialfield_locale", "Active" => "materialfield_Active", ), "field" =>array( "FieldID" => "field_FieldID", "ParentID" => "field_ParentID", "Name" => "field_Name", "Type" => "field_Type", "local" => "field_local", "filtered" => "field_filtered", "Value" => "field_Value", "Description" => "field_Description", "UserID" => "field_UserID", "Created" => "field_Created", "Modyfied" => "field_Modyfied", "Active" => "field_Active", "system" => "field_system", ), "structurematerial" =>array( "StructureMaterialID" => "structurematerial_StructureMaterialID", "StructureID" => "structurematerial_StructureID", "MaterialID" => "structurematerial_MaterialID", "Modified" => "structurematerial_Modified", "Active" => "structurematerial_Active", ), "structure" =>array( "StructureID" => "structure_StructureID", "ParentID" => "structure_ParentID", "Name" => "structure_Name", "locale" => "structure_locale", "Created" => "structure_Created", "UserID" => "structure_UserID", "Modyfied" => "structure_Modyfied", "Url" => "structure_Url", "MaterialID" => "structure_MaterialID", "PriorityNumber" => "structure_PriorityNumber", "type" => "structure_type", "Active" => "structure_Active", "system" => "structure_system", ), "material" =>array( "MaterialID" => "material_MaterialID", "parent_id" => "material_parent_id", "Name" => "material_Name", "Teaser" => "material_Teaser", "Url" => "material_Url", "Created" => "material_Created", "Modyfied" => "material_Modyfied", "UserID" => "material_UserID", "Draft" => "material_Draft", "type" => "material_type", "Published" => "material_Published", "Active" => "material_Active", "system" => "material_system", ), ); structurematerial::$_sql_from = array_merge( structurematerial::$_sql_from, array( "user" => "LEFT JOIN `user` ON `material`.`UserID` = `user`.`UserID`", "gallery" => "LEFT JOIN `gallery` ON `material`.`MaterialID` = `gallery`.`MaterialID`", "materialfield" => "LEFT JOIN `materialfield` ON `structurematerial`.`MaterialID` = `materialfield`.`MaterialID`", "field" => "LEFT JOIN `field` ON `materialfield`.`FieldID` = `field`.`FieldID`", "structurematerial" => "LEFT JOIN `structurematerial` ON `material`.`MaterialID` = `structurematerial`.`MaterialID`", "structure" => "LEFT JOIN `structure` ON `structurematerial`.`StructureID` = `structure`.`StructureID`", "material" => "LEFT JOIN `material` ON `structurematerial`.`MaterialID` = `material`.`MaterialID`", "structure_relation" => "LEFT JOIN `structure_relation` ON `structurematerial`.`StructureID` = `structure_relation`.parent_id", )); structurematerial::$_sql_select = array_merge( structurematerial::$_sql_select, array( "user" => "user.UserID as user_UserID,user.FName as user_FName,user.SName as user_SName,user.TName as user_TName,user.Email as user_Email,user.Password as user_Password,user.md5_email as user_md5_email,user.md5_password as user_md5_password,user.Created as user_Created,user.Modyfied as user_Modyfied,user.GroupID as user_GroupID,user.Active as user_Active,user.Online as user_Online,user.LastLogin as user_LastLogin,user.system as user_system", "gallery" => "gallery.PhotoID as gallery_PhotoID,gallery.MaterialID as gallery_MaterialID,gallery.priority as gallery_priority,gallery.Path as gallery_Path,gallery.Src as gallery_Src,gallery.size as gallery_size,gallery.Loaded as gallery_Loaded,gallery.Description as gallery_Description,gallery.Name as gallery_Name,gallery.Active as gallery_Active", "materialfield" => "materialfield.MaterialFieldID as materialfield_MaterialFieldID,materialfield.FieldID as materialfield_FieldID,materialfield.MaterialID as materialfield_MaterialID,materialfield.Value as materialfield_Value,materialfield.numeric_value as materialfield_numeric_value,materialfield.locale as materialfield_locale,materialfield.Active as materialfield_Active", "field" => "field.FieldID as field_FieldID,field.ParentID as field_ParentID,field.Name as field_Name,field.Type as field_Type,field.local as field_local,field.filtered as field_filtered,field.Value as field_Value,field.Description as field_Description,field.UserID as field_UserID,field.Created as field_Created,field.Modyfied as field_Modyfied,field.Active as field_Active,field.system as field_system", "structurematerial" => "structurematerial.StructureMaterialID as structurematerial_StructureMaterialID,structurematerial.StructureID as structurematerial_StructureID,structurematerial.MaterialID as structurematerial_MaterialID,structurematerial.Modified as structurematerial_Modified,structurematerial.Active as structurematerial_Active", "structure" => "structure.StructureID as structure_StructureID,structure.ParentID as structure_ParentID,structure.Name as structure_Name,structure.locale as structure_locale,structure.Created as structure_Created,structure.UserID as structure_UserID,structure.Modyfied as structure_Modyfied,structure.Url as structure_Url,structure.MaterialID as structure_MaterialID,structure.PriorityNumber as structure_PriorityNumber,structure.type as structure_type,structure.Active as structure_Active,structure.system as structure_system", "material" => "material.MaterialID as material_MaterialID,material.parent_id as material_parent_id,material.Name as material_Name,material.Teaser as material_Teaser,material.Url as material_Url,material.Created as material_Created,material.Modyfied as material_Modyfied,material.UserID as material_UserID,material.Draft as material_Draft,material.type as material_type,material.Published as material_Published,material.Active as material_Active,material.system as material_system", "structure_relation" => "structure_relation.structure_relation_id as structure_relation_structure_relation_id,structure_relation.parent_id as structure_relation_parent_id,structure_relation.child_id as structure_relation_child_id", )); structurematerial::$_map = array_merge( structurematerial::$_map, array( "user_UserID" => "user.UserID", "user_FName" => "user.FName", "user_SName" => "user.SName", "user_TName" => "user.TName", "user_Email" => "user.Email", "user_Password" => "user.Password", "user_md5_email" => "user.md5_email", "user_md5_password" => "user.md5_password", "user_Created" => "user.Created", "user_Modyfied" => "user.Modyfied", "user_GroupID" => "user.GroupID", "user_Active" => "user.Active", "user_Online" => "user.Online", "user_LastLogin" => "user.LastLogin", "user_system" => "user.system", "gallery_PhotoID" => "gallery.PhotoID", "gallery_MaterialID" => "gallery.MaterialID", "gallery_priority" => "gallery.priority", "gallery_Path" => "gallery.Path", "gallery_Src" => "gallery.Src", "gallery_size" => "gallery.size", "gallery_Loaded" => "gallery.Loaded", "gallery_Description" => "gallery.Description", "gallery_Name" => "gallery.Name", "gallery_Active" => "gallery.Active", "materialfield_MaterialFieldID" => "materialfield.MaterialFieldID", "materialfield_FieldID" => "materialfield.FieldID", "materialfield_MaterialID" => "materialfield.MaterialID", "materialfield_Value" => "materialfield.Value", "materialfield_numeric_value" => "materialfield.numeric_value", "materialfield_locale" => "materialfield.locale", "materialfield_Active" => "materialfield.Active", "field_FieldID" => "field.FieldID", "field_ParentID" => "field.ParentID", "field_Name" => "field.Name", "field_Type" => "field.Type", "field_local" => "field.local", "field_filtered" => "field.filtered", "field_Value" => "field.Value", "field_Description" => "field.Description", "field_UserID" => "field.UserID", "field_Created" => "field.Created", "field_Modyfied" => "field.Modyfied", "field_Active" => "field.Active", "field_system" => "field.system", "structurematerial_StructureMaterialID" => "structurematerial.StructureMaterialID", "structurematerial_StructureID" => "structurematerial.StructureID", "structurematerial_MaterialID" => "structurematerial.MaterialID", "structurematerial_Modified" => "structurematerial.Modified", "structurematerial_Active" => "structurematerial.Active", "structure_StructureID" => "structure.StructureID", "structure_ParentID" => "structure.ParentID", "structure_Name" => "structure.Name", "structure_locale" => "structure.locale", "structure_Created" => "structure.Created", "structure_UserID" => "structure.UserID", "structure_Modyfied" => "structure.Modyfied", "structure_Url" => "structure.Url", "structure_MaterialID" => "structure.MaterialID", "structure_PriorityNumber" => "structure.PriorityNumber", "structure_type" => "structure.type", "structure_Active" => "structure.Active", "structure_system" => "structure.system", "material_MaterialID" => "material.MaterialID", "material_parent_id" => "material.parent_id", "material_Name" => "material.Name", "material_Teaser" => "material.Teaser", "material_Url" => "material.Url", "material_Created" => "material.Created", "material_Modyfied" => "material.Modyfied", "material_UserID" => "material.UserID", "material_Draft" => "material.Draft", "material_type" => "material.type", "material_Published" => "material.Published", "material_Active" => "material.Active", "material_system" => "material.system", "structure_relation_structure_relation_id" => "structure_relation.structure_relation_id", "structure_relation_parent_id" => "structure_relation.parent_id", "structure_relation_child_id" => "structure_relation.child_id", )); structurematerial::$_relation_alias = array( "user" => "user", "gallery" => "gallery", "materialfield" => "materialfield", "field" => "field", "structurematerial" => "structurematerial", "structure" => "structure", "material" => "material", "structure_relation" => "structure_relation", ); structurematerial::$_relation_type = array( "user" => "0", "gallery" => "1", "materialfield" => "1", "field" => "0", "structurematerial" => "1", "structure" => "0", "material" => "1", "structure_relation" => "1", ); structurematerial::$_relations = array( "user" =>array( "UserID" => "user_UserID", "FName" => "user_FName", "SName" => "user_SName", "TName" => "user_TName", "Email" => "user_Email", "Password" => "user_Password", "md5_email" => "user_md5_email", "md5_password" => "user_md5_password", "Created" => "user_Created", "Modyfied" => "user_Modyfied", "GroupID" => "user_GroupID", "Active" => "user_Active", "Online" => "user_Online", "LastLogin" => "user_LastLogin", "system" => "user_system", ), "gallery" =>array( "PhotoID" => "gallery_PhotoID", "MaterialID" => "gallery_MaterialID", "priority" => "gallery_priority", "Path" => "gallery_Path", "Src" => "gallery_Src", "size" => "gallery_size", "Loaded" => "gallery_Loaded", "Description" => "gallery_Description", "Name" => "gallery_Name", "Active" => "gallery_Active", ), "materialfield" =>array( "MaterialFieldID" => "materialfield_MaterialFieldID", "FieldID" => "materialfield_FieldID", "MaterialID" => "materialfield_MaterialID", "Value" => "materialfield_Value", "numeric_value" => "materialfield_numeric_value", "locale" => "materialfield_locale", "Active" => "materialfield_Active", ), "field" =>array( "FieldID" => "field_FieldID", "ParentID" => "field_ParentID", "Name" => "field_Name", "Type" => "field_Type", "local" => "field_local", "filtered" => "field_filtered", "Value" => "field_Value", "Description" => "field_Description", "UserID" => "field_UserID", "Created" => "field_Created", "Modyfied" => "field_Modyfied", "Active" => "field_Active", "system" => "field_system", ), "structurematerial" =>array( "StructureMaterialID" => "structurematerial_StructureMaterialID", "StructureID" => "structurematerial_StructureID", "MaterialID" => "structurematerial_MaterialID", "Modified" => "structurematerial_Modified", "Active" => "structurematerial_Active", ), "structure" =>array( "StructureID" => "structure_StructureID", "ParentID" => "structure_ParentID", "Name" => "structure_Name", "locale" => "structure_locale", "Created" => "structure_Created", "UserID" => "structure_UserID", "Modyfied" => "structure_Modyfied", "Url" => "structure_Url", "MaterialID" => "structure_MaterialID", "PriorityNumber" => "structure_PriorityNumber", "type" => "structure_type", "Active" => "structure_Active", "system" => "structure_system", ), "material" =>array( "MaterialID" => "material_MaterialID", "parent_id" => "material_parent_id", "Name" => "material_Name", "Teaser" => "material_Teaser", "Url" => "material_Url", "Created" => "material_Created", "Modyfied" => "material_Modyfied", "UserID" => "material_UserID", "Draft" => "material_Draft", "type" => "material_type", "Published" => "material_Published", "Active" => "material_Active", "system" => "material_system", ), "structure_relation" =>array( "structure_relation_id" => "structure_relation_structure_relation_id", "parent_id" => "structure_relation_parent_id", "child_id" => "structure_relation_child_id", ), ); structure::$_sql_from = array_merge( structure::$_sql_from, array( "user" => "LEFT JOIN `user` ON `structure`.`UserID` = `user`.`UserID`", "gallery" => "LEFT JOIN `gallery` ON `material`.`MaterialID` = `gallery`.`MaterialID`", "materialfield" => "LEFT JOIN `materialfield` ON `structurematerial`.`MaterialID` = `materialfield`.`MaterialID`", "field" => "LEFT JOIN `field` ON `materialfield`.`FieldID` = `field`.`FieldID`", "structurematerial" => "LEFT JOIN `structurematerial` ON `structure`.`StructureID` = `structurematerial`.`StructureID`", "structure" => "LEFT JOIN `structure` ON `structurematerial`.`StructureID` = `structure`.`StructureID`", "material" => "LEFT JOIN `material` ON `structurematerial`.`MaterialID` = `material`.`MaterialID`", "structure_relation" => "LEFT JOIN `structure_relation` ON `structurematerial`.`StructureID` = `structure_relation`.parent_id", "manymaterials" => "LEFT JOIN `gallery` AS manymaterials ON `structurematerial`.`MaterialID` = `manymaterials`.`MaterialID`", "_mf" => "LEFT JOIN `materialfield` AS _mf ON `material`.`MaterialID` = `_mf`.MaterialID", "children_relations" => "LEFT JOIN `structure_relation` AS children_relations ON `structure`.`StructureID` = `children_relations`.parent_id", "children" => "LEFT JOIN `structure` AS children ON `children_relations`.`child_id` = `children`.StructureID", "parents_relations" => "LEFT JOIN `structure_relation` AS parents_relations ON `structure`.`StructureID` = `parents_relations`.child_id", "parents" => "LEFT JOIN `structure` AS parents ON `parents_relations`.`parent_id` = `parents`.StructureID", )); structure::$_sql_select = array_merge( structure::$_sql_select, array( "user" => "user.UserID as user_UserID,user.FName as user_FName,user.SName as user_SName,user.TName as user_TName,user.Email as user_Email,user.Password as user_Password,user.md5_email as user_md5_email,user.md5_password as user_md5_password,user.Created as user_Created,user.Modyfied as user_Modyfied,user.GroupID as user_GroupID,user.Active as user_Active,user.Online as user_Online,user.LastLogin as user_LastLogin,user.system as user_system", "gallery" => "gallery.PhotoID as gallery_PhotoID,gallery.MaterialID as gallery_MaterialID,gallery.priority as gallery_priority,gallery.Path as gallery_Path,gallery.Src as gallery_Src,gallery.size as gallery_size,gallery.Loaded as gallery_Loaded,gallery.Description as gallery_Description,gallery.Name as gallery_Name,gallery.Active as gallery_Active", "materialfield" => "materialfield.MaterialFieldID as materialfield_MaterialFieldID,materialfield.FieldID as materialfield_FieldID,materialfield.MaterialID as materialfield_MaterialID,materialfield.Value as materialfield_Value,materialfield.numeric_value as materialfield_numeric_value,materialfield.locale as materialfield_locale,materialfield.Active as materialfield_Active", "field" => "field.FieldID as field_FieldID,field.ParentID as field_ParentID,field.Name as field_Name,field.Type as field_Type,field.local as field_local,field.filtered as field_filtered,field.Value as field_Value,field.Description as field_Description,field.UserID as field_UserID,field.Created as field_Created,field.Modyfied as field_Modyfied,field.Active as field_Active,field.system as field_system", "structurematerial" => "structurematerial.StructureMaterialID as structurematerial_StructureMaterialID,structurematerial.StructureID as structurematerial_StructureID,structurematerial.MaterialID as structurematerial_MaterialID,structurematerial.Modified as structurematerial_Modified,structurematerial.Active as structurematerial_Active", "structure" => "structure.StructureID as structure_StructureID,structure.ParentID as structure_ParentID,structure.Name as structure_Name,structure.locale as structure_locale,structure.Created as structure_Created,structure.UserID as structure_UserID,structure.Modyfied as structure_Modyfied,structure.Url as structure_Url,structure.MaterialID as structure_MaterialID,structure.PriorityNumber as structure_PriorityNumber,structure.type as structure_type,structure.Active as structure_Active,structure.system as structure_system", "material" => "material.MaterialID as material_MaterialID,material.parent_id as material_parent_id,material.Name as material_Name,material.Teaser as material_Teaser,material.Url as material_Url,material.Created as material_Created,material.Modyfied as material_Modyfied,material.UserID as material_UserID,material.Draft as material_Draft,material.type as material_type,material.Published as material_Published,material.Active as material_Active,material.system as material_system", "structure_relation" => "structure_relation.structure_relation_id as structure_relation_structure_relation_id,structure_relation.parent_id as structure_relation_parent_id,structure_relation.child_id as structure_relation_child_id", "manymaterials" => "manymaterials.PhotoID as manymaterials_PhotoID,manymaterials.MaterialID as manymaterials_MaterialID,manymaterials.priority as manymaterials_priority,manymaterials.Path as manymaterials_Path,manymaterials.Src as manymaterials_Src,manymaterials.size as manymaterials_size,manymaterials.Loaded as manymaterials_Loaded,manymaterials.Description as manymaterials_Description,manymaterials.Name as manymaterials_Name,manymaterials.Active as manymaterials_Active", "_mf" => "_mf.MaterialFieldID as _mf_MaterialFieldID,_mf.FieldID as _mf_FieldID,_mf.MaterialID as _mf_MaterialID,_mf.Value as _mf_Value,_mf.numeric_value as _mf_numeric_value,_mf.locale as _mf_locale,_mf.Active as _mf_Active", "children_relations" => "children_relations.structure_relation_id as children_relations_structure_relation_id,children_relations.parent_id as children_relations_parent_id,children_relations.child_id as children_relations_child_id", "children" => "children.StructureID as children_StructureID,children.ParentID as children_ParentID,children.Name as children_Name,children.locale as children_locale,children.Created as children_Created,children.UserID as children_UserID,children.Modyfied as children_Modyfied,children.Url as children_Url,children.MaterialID as children_MaterialID,children.PriorityNumber as children_PriorityNumber,children.type as children_type,children.Active as children_Active,children.system as children_system", "parents_relations" => "parents_relations.structure_relation_id as parents_relations_structure_relation_id,parents_relations.parent_id as parents_relations_parent_id,parents_relations.child_id as parents_relations_child_id", "parents" => "parents.StructureID as parents_StructureID,parents.ParentID as parents_ParentID,parents.Name as parents_Name,parents.locale as parents_locale,parents.Created as parents_Created,parents.UserID as parents_UserID,parents.Modyfied as parents_Modyfied,parents.Url as parents_Url,parents.MaterialID as parents_MaterialID,parents.PriorityNumber as parents_PriorityNumber,parents.type as parents_type,parents.Active as parents_Active,parents.system as parents_system", )); structure::$_map = array_merge( structure::$_map, array( "user_UserID" => "user.UserID", "user_FName" => "user.FName", "user_SName" => "user.SName", "user_TName" => "user.TName", "user_Email" => "user.Email", "user_Password" => "user.Password", "user_md5_email" => "user.md5_email", "user_md5_password" => "user.md5_password", "user_Created" => "user.Created", "user_Modyfied" => "user.Modyfied", "user_GroupID" => "user.GroupID", "user_Active" => "user.Active", "user_Online" => "user.Online", "user_LastLogin" => "user.LastLogin", "user_system" => "user.system", "gallery_PhotoID" => "gallery.PhotoID", "gallery_MaterialID" => "gallery.MaterialID", "gallery_priority" => "gallery.priority", "gallery_Path" => "gallery.Path", "gallery_Src" => "gallery.Src", "gallery_size" => "gallery.size", "gallery_Loaded" => "gallery.Loaded", "gallery_Description" => "gallery.Description", "gallery_Name" => "gallery.Name", "gallery_Active" => "gallery.Active", "materialfield_MaterialFieldID" => "materialfield.MaterialFieldID", "materialfield_FieldID" => "materialfield.FieldID", "materialfield_MaterialID" => "materialfield.MaterialID", "materialfield_Value" => "materialfield.Value", "materialfield_numeric_value" => "materialfield.numeric_value", "materialfield_locale" => "materialfield.locale", "materialfield_Active" => "materialfield.Active", "field_FieldID" => "field.FieldID", "field_ParentID" => "field.ParentID", "field_Name" => "field.Name", "field_Type" => "field.Type", "field_local" => "field.local", "field_filtered" => "field.filtered", "field_Value" => "field.Value", "field_Description" => "field.Description", "field_UserID" => "field.UserID", "field_Created" => "field.Created", "field_Modyfied" => "field.Modyfied", "field_Active" => "field.Active", "field_system" => "field.system", "structurematerial_StructureMaterialID" => "structurematerial.StructureMaterialID", "structurematerial_StructureID" => "structurematerial.StructureID", "structurematerial_MaterialID" => "structurematerial.MaterialID", "structurematerial_Modified" => "structurematerial.Modified", "structurematerial_Active" => "structurematerial.Active", "structure_StructureID" => "structure.StructureID", "structure_ParentID" => "structure.ParentID", "structure_Name" => "structure.Name", "structure_locale" => "structure.locale", "structure_Created" => "structure.Created", "structure_UserID" => "structure.UserID", "structure_Modyfied" => "structure.Modyfied", "structure_Url" => "structure.Url", "structure_MaterialID" => "structure.MaterialID", "structure_PriorityNumber" => "structure.PriorityNumber", "structure_type" => "structure.type", "structure_Active" => "structure.Active", "structure_system" => "structure.system", "material_MaterialID" => "material.MaterialID", "material_parent_id" => "material.parent_id", "material_Name" => "material.Name", "material_Teaser" => "material.Teaser", "material_Url" => "material.Url", "material_Created" => "material.Created", "material_Modyfied" => "material.Modyfied", "material_UserID" => "material.UserID", "material_Draft" => "material.Draft", "material_type" => "material.type", "material_Published" => "material.Published", "material_Active" => "material.Active", "material_system" => "material.system", "structure_relation_structure_relation_id" => "structure_relation.structure_relation_id", "structure_relation_parent_id" => "structure_relation.parent_id", "structure_relation_child_id" => "structure_relation.child_id", "manymaterials_PhotoID" => "manymaterials.PhotoID", "manymaterials_MaterialID" => "manymaterials.MaterialID", "manymaterials_priority" => "manymaterials.priority", "manymaterials_Path" => "manymaterials.Path", "manymaterials_Src" => "manymaterials.Src", "manymaterials_size" => "manymaterials.size", "manymaterials_Loaded" => "manymaterials.Loaded", "manymaterials_Description" => "manymaterials.Description", "manymaterials_Name" => "manymaterials.Name", "manymaterials_Active" => "manymaterials.Active", "_mf_MaterialFieldID" => "_mf.MaterialFieldID", "_mf_FieldID" => "_mf.FieldID", "_mf_MaterialID" => "_mf.MaterialID", "_mf_Value" => "_mf.Value", "_mf_numeric_value" => "_mf.numeric_value", "_mf_locale" => "_mf.locale", "_mf_Active" => "_mf.Active", "children_relations_structure_relation_id" => "children_relations.structure_relation_id", "children_relations_parent_id" => "children_relations.parent_id", "children_relations_child_id" => "children_relations.child_id", "children_StructureID" => "children.StructureID", "children_ParentID" => "children.ParentID", "children_Name" => "children.Name", "children_locale" => "children.locale", "children_Created" => "children.Created", "children_UserID" => "children.UserID", "children_Modyfied" => "children.Modyfied", "children_Url" => "children.Url", "children_MaterialID" => "children.MaterialID", "children_PriorityNumber" => "children.PriorityNumber", "children_type" => "children.type", "children_Active" => "children.Active", "children_system" => "children.system", "parents_relations_structure_relation_id" => "parents_relations.structure_relation_id", "parents_relations_parent_id" => "parents_relations.parent_id", "parents_relations_child_id" => "parents_relations.child_id", "parents_StructureID" => "parents.StructureID", "parents_ParentID" => "parents.ParentID", "parents_Name" => "parents.Name", "parents_locale" => "parents.locale", "parents_Created" => "parents.Created", "parents_UserID" => "parents.UserID", "parents_Modyfied" => "parents.Modyfied", "parents_Url" => "parents.Url", "parents_MaterialID" => "parents.MaterialID", "parents_PriorityNumber" => "parents.PriorityNumber", "parents_type" => "parents.type", "parents_Active" => "parents.Active", "parents_system" => "parents.system", )); structure::$_relation_alias = array( "user" => "user", "gallery" => "gallery", "materialfield" => "materialfield", "field" => "field", "structurematerial" => "structurematerial", "structure" => "structure", "material" => "material", "structure_relation" => "structure_relation", "manymaterials" => "gallery", "_mf" => "materialfield", "children_relations" => "structure_relation", "children" => "structure", "parents_relations" => "structure_relation", "parents" => "structure", ); structure::$_relation_type = array( "user" => "0", "gallery" => "1", "materialfield" => "1", "field" => "0", "structurematerial" => "1", "structure" => "0", "material" => "1", "structure_relation" => "1", "manymaterials" => "1", "_mf" => "1", "children_relations" => "1", "children" => "1", "parents_relations" => "1", "parents" => "1", ); structure::$_relations = array( "user" =>array( "UserID" => "user_UserID", "FName" => "user_FName", "SName" => "user_SName", "TName" => "user_TName", "Email" => "user_Email", "Password" => "user_Password", "md5_email" => "user_md5_email", "md5_password" => "user_md5_password", "Created" => "user_Created", "Modyfied" => "user_Modyfied", "GroupID" => "user_GroupID", "Active" => "user_Active", "Online" => "user_Online", "LastLogin" => "user_LastLogin", "system" => "user_system", ), "gallery" =>array( "PhotoID" => "gallery_PhotoID", "MaterialID" => "gallery_MaterialID", "priority" => "gallery_priority", "Path" => "gallery_Path", "Src" => "gallery_Src", "size" => "gallery_size", "Loaded" => "gallery_Loaded", "Description" => "gallery_Description", "Name" => "gallery_Name", "Active" => "gallery_Active", ), "materialfield" =>array( "MaterialFieldID" => "materialfield_MaterialFieldID", "FieldID" => "materialfield_FieldID", "MaterialID" => "materialfield_MaterialID", "Value" => "materialfield_Value", "numeric_value" => "materialfield_numeric_value", "locale" => "materialfield_locale", "Active" => "materialfield_Active", ), "field" =>array( "FieldID" => "field_FieldID", "ParentID" => "field_ParentID", "Name" => "field_Name", "Type" => "field_Type", "local" => "field_local", "filtered" => "field_filtered", "Value" => "field_Value", "Description" => "field_Description", "UserID" => "field_UserID", "Created" => "field_Created", "Modyfied" => "field_Modyfied", "Active" => "field_Active", "system" => "field_system", ), "structurematerial" =>array( "StructureMaterialID" => "structurematerial_StructureMaterialID", "StructureID" => "structurematerial_StructureID", "MaterialID" => "structurematerial_MaterialID", "Modified" => "structurematerial_Modified", "Active" => "structurematerial_Active", ), "structure" =>array( "StructureID" => "structure_StructureID", "ParentID" => "structure_ParentID", "Name" => "structure_Name", "locale" => "structure_locale", "Created" => "structure_Created", "UserID" => "structure_UserID", "Modyfied" => "structure_Modyfied", "Url" => "structure_Url", "MaterialID" => "structure_MaterialID", "PriorityNumber" => "structure_PriorityNumber", "type" => "structure_type", "Active" => "structure_Active", "system" => "structure_system", ), "material" =>array( "MaterialID" => "material_MaterialID", "parent_id" => "material_parent_id", "Name" => "material_Name", "Teaser" => "material_Teaser", "Url" => "material_Url", "Created" => "material_Created", "Modyfied" => "material_Modyfied", "UserID" => "material_UserID", "Draft" => "material_Draft", "type" => "material_type", "Published" => "material_Published", "Active" => "material_Active", "system" => "material_system", ), "structure_relation" =>array( "structure_relation_id" => "structure_relation_structure_relation_id", "parent_id" => "structure_relation_parent_id", "child_id" => "structure_relation_child_id", ), "manymaterials" =>array( "PhotoID" => "manymaterials_PhotoID", "MaterialID" => "manymaterials_MaterialID", "priority" => "manymaterials_priority", "Path" => "manymaterials_Path", "Src" => "manymaterials_Src", "size" => "manymaterials_size", "Loaded" => "manymaterials_Loaded", "Description" => "manymaterials_Description", "Name" => "manymaterials_Name", "Active" => "manymaterials_Active", ), "_mf" =>array( "MaterialFieldID" => "_mf_MaterialFieldID", "FieldID" => "_mf_FieldID", "MaterialID" => "_mf_MaterialID", "Value" => "_mf_Value", "numeric_value" => "_mf_numeric_value", "locale" => "_mf_locale", "Active" => "_mf_Active", ), "children_relations" =>array( "structure_relation_id" => "children_relations_structure_relation_id", "parent_id" => "children_relations_parent_id", "child_id" => "children_relations_child_id", ), "children" =>array( "StructureID" => "children_StructureID", "ParentID" => "children_ParentID", "Name" => "children_Name", "locale" => "children_locale", "Created" => "children_Created", "UserID" => "children_UserID", "Modyfied" => "children_Modyfied", "Url" => "children_Url", "MaterialID" => "children_MaterialID", "PriorityNumber" => "children_PriorityNumber", "type" => "children_type", "Active" => "children_Active", "system" => "children_system", ), "parents_relations" =>array( "structure_relation_id" => "parents_relations_structure_relation_id", "parent_id" => "parents_relations_parent_id", "child_id" => "parents_relations_child_id", ), "parents" =>array( "StructureID" => "parents_StructureID", "ParentID" => "parents_ParentID", "Name" => "parents_Name", "locale" => "parents_locale", "Created" => "parents_Created", "UserID" => "parents_UserID", "Modyfied" => "parents_Modyfied", "Url" => "parents_Url", "MaterialID" => "parents_MaterialID", "PriorityNumber" => "parents_PriorityNumber", "type" => "parents_type", "Active" => "parents_Active", "system" => "parents_system", ), ); related_materials::$_sql_from = array_merge( related_materials::$_sql_from, array( "user" => "LEFT JOIN `user` ON `structure`.`UserID` = `user`.`UserID`", "gallery" => "LEFT JOIN `gallery` ON `material`.`MaterialID` = `gallery`.`MaterialID`", "materialfield" => "LEFT JOIN `materialfield` ON `related_materials`.`first_material` = `materialfield`.MaterialID", "field" => "LEFT JOIN `field` ON `materialfield`.`FieldID` = `field`.`FieldID`", "structurematerial" => "LEFT JOIN `structurematerial` ON `structure`.`StructureID` = `structurematerial`.`StructureID`", "structure" => "LEFT JOIN `structure` ON `structurematerial`.`StructureID` = `structure`.`StructureID`", "material" => "LEFT JOIN `material` ON `related_materials`.`first_material` = `material`.MaterialID", "structure_relation" => "LEFT JOIN `structure_relation` ON `structurematerial`.`StructureID` = `structure_relation`.parent_id", "manymaterials" => "LEFT JOIN `gallery` AS manymaterials ON `structurematerial`.`MaterialID` = `manymaterials`.`MaterialID`", "_mf" => "LEFT JOIN `materialfield` AS _mf ON `material`.`MaterialID` = `_mf`.MaterialID", "children_relations" => "LEFT JOIN `structure_relation` AS children_relations ON `structure`.`StructureID` = `children_relations`.parent_id", "children" => "LEFT JOIN `structure` AS children ON `children_relations`.`child_id` = `children`.StructureID", "parents_relations" => "LEFT JOIN `structure_relation` AS parents_relations ON `structure`.`StructureID` = `parents_relations`.child_id", "parents" => "LEFT JOIN `structure` AS parents ON `parents_relations`.`parent_id` = `parents`.StructureID", )); related_materials::$_sql_select = array_merge( related_materials::$_sql_select, array( "user" => "user.UserID as user_UserID,user.FName as user_FName,user.SName as user_SName,user.TName as user_TName,user.Email as user_Email,user.Password as user_Password,user.md5_email as user_md5_email,user.md5_password as user_md5_password,user.Created as user_Created,user.Modyfied as user_Modyfied,user.GroupID as user_GroupID,user.Active as user_Active,user.Online as user_Online,user.LastLogin as user_LastLogin,user.system as user_system", "gallery" => "gallery.PhotoID as gallery_PhotoID,gallery.MaterialID as gallery_MaterialID,gallery.priority as gallery_priority,gallery.Path as gallery_Path,gallery.Src as gallery_Src,gallery.size as gallery_size,gallery.Loaded as gallery_Loaded,gallery.Description as gallery_Description,gallery.Name as gallery_Name,gallery.Active as gallery_Active", "materialfield" => "materialfield.MaterialFieldID as materialfield_MaterialFieldID,materialfield.FieldID as materialfield_FieldID,materialfield.MaterialID as materialfield_MaterialID,materialfield.Value as materialfield_Value,materialfield.numeric_value as materialfield_numeric_value,materialfield.locale as materialfield_locale,materialfield.Active as materialfield_Active", "field" => "field.FieldID as field_FieldID,field.ParentID as field_ParentID,field.Name as field_Name,field.Type as field_Type,field.local as field_local,field.filtered as field_filtered,field.Value as field_Value,field.Description as field_Description,field.UserID as field_UserID,field.Created as field_Created,field.Modyfied as field_Modyfied,field.Active as field_Active,field.system as field_system", "structurematerial" => "structurematerial.StructureMaterialID as structurematerial_StructureMaterialID,structurematerial.StructureID as structurematerial_StructureID,structurematerial.MaterialID as structurematerial_MaterialID,structurematerial.Modified as structurematerial_Modified,structurematerial.Active as structurematerial_Active", "structure" => "structure.StructureID as structure_StructureID,structure.ParentID as structure_ParentID,structure.Name as structure_Name,structure.locale as structure_locale,structure.Created as structure_Created,structure.UserID as structure_UserID,structure.Modyfied as structure_Modyfied,structure.Url as structure_Url,structure.MaterialID as structure_MaterialID,structure.PriorityNumber as structure_PriorityNumber,structure.type as structure_type,structure.Active as structure_Active,structure.system as structure_system", "material" => "material.MaterialID as material_MaterialID,material.parent_id as material_parent_id,material.Name as material_Name,material.Teaser as material_Teaser,material.Url as material_Url,material.Created as material_Created,material.Modyfied as material_Modyfied,material.UserID as material_UserID,material.Draft as material_Draft,material.type as material_type,material.Published as material_Published,material.Active as material_Active,material.system as material_system", "structure_relation" => "structure_relation.structure_relation_id as structure_relation_structure_relation_id,structure_relation.parent_id as structure_relation_parent_id,structure_relation.child_id as structure_relation_child_id", "manymaterials" => "manymaterials.PhotoID as manymaterials_PhotoID,manymaterials.MaterialID as manymaterials_MaterialID,manymaterials.priority as manymaterials_priority,manymaterials.Path as manymaterials_Path,manymaterials.Src as manymaterials_Src,manymaterials.size as manymaterials_size,manymaterials.Loaded as manymaterials_Loaded,manymaterials.Description as manymaterials_Description,manymaterials.Name as manymaterials_Name,manymaterials.Active as manymaterials_Active", "_mf" => "_mf.MaterialFieldID as _mf_MaterialFieldID,_mf.FieldID as _mf_FieldID,_mf.MaterialID as _mf_MaterialID,_mf.Value as _mf_Value,_mf.numeric_value as _mf_numeric_value,_mf.locale as _mf_locale,_mf.Active as _mf_Active", "children_relations" => "children_relations.structure_relation_id as children_relations_structure_relation_id,children_relations.parent_id as children_relations_parent_id,children_relations.child_id as children_relations_child_id", "children" => "children.StructureID as children_StructureID,children.ParentID as children_ParentID,children.Name as children_Name,children.locale as children_locale,children.Created as children_Created,children.UserID as children_UserID,children.Modyfied as children_Modyfied,children.Url as children_Url,children.MaterialID as children_MaterialID,children.PriorityNumber as children_PriorityNumber,children.type as children_type,children.Active as children_Active,children.system as children_system", "parents_relations" => "parents_relations.structure_relation_id as parents_relations_structure_relation_id,parents_relations.parent_id as parents_relations_parent_id,parents_relations.child_id as parents_relations_child_id", "parents" => "parents.StructureID as parents_StructureID,parents.ParentID as parents_ParentID,parents.Name as parents_Name,parents.locale as parents_locale,parents.Created as parents_Created,parents.UserID as parents_UserID,parents.Modyfied as parents_Modyfied,parents.Url as parents_Url,parents.MaterialID as parents_MaterialID,parents.PriorityNumber as parents_PriorityNumber,parents.type as parents_type,parents.Active as parents_Active,parents.system as parents_system", )); related_materials::$_map = array_merge( related_materials::$_map, array( "user_UserID" => "user.UserID", "user_FName" => "user.FName", "user_SName" => "user.SName", "user_TName" => "user.TName", "user_Email" => "user.Email", "user_Password" => "user.Password", "user_md5_email" => "user.md5_email", "user_md5_password" => "user.md5_password", "user_Created" => "user.Created", "user_Modyfied" => "user.Modyfied", "user_GroupID" => "user.GroupID", "user_Active" => "user.Active", "user_Online" => "user.Online", "user_LastLogin" => "user.LastLogin", "user_system" => "user.system", "gallery_PhotoID" => "gallery.PhotoID", "gallery_MaterialID" => "gallery.MaterialID", "gallery_priority" => "gallery.priority", "gallery_Path" => "gallery.Path", "gallery_Src" => "gallery.Src", "gallery_size" => "gallery.size", "gallery_Loaded" => "gallery.Loaded", "gallery_Description" => "gallery.Description", "gallery_Name" => "gallery.Name", "gallery_Active" => "gallery.Active", "materialfield_MaterialFieldID" => "materialfield.MaterialFieldID", "materialfield_FieldID" => "materialfield.FieldID", "materialfield_MaterialID" => "materialfield.MaterialID", "materialfield_Value" => "materialfield.Value", "materialfield_numeric_value" => "materialfield.numeric_value", "materialfield_locale" => "materialfield.locale", "materialfield_Active" => "materialfield.Active", "field_FieldID" => "field.FieldID", "field_ParentID" => "field.ParentID", "field_Name" => "field.Name", "field_Type" => "field.Type", "field_local" => "field.local", "field_filtered" => "field.filtered", "field_Value" => "field.Value", "field_Description" => "field.Description", "field_UserID" => "field.UserID", "field_Created" => "field.Created", "field_Modyfied" => "field.Modyfied", "field_Active" => "field.Active", "field_system" => "field.system", "structurematerial_StructureMaterialID" => "structurematerial.StructureMaterialID", "structurematerial_StructureID" => "structurematerial.StructureID", "structurematerial_MaterialID" => "structurematerial.MaterialID", "structurematerial_Modified" => "structurematerial.Modified", "structurematerial_Active" => "structurematerial.Active", "structure_StructureID" => "structure.StructureID", "structure_ParentID" => "structure.ParentID", "structure_Name" => "structure.Name", "structure_locale" => "structure.locale", "structure_Created" => "structure.Created", "structure_UserID" => "structure.UserID", "structure_Modyfied" => "structure.Modyfied", "structure_Url" => "structure.Url", "structure_MaterialID" => "structure.MaterialID", "structure_PriorityNumber" => "structure.PriorityNumber", "structure_type" => "structure.type", "structure_Active" => "structure.Active", "structure_system" => "structure.system", "material_MaterialID" => "material.MaterialID", "material_parent_id" => "material.parent_id", "material_Name" => "material.Name", "material_Teaser" => "material.Teaser", "material_Url" => "material.Url", "material_Created" => "material.Created", "material_Modyfied" => "material.Modyfied", "material_UserID" => "material.UserID", "material_Draft" => "material.Draft", "material_type" => "material.type", "material_Published" => "material.Published", "material_Active" => "material.Active", "material_system" => "material.system", "structure_relation_structure_relation_id" => "structure_relation.structure_relation_id", "structure_relation_parent_id" => "structure_relation.parent_id", "structure_relation_child_id" => "structure_relation.child_id", "manymaterials_PhotoID" => "manymaterials.PhotoID", "manymaterials_MaterialID" => "manymaterials.MaterialID", "manymaterials_priority" => "manymaterials.priority", "manymaterials_Path" => "manymaterials.Path", "manymaterials_Src" => "manymaterials.Src", "manymaterials_size" => "manymaterials.size", "manymaterials_Loaded" => "manymaterials.Loaded", "manymaterials_Description" => "manymaterials.Description", "manymaterials_Name" => "manymaterials.Name", "manymaterials_Active" => "manymaterials.Active", "_mf_MaterialFieldID" => "_mf.MaterialFieldID", "_mf_FieldID" => "_mf.FieldID", "_mf_MaterialID" => "_mf.MaterialID", "_mf_Value" => "_mf.Value", "_mf_numeric_value" => "_mf.numeric_value", "_mf_locale" => "_mf.locale", "_mf_Active" => "_mf.Active", "children_relations_structure_relation_id" => "children_relations.structure_relation_id", "children_relations_parent_id" => "children_relations.parent_id", "children_relations_child_id" => "children_relations.child_id", "children_StructureID" => "children.StructureID", "children_ParentID" => "children.ParentID", "children_Name" => "children.Name", "children_locale" => "children.locale", "children_Created" => "children.Created", "children_UserID" => "children.UserID", "children_Modyfied" => "children.Modyfied", "children_Url" => "children.Url", "children_MaterialID" => "children.MaterialID", "children_PriorityNumber" => "children.PriorityNumber", "children_type" => "children.type", "children_Active" => "children.Active", "children_system" => "children.system", "parents_relations_structure_relation_id" => "parents_relations.structure_relation_id", "parents_relations_parent_id" => "parents_relations.parent_id", "parents_relations_child_id" => "parents_relations.child_id", "parents_StructureID" => "parents.StructureID", "parents_ParentID" => "parents.ParentID", "parents_Name" => "parents.Name", "parents_locale" => "parents.locale", "parents_Created" => "parents.Created", "parents_UserID" => "parents.UserID", "parents_Modyfied" => "parents.Modyfied", "parents_Url" => "parents.Url", "parents_MaterialID" => "parents.MaterialID", "parents_PriorityNumber" => "parents.PriorityNumber", "parents_type" => "parents.type", "parents_Active" => "parents.Active", "parents_system" => "parents.system", )); related_materials::$_relation_alias = array( "user" => "user", "gallery" => "gallery", "materialfield" => "materialfield", "field" => "field", "structurematerial" => "structurematerial", "structure" => "structure", "material" => "material", "structure_relation" => "structure_relation", "manymaterials" => "gallery", "_mf" => "materialfield", "children_relations" => "structure_relation", "children" => "structure", "parents_relations" => "structure_relation", "parents" => "structure", ); related_materials::$_relation_type = array( "user" => "0", "gallery" => "1", "materialfield" => "1", "field" => "0", "structurematerial" => "1", "structure" => "0", "material" => "1", "structure_relation" => "1", "manymaterials" => "1", "_mf" => "1", "children_relations" => "1", "children" => "1", "parents_relations" => "1", "parents" => "1", ); related_materials::$_relations = array( "user" =>array( "UserID" => "user_UserID", "FName" => "user_FName", "SName" => "user_SName", "TName" => "user_TName", "Email" => "user_Email", "Password" => "user_Password", "md5_email" => "user_md5_email", "md5_password" => "user_md5_password", "Created" => "user_Created", "Modyfied" => "user_Modyfied", "GroupID" => "user_GroupID", "Active" => "user_Active", "Online" => "user_Online", "LastLogin" => "user_LastLogin", "system" => "user_system", ), "gallery" =>array( "PhotoID" => "gallery_PhotoID", "MaterialID" => "gallery_MaterialID", "priority" => "gallery_priority", "Path" => "gallery_Path", "Src" => "gallery_Src", "size" => "gallery_size", "Loaded" => "gallery_Loaded", "Description" => "gallery_Description", "Name" => "gallery_Name", "Active" => "gallery_Active", ), "materialfield" =>array( "MaterialFieldID" => "materialfield_MaterialFieldID", "FieldID" => "materialfield_FieldID", "MaterialID" => "materialfield_MaterialID", "Value" => "materialfield_Value", "numeric_value" => "materialfield_numeric_value", "locale" => "materialfield_locale", "Active" => "materialfield_Active", ), "field" =>array( "FieldID" => "field_FieldID", "ParentID" => "field_ParentID", "Name" => "field_Name", "Type" => "field_Type", "local" => "field_local", "filtered" => "field_filtered", "Value" => "field_Value", "Description" => "field_Description", "UserID" => "field_UserID", "Created" => "field_Created", "Modyfied" => "field_Modyfied", "Active" => "field_Active", "system" => "field_system", ), "structurematerial" =>array( "StructureMaterialID" => "structurematerial_StructureMaterialID", "StructureID" => "structurematerial_StructureID", "MaterialID" => "structurematerial_MaterialID", "Modified" => "structurematerial_Modified", "Active" => "structurematerial_Active", ), "structure" =>array( "StructureID" => "structure_StructureID", "ParentID" => "structure_ParentID", "Name" => "structure_Name", "locale" => "structure_locale", "Created" => "structure_Created", "UserID" => "structure_UserID", "Modyfied" => "structure_Modyfied", "Url" => "structure_Url", "MaterialID" => "structure_MaterialID", "PriorityNumber" => "structure_PriorityNumber", "type" => "structure_type", "Active" => "structure_Active", "system" => "structure_system", ), "material" =>array( "MaterialID" => "material_MaterialID", "parent_id" => "material_parent_id", "Name" => "material_Name", "Teaser" => "material_Teaser", "Url" => "material_Url", "Created" => "material_Created", "Modyfied" => "material_Modyfied", "UserID" => "material_UserID", "Draft" => "material_Draft", "type" => "material_type", "Published" => "material_Published", "Active" => "material_Active", "system" => "material_system", ), "structure_relation" =>array( "structure_relation_id" => "structure_relation_structure_relation_id", "parent_id" => "structure_relation_parent_id", "child_id" => "structure_relation_child_id", ), "manymaterials" =>array( "PhotoID" => "manymaterials_PhotoID", "MaterialID" => "manymaterials_MaterialID", "priority" => "manymaterials_priority", "Path" => "manymaterials_Path", "Src" => "manymaterials_Src", "size" => "manymaterials_size", "Loaded" => "manymaterials_Loaded", "Description" => "manymaterials_Description", "Name" => "manymaterials_Name", "Active" => "manymaterials_Active", ), "_mf" =>array( "MaterialFieldID" => "_mf_MaterialFieldID", "FieldID" => "_mf_FieldID", "MaterialID" => "_mf_MaterialID", "Value" => "_mf_Value", "numeric_value" => "_mf_numeric_value", "locale" => "_mf_locale", "Active" => "_mf_Active", ), "children_relations" =>array( "structure_relation_id" => "children_relations_structure_relation_id", "parent_id" => "children_relations_parent_id", "child_id" => "children_relations_child_id", ), "children" =>array( "StructureID" => "children_StructureID", "ParentID" => "children_ParentID", "Name" => "children_Name", "locale" => "children_locale", "Created" => "children_Created", "UserID" => "children_UserID", "Modyfied" => "children_Modyfied", "Url" => "children_Url", "MaterialID" => "children_MaterialID", "PriorityNumber" => "children_PriorityNumber", "type" => "children_type", "Active" => "children_Active", "system" => "children_system", ), "parents_relations" =>array( "structure_relation_id" => "parents_relations_structure_relation_id", "parent_id" => "parents_relations_parent_id", "child_id" => "parents_relations_child_id", ), "parents" =>array( "StructureID" => "parents_StructureID", "ParentID" => "parents_ParentID", "Name" => "parents_Name", "locale" => "parents_locale", "Created" => "parents_Created", "UserID" => "parents_UserID", "Modyfied" => "parents_Modyfied", "Url" => "parents_Url", "MaterialID" => "parents_MaterialID", "PriorityNumber" => "parents_PriorityNumber", "type" => "parents_type", "Active" => "parents_Active", "system" => "parents_system", ), ); field::$_sql_from = array_merge( field::$_sql_from, array( "user" => "LEFT JOIN `user` ON `structure`.`UserID` = `user`.`UserID`", "gallery" => "LEFT JOIN `gallery` ON `material`.`MaterialID` = `gallery`.`MaterialID`", "materialfield" => "LEFT JOIN `materialfield` ON `related_materials`.`first_material` = `materialfield`.MaterialID", "field" => "LEFT JOIN `field` ON `materialfield`.`FieldID` = `field`.`FieldID`", "structurematerial" => "LEFT JOIN `structurematerial` ON `structure`.`StructureID` = `structurematerial`.`StructureID`", "structure" => "LEFT JOIN `structure` ON `structurefield`.`StructureID` = `structure`.`StructureID`", "material" => "LEFT JOIN `material` ON `related_materials`.`first_material` = `material`.MaterialID", "structure_relation" => "LEFT JOIN `structure_relation` ON `structurematerial`.`StructureID` = `structure_relation`.parent_id", "manymaterials" => "LEFT JOIN `gallery` AS manymaterials ON `structurematerial`.`MaterialID` = `manymaterials`.`MaterialID`", "_mf" => "LEFT JOIN `materialfield` AS _mf ON `material`.`MaterialID` = `_mf`.MaterialID", "children_relations" => "LEFT JOIN `structure_relation` AS children_relations ON `structure`.`StructureID` = `children_relations`.parent_id", "children" => "LEFT JOIN `structure` AS children ON `children_relations`.`child_id` = `children`.StructureID", "parents_relations" => "LEFT JOIN `structure_relation` AS parents_relations ON `structure`.`StructureID` = `parents_relations`.child_id", "parents" => "LEFT JOIN `structure` AS parents ON `parents_relations`.`parent_id` = `parents`.StructureID", "structurefield" => "LEFT JOIN `structurefield` ON `field`.`FieldID` = `structurefield`.`FieldID`", )); field::$_sql_select = array_merge( field::$_sql_select, array( "user" => "user.UserID as user_UserID,user.FName as user_FName,user.SName as user_SName,user.TName as user_TName,user.Email as user_Email,user.Password as user_Password,user.md5_email as user_md5_email,user.md5_password as user_md5_password,user.Created as user_Created,user.Modyfied as user_Modyfied,user.GroupID as user_GroupID,user.Active as user_Active,user.Online as user_Online,user.LastLogin as user_LastLogin,user.system as user_system", "gallery" => "gallery.PhotoID as gallery_PhotoID,gallery.MaterialID as gallery_MaterialID,gallery.priority as gallery_priority,gallery.Path as gallery_Path,gallery.Src as gallery_Src,gallery.size as gallery_size,gallery.Loaded as gallery_Loaded,gallery.Description as gallery_Description,gallery.Name as gallery_Name,gallery.Active as gallery_Active", "materialfield" => "materialfield.MaterialFieldID as materialfield_MaterialFieldID,materialfield.FieldID as materialfield_FieldID,materialfield.MaterialID as materialfield_MaterialID,materialfield.Value as materialfield_Value,materialfield.numeric_value as materialfield_numeric_value,materialfield.locale as materialfield_locale,materialfield.Active as materialfield_Active", "field" => "field.FieldID as field_FieldID,field.ParentID as field_ParentID,field.Name as field_Name,field.Type as field_Type,field.local as field_local,field.filtered as field_filtered,field.Value as field_Value,field.Description as field_Description,field.UserID as field_UserID,field.Created as field_Created,field.Modyfied as field_Modyfied,field.Active as field_Active,field.system as field_system", "structurematerial" => "structurematerial.StructureMaterialID as structurematerial_StructureMaterialID,structurematerial.StructureID as structurematerial_StructureID,structurematerial.MaterialID as structurematerial_MaterialID,structurematerial.Modified as structurematerial_Modified,structurematerial.Active as structurematerial_Active", "structure" => "structure.StructureID as structure_StructureID,structure.ParentID as structure_ParentID,structure.Name as structure_Name,structure.locale as structure_locale,structure.Created as structure_Created,structure.UserID as structure_UserID,structure.Modyfied as structure_Modyfied,structure.Url as structure_Url,structure.MaterialID as structure_MaterialID,structure.PriorityNumber as structure_PriorityNumber,structure.type as structure_type,structure.Active as structure_Active,structure.system as structure_system", "material" => "material.MaterialID as material_MaterialID,material.parent_id as material_parent_id,material.Name as material_Name,material.Teaser as material_Teaser,material.Url as material_Url,material.Created as material_Created,material.Modyfied as material_Modyfied,material.UserID as material_UserID,material.Draft as material_Draft,material.type as material_type,material.Published as material_Published,material.Active as material_Active,material.system as material_system", "structure_relation" => "structure_relation.structure_relation_id as structure_relation_structure_relation_id,structure_relation.parent_id as structure_relation_parent_id,structure_relation.child_id as structure_relation_child_id", "manymaterials" => "manymaterials.PhotoID as manymaterials_PhotoID,manymaterials.MaterialID as manymaterials_MaterialID,manymaterials.priority as manymaterials_priority,manymaterials.Path as manymaterials_Path,manymaterials.Src as manymaterials_Src,manymaterials.size as manymaterials_size,manymaterials.Loaded as manymaterials_Loaded,manymaterials.Description as manymaterials_Description,manymaterials.Name as manymaterials_Name,manymaterials.Active as manymaterials_Active", "_mf" => "_mf.MaterialFieldID as _mf_MaterialFieldID,_mf.FieldID as _mf_FieldID,_mf.MaterialID as _mf_MaterialID,_mf.Value as _mf_Value,_mf.numeric_value as _mf_numeric_value,_mf.locale as _mf_locale,_mf.Active as _mf_Active", "children_relations" => "children_relations.structure_relation_id as children_relations_structure_relation_id,children_relations.parent_id as children_relations_parent_id,children_relations.child_id as children_relations_child_id", "children" => "children.StructureID as children_StructureID,children.ParentID as children_ParentID,children.Name as children_Name,children.locale as children_locale,children.Created as children_Created,children.UserID as children_UserID,children.Modyfied as children_Modyfied,children.Url as children_Url,children.MaterialID as children_MaterialID,children.PriorityNumber as children_PriorityNumber,children.type as children_type,children.Active as children_Active,children.system as children_system", "parents_relations" => "parents_relations.structure_relation_id as parents_relations_structure_relation_id,parents_relations.parent_id as parents_relations_parent_id,parents_relations.child_id as parents_relations_child_id", "parents" => "parents.StructureID as parents_StructureID,parents.ParentID as parents_ParentID,parents.Name as parents_Name,parents.locale as parents_locale,parents.Created as parents_Created,parents.UserID as parents_UserID,parents.Modyfied as parents_Modyfied,parents.Url as parents_Url,parents.MaterialID as parents_MaterialID,parents.PriorityNumber as parents_PriorityNumber,parents.type as parents_type,parents.Active as parents_Active,parents.system as parents_system", "structurefield" => "structurefield.StructureFieldID as structurefield_StructureFieldID,structurefield.StructureID as structurefield_StructureID,structurefield.FieldID as structurefield_FieldID,structurefield.Modified as structurefield_Modified,structurefield.Active as structurefield_Active", )); field::$_map = array_merge( field::$_map, array( "user_UserID" => "user.UserID", "user_FName" => "user.FName", "user_SName" => "user.SName", "user_TName" => "user.TName", "user_Email" => "user.Email", "user_Password" => "user.Password", "user_md5_email" => "user.md5_email", "user_md5_password" => "user.md5_password", "user_Created" => "user.Created", "user_Modyfied" => "user.Modyfied", "user_GroupID" => "user.GroupID", "user_Active" => "user.Active", "user_Online" => "user.Online", "user_LastLogin" => "user.LastLogin", "user_system" => "user.system", "gallery_PhotoID" => "gallery.PhotoID", "gallery_MaterialID" => "gallery.MaterialID", "gallery_priority" => "gallery.priority", "gallery_Path" => "gallery.Path", "gallery_Src" => "gallery.Src", "gallery_size" => "gallery.size", "gallery_Loaded" => "gallery.Loaded", "gallery_Description" => "gallery.Description", "gallery_Name" => "gallery.Name", "gallery_Active" => "gallery.Active", "materialfield_MaterialFieldID" => "materialfield.MaterialFieldID", "materialfield_FieldID" => "materialfield.FieldID", "materialfield_MaterialID" => "materialfield.MaterialID", "materialfield_Value" => "materialfield.Value", "materialfield_numeric_value" => "materialfield.numeric_value", "materialfield_locale" => "materialfield.locale", "materialfield_Active" => "materialfield.Active", "field_FieldID" => "field.FieldID", "field_ParentID" => "field.ParentID", "field_Name" => "field.Name", "field_Type" => "field.Type", "field_local" => "field.local", "field_filtered" => "field.filtered", "field_Value" => "field.Value", "field_Description" => "field.Description", "field_UserID" => "field.UserID", "field_Created" => "field.Created", "field_Modyfied" => "field.Modyfied", "field_Active" => "field.Active", "field_system" => "field.system", "structurematerial_StructureMaterialID" => "structurematerial.StructureMaterialID", "structurematerial_StructureID" => "structurematerial.StructureID", "structurematerial_MaterialID" => "structurematerial.MaterialID", "structurematerial_Modified" => "structurematerial.Modified", "structurematerial_Active" => "structurematerial.Active", "structure_StructureID" => "structure.StructureID", "structure_ParentID" => "structure.ParentID", "structure_Name" => "structure.Name", "structure_locale" => "structure.locale", "structure_Created" => "structure.Created", "structure_UserID" => "structure.UserID", "structure_Modyfied" => "structure.Modyfied", "structure_Url" => "structure.Url", "structure_MaterialID" => "structure.MaterialID", "structure_PriorityNumber" => "structure.PriorityNumber", "structure_type" => "structure.type", "structure_Active" => "structure.Active", "structure_system" => "structure.system", "material_MaterialID" => "material.MaterialID", "material_parent_id" => "material.parent_id", "material_Name" => "material.Name", "material_Teaser" => "material.Teaser", "material_Url" => "material.Url", "material_Created" => "material.Created", "material_Modyfied" => "material.Modyfied", "material_UserID" => "material.UserID", "material_Draft" => "material.Draft", "material_type" => "material.type", "material_Published" => "material.Published", "material_Active" => "material.Active", "material_system" => "material.system", "structure_relation_structure_relation_id" => "structure_relation.structure_relation_id", "structure_relation_parent_id" => "structure_relation.parent_id", "structure_relation_child_id" => "structure_relation.child_id", "manymaterials_PhotoID" => "manymaterials.PhotoID", "manymaterials_MaterialID" => "manymaterials.MaterialID", "manymaterials_priority" => "manymaterials.priority", "manymaterials_Path" => "manymaterials.Path", "manymaterials_Src" => "manymaterials.Src", "manymaterials_size" => "manymaterials.size", "manymaterials_Loaded" => "manymaterials.Loaded", "manymaterials_Description" => "manymaterials.Description", "manymaterials_Name" => "manymaterials.Name", "manymaterials_Active" => "manymaterials.Active", "_mf_MaterialFieldID" => "_mf.MaterialFieldID", "_mf_FieldID" => "_mf.FieldID", "_mf_MaterialID" => "_mf.MaterialID", "_mf_Value" => "_mf.Value", "_mf_numeric_value" => "_mf.numeric_value", "_mf_locale" => "_mf.locale", "_mf_Active" => "_mf.Active", "children_relations_structure_relation_id" => "children_relations.structure_relation_id", "children_relations_parent_id" => "children_relations.parent_id", "children_relations_child_id" => "children_relations.child_id", "children_StructureID" => "children.StructureID", "children_ParentID" => "children.ParentID", "children_Name" => "children.Name", "children_locale" => "children.locale", "children_Created" => "children.Created", "children_UserID" => "children.UserID", "children_Modyfied" => "children.Modyfied", "children_Url" => "children.Url", "children_MaterialID" => "children.MaterialID", "children_PriorityNumber" => "children.PriorityNumber", "children_type" => "children.type", "children_Active" => "children.Active", "children_system" => "children.system", "parents_relations_structure_relation_id" => "parents_relations.structure_relation_id", "parents_relations_parent_id" => "parents_relations.parent_id", "parents_relations_child_id" => "parents_relations.child_id", "parents_StructureID" => "parents.StructureID", "parents_ParentID" => "parents.ParentID", "parents_Name" => "parents.Name", "parents_locale" => "parents.locale", "parents_Created" => "parents.Created", "parents_UserID" => "parents.UserID", "parents_Modyfied" => "parents.Modyfied", "parents_Url" => "parents.Url", "parents_MaterialID" => "parents.MaterialID", "parents_PriorityNumber" => "parents.PriorityNumber", "parents_type" => "parents.type", "parents_Active" => "parents.Active", "parents_system" => "parents.system", "structurefield_StructureFieldID" => "structurefield.StructureFieldID", "structurefield_StructureID" => "structurefield.StructureID", "structurefield_FieldID" => "structurefield.FieldID", "structurefield_Modified" => "structurefield.Modified", "structurefield_Active" => "structurefield.Active", )); field::$_relation_alias = array( "user" => "user", "gallery" => "gallery", "materialfield" => "materialfield", "field" => "field", "structurematerial" => "structurematerial", "structure" => "structure", "material" => "material", "structure_relation" => "structure_relation", "manymaterials" => "gallery", "_mf" => "materialfield", "children_relations" => "structure_relation", "children" => "structure", "parents_relations" => "structure_relation", "parents" => "structure", "structurefield" => "structurefield", ); field::$_relation_type = array( "user" => "0", "gallery" => "1", "materialfield" => "1", "field" => "0", "structurematerial" => "1", "structure" => "0", "material" => "1", "structure_relation" => "1", "manymaterials" => "1", "_mf" => "1", "children_relations" => "1", "children" => "1", "parents_relations" => "1", "parents" => "1", "structurefield" => "0", ); field::$_relations = array( "user" =>array( "UserID" => "user_UserID", "FName" => "user_FName", "SName" => "user_SName", "TName" => "user_TName", "Email" => "user_Email", "Password" => "user_Password", "md5_email" => "user_md5_email", "md5_password" => "user_md5_password", "Created" => "user_Created", "Modyfied" => "user_Modyfied", "GroupID" => "user_GroupID", "Active" => "user_Active", "Online" => "user_Online", "LastLogin" => "user_LastLogin", "system" => "user_system", ), "gallery" =>array( "PhotoID" => "gallery_PhotoID", "MaterialID" => "gallery_MaterialID", "priority" => "gallery_priority", "Path" => "gallery_Path", "Src" => "gallery_Src", "size" => "gallery_size", "Loaded" => "gallery_Loaded", "Description" => "gallery_Description", "Name" => "gallery_Name", "Active" => "gallery_Active", ), "materialfield" =>array( "MaterialFieldID" => "materialfield_MaterialFieldID", "FieldID" => "materialfield_FieldID", "MaterialID" => "materialfield_MaterialID", "Value" => "materialfield_Value", "numeric_value" => "materialfield_numeric_value", "locale" => "materialfield_locale", "Active" => "materialfield_Active", ), "field" =>array( "FieldID" => "field_FieldID", "ParentID" => "field_ParentID", "Name" => "field_Name", "Type" => "field_Type", "local" => "field_local", "filtered" => "field_filtered", "Value" => "field_Value", "Description" => "field_Description", "UserID" => "field_UserID", "Created" => "field_Created", "Modyfied" => "field_Modyfied", "Active" => "field_Active", "system" => "field_system", ), "structurematerial" =>array( "StructureMaterialID" => "structurematerial_StructureMaterialID", "StructureID" => "structurematerial_StructureID", "MaterialID" => "structurematerial_MaterialID", "Modified" => "structurematerial_Modified", "Active" => "structurematerial_Active", ), "structure" =>array( "StructureID" => "structure_StructureID", "ParentID" => "structure_ParentID", "Name" => "structure_Name", "locale" => "structure_locale", "Created" => "structure_Created", "UserID" => "structure_UserID", "Modyfied" => "structure_Modyfied", "Url" => "structure_Url", "MaterialID" => "structure_MaterialID", "PriorityNumber" => "structure_PriorityNumber", "type" => "structure_type", "Active" => "structure_Active", "system" => "structure_system", ), "material" =>array( "MaterialID" => "material_MaterialID", "parent_id" => "material_parent_id", "Name" => "material_Name", "Teaser" => "material_Teaser", "Url" => "material_Url", "Created" => "material_Created", "Modyfied" => "material_Modyfied", "UserID" => "material_UserID", "Draft" => "material_Draft", "type" => "material_type", "Published" => "material_Published", "Active" => "material_Active", "system" => "material_system", ), "structure_relation" =>array( "structure_relation_id" => "structure_relation_structure_relation_id", "parent_id" => "structure_relation_parent_id", "child_id" => "structure_relation_child_id", ), "manymaterials" =>array( "PhotoID" => "manymaterials_PhotoID", "MaterialID" => "manymaterials_MaterialID", "priority" => "manymaterials_priority", "Path" => "manymaterials_Path", "Src" => "manymaterials_Src", "size" => "manymaterials_size", "Loaded" => "manymaterials_Loaded", "Description" => "manymaterials_Description", "Name" => "manymaterials_Name", "Active" => "manymaterials_Active", ), "_mf" =>array( "MaterialFieldID" => "_mf_MaterialFieldID", "FieldID" => "_mf_FieldID", "MaterialID" => "_mf_MaterialID", "Value" => "_mf_Value", "numeric_value" => "_mf_numeric_value", "locale" => "_mf_locale", "Active" => "_mf_Active", ), "children_relations" =>array( "structure_relation_id" => "children_relations_structure_relation_id", "parent_id" => "children_relations_parent_id", "child_id" => "children_relations_child_id", ), "children" =>array( "StructureID" => "children_StructureID", "ParentID" => "children_ParentID", "Name" => "children_Name", "locale" => "children_locale", "Created" => "children_Created", "UserID" => "children_UserID", "Modyfied" => "children_Modyfied", "Url" => "children_Url", "MaterialID" => "children_MaterialID", "PriorityNumber" => "children_PriorityNumber", "type" => "children_type", "Active" => "children_Active", "system" => "children_system", ), "parents_relations" =>array( "structure_relation_id" => "parents_relations_structure_relation_id", "parent_id" => "parents_relations_parent_id", "child_id" => "parents_relations_child_id", ), "parents" =>array( "StructureID" => "parents_StructureID", "ParentID" => "parents_ParentID", "Name" => "parents_Name", "locale" => "parents_locale", "Created" => "parents_Created", "UserID" => "parents_UserID", "Modyfied" => "parents_Modyfied", "Url" => "parents_Url", "MaterialID" => "parents_MaterialID", "PriorityNumber" => "parents_PriorityNumber", "type" => "parents_type", "Active" => "parents_Active", "system" => "parents_system", ), "structurefield" =>array( "StructureFieldID" => "structurefield_StructureFieldID", "StructureID" => "structurefield_StructureID", "FieldID" => "structurefield_FieldID", "Modified" => "structurefield_Modified", "Active" => "structurefield_Active", ), ); structurefield::$_sql_from = array_merge( structurefield::$_sql_from, array( "user" => "LEFT JOIN `user` ON `structure`.`UserID` = `user`.`UserID`", "gallery" => "LEFT JOIN `gallery` ON `material`.`MaterialID` = `gallery`.`MaterialID`", "materialfield" => "LEFT JOIN `materialfield` ON `structurefield`.`FieldID` = `materialfield`.`FieldID`", "field" => "LEFT JOIN `field` ON `structurefield`.`FieldID` = `field`.`FieldID`", "structurematerial" => "LEFT JOIN `structurematerial` ON `structure`.`StructureID` = `structurematerial`.`StructureID`", "structure" => "LEFT JOIN `structure` ON `structurefield`.`StructureID` = `structure`.`StructureID`", "material" => "LEFT JOIN `material` ON `materialfield`.`MaterialID` = `material`.`MaterialID`", "structure_relation" => "LEFT JOIN `structure_relation` ON `structurematerial`.`StructureID` = `structure_relation`.parent_id", "manymaterials" => "LEFT JOIN `gallery` AS manymaterials ON `structurematerial`.`MaterialID` = `manymaterials`.`MaterialID`", "_mf" => "LEFT JOIN `materialfield` AS _mf ON `material`.`MaterialID` = `_mf`.MaterialID", "children_relations" => "LEFT JOIN `structure_relation` AS children_relations ON `structure`.`StructureID` = `children_relations`.parent_id", "children" => "LEFT JOIN `structure` AS children ON `children_relations`.`child_id` = `children`.StructureID", "parents_relations" => "LEFT JOIN `structure_relation` AS parents_relations ON `structure`.`StructureID` = `parents_relations`.child_id", "parents" => "LEFT JOIN `structure` AS parents ON `parents_relations`.`parent_id` = `parents`.StructureID", "structurefield" => "LEFT JOIN `structurefield` ON `field`.`FieldID` = `structurefield`.`FieldID`", )); structurefield::$_sql_select = array_merge( structurefield::$_sql_select, array( "user" => "user.UserID as user_UserID,user.FName as user_FName,user.SName as user_SName,user.TName as user_TName,user.Email as user_Email,user.Password as user_Password,user.md5_email as user_md5_email,user.md5_password as user_md5_password,user.Created as user_Created,user.Modyfied as user_Modyfied,user.GroupID as user_GroupID,user.Active as user_Active,user.Online as user_Online,user.LastLogin as user_LastLogin,user.system as user_system", "gallery" => "gallery.PhotoID as gallery_PhotoID,gallery.MaterialID as gallery_MaterialID,gallery.priority as gallery_priority,gallery.Path as gallery_Path,gallery.Src as gallery_Src,gallery.size as gallery_size,gallery.Loaded as gallery_Loaded,gallery.Description as gallery_Description,gallery.Name as gallery_Name,gallery.Active as gallery_Active", "materialfield" => "materialfield.MaterialFieldID as materialfield_MaterialFieldID,materialfield.FieldID as materialfield_FieldID,materialfield.MaterialID as materialfield_MaterialID,materialfield.Value as materialfield_Value,materialfield.numeric_value as materialfield_numeric_value,materialfield.locale as materialfield_locale,materialfield.Active as materialfield_Active", "field" => "field.FieldID as field_FieldID,field.ParentID as field_ParentID,field.Name as field_Name,field.Type as field_Type,field.local as field_local,field.filtered as field_filtered,field.Value as field_Value,field.Description as field_Description,field.UserID as field_UserID,field.Created as field_Created,field.Modyfied as field_Modyfied,field.Active as field_Active,field.system as field_system", "structurematerial" => "structurematerial.StructureMaterialID as structurematerial_StructureMaterialID,structurematerial.StructureID as structurematerial_StructureID,structurematerial.MaterialID as structurematerial_MaterialID,structurematerial.Modified as structurematerial_Modified,structurematerial.Active as structurematerial_Active", "structure" => "structure.StructureID as structure_StructureID,structure.ParentID as structure_ParentID,structure.Name as structure_Name,structure.locale as structure_locale,structure.Created as structure_Created,structure.UserID as structure_UserID,structure.Modyfied as structure_Modyfied,structure.Url as structure_Url,structure.MaterialID as structure_MaterialID,structure.PriorityNumber as structure_PriorityNumber,structure.type as structure_type,structure.Active as structure_Active,structure.system as structure_system", "material" => "material.MaterialID as material_MaterialID,material.parent_id as material_parent_id,material.Name as material_Name,material.Teaser as material_Teaser,material.Url as material_Url,material.Created as material_Created,material.Modyfied as material_Modyfied,material.UserID as material_UserID,material.Draft as material_Draft,material.type as material_type,material.Published as material_Published,material.Active as material_Active,material.system as material_system", "structure_relation" => "structure_relation.structure_relation_id as structure_relation_structure_relation_id,structure_relation.parent_id as structure_relation_parent_id,structure_relation.child_id as structure_relation_child_id", "manymaterials" => "manymaterials.PhotoID as manymaterials_PhotoID,manymaterials.MaterialID as manymaterials_MaterialID,manymaterials.priority as manymaterials_priority,manymaterials.Path as manymaterials_Path,manymaterials.Src as manymaterials_Src,manymaterials.size as manymaterials_size,manymaterials.Loaded as manymaterials_Loaded,manymaterials.Description as manymaterials_Description,manymaterials.Name as manymaterials_Name,manymaterials.Active as manymaterials_Active", "_mf" => "_mf.MaterialFieldID as _mf_MaterialFieldID,_mf.FieldID as _mf_FieldID,_mf.MaterialID as _mf_MaterialID,_mf.Value as _mf_Value,_mf.numeric_value as _mf_numeric_value,_mf.locale as _mf_locale,_mf.Active as _mf_Active", "children_relations" => "children_relations.structure_relation_id as children_relations_structure_relation_id,children_relations.parent_id as children_relations_parent_id,children_relations.child_id as children_relations_child_id", "children" => "children.StructureID as children_StructureID,children.ParentID as children_ParentID,children.Name as children_Name,children.locale as children_locale,children.Created as children_Created,children.UserID as children_UserID,children.Modyfied as children_Modyfied,children.Url as children_Url,children.MaterialID as children_MaterialID,children.PriorityNumber as children_PriorityNumber,children.type as children_type,children.Active as children_Active,children.system as children_system", "parents_relations" => "parents_relations.structure_relation_id as parents_relations_structure_relation_id,parents_relations.parent_id as parents_relations_parent_id,parents_relations.child_id as parents_relations_child_id", "parents" => "parents.StructureID as parents_StructureID,parents.ParentID as parents_ParentID,parents.Name as parents_Name,parents.locale as parents_locale,parents.Created as parents_Created,parents.UserID as parents_UserID,parents.Modyfied as parents_Modyfied,parents.Url as parents_Url,parents.MaterialID as parents_MaterialID,parents.PriorityNumber as parents_PriorityNumber,parents.type as parents_type,parents.Active as parents_Active,parents.system as parents_system", "structurefield" => "structurefield.StructureFieldID as structurefield_StructureFieldID,structurefield.StructureID as structurefield_StructureID,structurefield.FieldID as structurefield_FieldID,structurefield.Modified as structurefield_Modified,structurefield.Active as structurefield_Active", )); structurefield::$_map = array_merge( structurefield::$_map, array( "user_UserID" => "user.UserID", "user_FName" => "user.FName", "user_SName" => "user.SName", "user_TName" => "user.TName", "user_Email" => "user.Email", "user_Password" => "user.Password", "user_md5_email" => "user.md5_email", "user_md5_password" => "user.md5_password", "user_Created" => "user.Created", "user_Modyfied" => "user.Modyfied", "user_GroupID" => "user.GroupID", "user_Active" => "user.Active", "user_Online" => "user.Online", "user_LastLogin" => "user.LastLogin", "user_system" => "user.system", "gallery_PhotoID" => "gallery.PhotoID", "gallery_MaterialID" => "gallery.MaterialID", "gallery_priority" => "gallery.priority", "gallery_Path" => "gallery.Path", "gallery_Src" => "gallery.Src", "gallery_size" => "gallery.size", "gallery_Loaded" => "gallery.Loaded", "gallery_Description" => "gallery.Description", "gallery_Name" => "gallery.Name", "gallery_Active" => "gallery.Active", "materialfield_MaterialFieldID" => "materialfield.MaterialFieldID", "materialfield_FieldID" => "materialfield.FieldID", "materialfield_MaterialID" => "materialfield.MaterialID", "materialfield_Value" => "materialfield.Value", "materialfield_numeric_value" => "materialfield.numeric_value", "materialfield_locale" => "materialfield.locale", "materialfield_Active" => "materialfield.Active", "field_FieldID" => "field.FieldID", "field_ParentID" => "field.ParentID", "field_Name" => "field.Name", "field_Type" => "field.Type", "field_local" => "field.local", "field_filtered" => "field.filtered", "field_Value" => "field.Value", "field_Description" => "field.Description", "field_UserID" => "field.UserID", "field_Created" => "field.Created", "field_Modyfied" => "field.Modyfied", "field_Active" => "field.Active", "field_system" => "field.system", "structurematerial_StructureMaterialID" => "structurematerial.StructureMaterialID", "structurematerial_StructureID" => "structurematerial.StructureID", "structurematerial_MaterialID" => "structurematerial.MaterialID", "structurematerial_Modified" => "structurematerial.Modified", "structurematerial_Active" => "structurematerial.Active", "structure_StructureID" => "structure.StructureID", "structure_ParentID" => "structure.ParentID", "structure_Name" => "structure.Name", "structure_locale" => "structure.locale", "structure_Created" => "structure.Created", "structure_UserID" => "structure.UserID", "structure_Modyfied" => "structure.Modyfied", "structure_Url" => "structure.Url", "structure_MaterialID" => "structure.MaterialID", "structure_PriorityNumber" => "structure.PriorityNumber", "structure_type" => "structure.type", "structure_Active" => "structure.Active", "structure_system" => "structure.system", "material_MaterialID" => "material.MaterialID", "material_parent_id" => "material.parent_id", "material_Name" => "material.Name", "material_Teaser" => "material.Teaser", "material_Url" => "material.Url", "material_Created" => "material.Created", "material_Modyfied" => "material.Modyfied", "material_UserID" => "material.UserID", "material_Draft" => "material.Draft", "material_type" => "material.type", "material_Published" => "material.Published", "material_Active" => "material.Active", "material_system" => "material.system", "structure_relation_structure_relation_id" => "structure_relation.structure_relation_id", "structure_relation_parent_id" => "structure_relation.parent_id", "structure_relation_child_id" => "structure_relation.child_id", "manymaterials_PhotoID" => "manymaterials.PhotoID", "manymaterials_MaterialID" => "manymaterials.MaterialID", "manymaterials_priority" => "manymaterials.priority", "manymaterials_Path" => "manymaterials.Path", "manymaterials_Src" => "manymaterials.Src", "manymaterials_size" => "manymaterials.size", "manymaterials_Loaded" => "manymaterials.Loaded", "manymaterials_Description" => "manymaterials.Description", "manymaterials_Name" => "manymaterials.Name", "manymaterials_Active" => "manymaterials.Active", "_mf_MaterialFieldID" => "_mf.MaterialFieldID", "_mf_FieldID" => "_mf.FieldID", "_mf_MaterialID" => "_mf.MaterialID", "_mf_Value" => "_mf.Value", "_mf_numeric_value" => "_mf.numeric_value", "_mf_locale" => "_mf.locale", "_mf_Active" => "_mf.Active", "children_relations_structure_relation_id" => "children_relations.structure_relation_id", "children_relations_parent_id" => "children_relations.parent_id", "children_relations_child_id" => "children_relations.child_id", "children_StructureID" => "children.StructureID", "children_ParentID" => "children.ParentID", "children_Name" => "children.Name", "children_locale" => "children.locale", "children_Created" => "children.Created", "children_UserID" => "children.UserID", "children_Modyfied" => "children.Modyfied", "children_Url" => "children.Url", "children_MaterialID" => "children.MaterialID", "children_PriorityNumber" => "children.PriorityNumber", "children_type" => "children.type", "children_Active" => "children.Active", "children_system" => "children.system", "parents_relations_structure_relation_id" => "parents_relations.structure_relation_id", "parents_relations_parent_id" => "parents_relations.parent_id", "parents_relations_child_id" => "parents_relations.child_id", "parents_StructureID" => "parents.StructureID", "parents_ParentID" => "parents.ParentID", "parents_Name" => "parents.Name", "parents_locale" => "parents.locale", "parents_Created" => "parents.Created", "parents_UserID" => "parents.UserID", "parents_Modyfied" => "parents.Modyfied", "parents_Url" => "parents.Url", "parents_MaterialID" => "parents.MaterialID", "parents_PriorityNumber" => "parents.PriorityNumber", "parents_type" => "parents.type", "parents_Active" => "parents.Active", "parents_system" => "parents.system", "structurefield_StructureFieldID" => "structurefield.StructureFieldID", "structurefield_StructureID" => "structurefield.StructureID", "structurefield_FieldID" => "structurefield.FieldID", "structurefield_Modified" => "structurefield.Modified", "structurefield_Active" => "structurefield.Active", )); structurefield::$_relation_alias = array( "user" => "user", "gallery" => "gallery", "materialfield" => "materialfield", "field" => "field", "structurematerial" => "structurematerial", "structure" => "structure", "material" => "material", "structure_relation" => "structure_relation", "manymaterials" => "gallery", "_mf" => "materialfield", "children_relations" => "structure_relation", "children" => "structure", "parents_relations" => "structure_relation", "parents" => "structure", "structurefield" => "structurefield", ); structurefield::$_relation_type = array( "user" => "0", "gallery" => "1", "materialfield" => "0", "field" => "0", "structurematerial" => "1", "structure" => "0", "material" => "0", "structure_relation" => "1", "manymaterials" => "1", "_mf" => "1", "children_relations" => "1", "children" => "1", "parents_relations" => "1", "parents" => "1", "structurefield" => "0", ); structurefield::$_relations = array( "user" =>array( "UserID" => "user_UserID", "FName" => "user_FName", "SName" => "user_SName", "TName" => "user_TName", "Email" => "user_Email", "Password" => "user_Password", "md5_email" => "user_md5_email", "md5_password" => "user_md5_password", "Created" => "user_Created", "Modyfied" => "user_Modyfied", "GroupID" => "user_GroupID", "Active" => "user_Active", "Online" => "user_Online", "LastLogin" => "user_LastLogin", "system" => "user_system", ), "gallery" =>array( "PhotoID" => "gallery_PhotoID", "MaterialID" => "gallery_MaterialID", "priority" => "gallery_priority", "Path" => "gallery_Path", "Src" => "gallery_Src", "size" => "gallery_size", "Loaded" => "gallery_Loaded", "Description" => "gallery_Description", "Name" => "gallery_Name", "Active" => "gallery_Active", ), "materialfield" =>array( "MaterialFieldID" => "materialfield_MaterialFieldID", "FieldID" => "materialfield_FieldID", "MaterialID" => "materialfield_MaterialID", "Value" => "materialfield_Value", "numeric_value" => "materialfield_numeric_value", "locale" => "materialfield_locale", "Active" => "materialfield_Active", ), "field" =>array( "FieldID" => "field_FieldID", "ParentID" => "field_ParentID", "Name" => "field_Name", "Type" => "field_Type", "local" => "field_local", "filtered" => "field_filtered", "Value" => "field_Value", "Description" => "field_Description", "UserID" => "field_UserID", "Created" => "field_Created", "Modyfied" => "field_Modyfied", "Active" => "field_Active", "system" => "field_system", ), "structurematerial" =>array( "StructureMaterialID" => "structurematerial_StructureMaterialID", "StructureID" => "structurematerial_StructureID", "MaterialID" => "structurematerial_MaterialID", "Modified" => "structurematerial_Modified", "Active" => "structurematerial_Active", ), "structure" =>array( "StructureID" => "structure_StructureID", "ParentID" => "structure_ParentID", "Name" => "structure_Name", "locale" => "structure_locale", "Created" => "structure_Created", "UserID" => "structure_UserID", "Modyfied" => "structure_Modyfied", "Url" => "structure_Url", "MaterialID" => "structure_MaterialID", "PriorityNumber" => "structure_PriorityNumber", "type" => "structure_type", "Active" => "structure_Active", "system" => "structure_system", ), "material" =>array( "MaterialID" => "material_MaterialID", "parent_id" => "material_parent_id", "Name" => "material_Name", "Teaser" => "material_Teaser", "Url" => "material_Url", "Created" => "material_Created", "Modyfied" => "material_Modyfied", "UserID" => "material_UserID", "Draft" => "material_Draft", "type" => "material_type", "Published" => "material_Published", "Active" => "material_Active", "system" => "material_system", ), "structure_relation" =>array( "structure_relation_id" => "structure_relation_structure_relation_id", "parent_id" => "structure_relation_parent_id", "child_id" => "structure_relation_child_id", ), "manymaterials" =>array( "PhotoID" => "manymaterials_PhotoID", "MaterialID" => "manymaterials_MaterialID", "priority" => "manymaterials_priority", "Path" => "manymaterials_Path", "Src" => "manymaterials_Src", "size" => "manymaterials_size", "Loaded" => "manymaterials_Loaded", "Description" => "manymaterials_Description", "Name" => "manymaterials_Name", "Active" => "manymaterials_Active", ), "_mf" =>array( "MaterialFieldID" => "_mf_MaterialFieldID", "FieldID" => "_mf_FieldID", "MaterialID" => "_mf_MaterialID", "Value" => "_mf_Value", "numeric_value" => "_mf_numeric_value", "locale" => "_mf_locale", "Active" => "_mf_Active", ), "children_relations" =>array( "structure_relation_id" => "children_relations_structure_relation_id", "parent_id" => "children_relations_parent_id", "child_id" => "children_relations_child_id", ), "children" =>array( "StructureID" => "children_StructureID", "ParentID" => "children_ParentID", "Name" => "children_Name", "locale" => "children_locale", "Created" => "children_Created", "UserID" => "children_UserID", "Modyfied" => "children_Modyfied", "Url" => "children_Url", "MaterialID" => "children_MaterialID", "PriorityNumber" => "children_PriorityNumber", "type" => "children_type", "Active" => "children_Active", "system" => "children_system", ), "parents_relations" =>array( "structure_relation_id" => "parents_relations_structure_relation_id", "parent_id" => "parents_relations_parent_id", "child_id" => "parents_relations_child_id", ), "parents" =>array( "StructureID" => "parents_StructureID", "ParentID" => "parents_ParentID", "Name" => "parents_Name", "locale" => "parents_locale", "Created" => "parents_Created", "UserID" => "parents_UserID", "Modyfied" => "parents_Modyfied", "Url" => "parents_Url", "MaterialID" => "parents_MaterialID", "PriorityNumber" => "parents_PriorityNumber", "type" => "parents_type", "Active" => "parents_Active", "system" => "parents_system", ), "structurefield" =>array( "StructureFieldID" => "structurefield_StructureFieldID", "StructureID" => "structurefield_StructureID", "FieldID" => "structurefield_FieldID", "Modified" => "structurefield_Modified", "Active" => "structurefield_Active", ), ); class CacheTable implements iCache { public static function & get( $key ) { $ret_val = null; $sql_result = db()->simple_query('SELECT `value` FROM `'.self::TABLE_NAME.'` WHERE `key`="'.md5($key).'"'); if( ! is_bool( $sql_result ) ) { $row = mysqli_fetch_row( $sql_result ); if( is_array($row) ) $ret_val = unserialize(base64_decode($row[ 0 ])); } return $ret_val; } public static function ifget( $key, & $ret_val ) { $ret_val = self::get( $key ); if( $ret_val === null ) return false; return true; } public static function set( $key, $value ) { $value = base64_encode(serialize( $value )); if( strlen($value) < 65400 ) mysqli_query( 'INSERT INTO `'.self::TABLE_NAME.'` ( `key`, `value` ) VALUES '. '("'.md5($key).'","'.$value.'") ON DUPLICATE KEY UPDATE `value`="'.$value.'"'); else e('Cannot cache(##) string too long()', E_SAMSON_ACTIVERECORD_ERROR, array( $key, strlen($value) )); } } class QueryParams { protected $classname; protected $limit; protected $group = array(); protected $conditions = array() ; protected $condition; protected $relations = array(); protected $fields = array(); public function flush() { $this->limit = null; $this->group = array(); $this->conditions = array(); $this->relations = array(); $this->fields = array(); $this->condition = new Condition(); $this->conditions[] = & $this->condition; return $this; } public function limit( $count, $offset = 0 ){ $this->limit = array( $offset, $count ); } public function group( $field, $direction = 'ASC' ){ $this->group[] = array( $field, $direction ); } public function condition( $argument, $value = '', $relation = dbRelation::EQUAL ){ $this->condition->add( $argument, $value, $relation ); } public function relation(){} public function __construct( $classname ) { $this->classname = $classname; $this->flush(); } } class RelationData { public $base; public $relation; public $table; public $realTableName; public $virtualTableName; public $aliasTableName; public $className; public $ignore = false; public function __construct( $base_class, $table_name_simple, $relation_class = null, $ignore = false ) { $table_name = \samson\core\AutoLoader::className( $table_name_simple, 'samson\activerecord'); if (!isset($relation_class)) { if (!class_exists($table_name, false)) { eval('$_relation_alias = '.$base_class.'::$_relation_alias;'); if( isset($_relation_alias[ $table_name_simple ])) { $relation_class = \samson\core\AutoLoader::className($_relation_alias[ $table_name_simple ], __NAMESPACE__); } else if (isset($_relation_alias[ $table_name ])) { $relation_class = \samson\core\AutoLoader::className($_relation_alias[ $table_name ], __NAMESPACE__); } else { $relation_class = $table_name; } } else $relation_class = $table_name; $parent_class = get_parent_class( $relation_class ); if( $parent_class != \samson\core\AutoLoader::className( 'dbRecord', 'samson\activerecord')) $table_name = \samson\core\AutoLoader::getOnlyClass($parent_class); } $this->base = $base_class; $this->relation = $relation_class; $this->table = \samson\core\AutoLoader::getOnlyClass( $table_name ); $this->ignore = $ignore; $this->table = str_replace('samson_activerecord_', '', $this->table); } } class TableMetadata { public $table_name; public $primary_field; public $columns; public $unique_columns; public $index_columns; public $column_types; public $select; public $from; public $fields; } class dbFiller { public static function fill( $class_name, array & $standart_rows ) { $class_data = db()->__get_table_data( $class_name ); $db_rows = dbQuery( $class_name )->all(); $db_needs_update = false; foreach ( $standart_rows as $standart_row ) { $key = implode( '', $standart_row ); $found = false; foreach ( $db_rows as $db_row ) { $u_key = ''; foreach ( $class_data['_attributes'] as $a ) if( $a != $class_data['_primary'] ) $u_key .= $db_row[ $a ]; if( $key === $u_key ){$found = true; break; } } if( ! $found ) { $r = new $class_name(); $idx = 0; $db_needs_update = true; foreach ( $class_data['_attributes'] as $a ) if( $a != $class_data['_primary'] ) $r->$a = $standart_row[ $idx++ ]; $r->save(); } } } } class dbSimplify { public static function query( $query_result, & $r_object = NULL, $return_array = FALSE ) { if( is_array( $query_result ) && sizeof( $query_result ) > 0 ) { if( $return_array ) $r_object = $query_result; else $r_object = $query_result[0]; return TRUE; } $r_object = NULL; return FALSE; } public static function implode( array $collection, $field_name ) { $result = array(); if( sizeof( $collection ) > 0 ) { foreach ( $collection as & $record ) { $result[] = $record[ $field_name ]; } } return $result; } public static function parse( $entity_name, $argument, & $r_object = NULL, $field_name = 'id' ) { if( is_string( $argument ) || is_numeric( $argument ) ) { $entity_name = ns_classname( $entity_name,'samson\activerecord'); if( class_exists( $entity_name ) ) { $vars = db()->__get_table_data( $entity_name ); $field_name = ( $field_name == 'id' ) ? $vars['_primary'] : $field_name; $query = dbQuery( $entity_name )->cond( $field_name, $argument ); if ( isset( $vars['_attributes'][ 'Active' ] ) ) $query->cond( 'Active', 1 ); $r_object = db()->find( $entity_name, $query ); if( ($r_object !== FALSE) && ( sizeof( $r_object ) > 0 ) ) { $r_object = $r_object[ 0 ]; return TRUE; } } else return FALSE; } else if( is_object( $argument ) ) { $r_object = $argument; return TRUE; } $r_object = NULL; return FALSE; } public static function save( $class_name, & $db_object = NULL, array $_data = NULL ) { $class_name = ns_classname($class_name,'samson\activerecord'); extract(db()->__get_table_data( $class_name )); if( is_object( $db_object ) && strtolower(get_class( $db_object )) == strtolower($class_name) ) ; else if( isset($_data[ $_primary ])) { $id = $_data[ $_primary ]; if( isset(dbRecord::$instances[ $class_name ][ $id ] ) ) $db_object = dbRecord::$instances[ $class_name ][ $id ]; else $db_object = new $class_name( $id ); } else $db_object = new $class_name( FALSE ); if( isset($_data) ) foreach ( $_data as $k => $v ) { if (( $k != $_primary )&&(!is_array($v)) ) $db_object->$k = trim( $v ); } $db_object->save(); return TRUE; } public static function delete( $class_name, $db_object = NULL, & $_data = NULL ) { if ( dbSimplify::parse( $class_name, $db_object, $db_object ) ) { $db_object->Active = 0; $db_object->save(); return TRUE; } return FALSE; } public static function toarray($class_name, $name_attr = 'Name', $select_param = array()) { $data = array( ); if ( class_exists( $class_name ) ) { $query = dbQuery( $value )->cond( 'Active', 1 ); if (sizeof($select_param) > 0) foreach ($select_param as $k=>$v) $query->cond($k, $v); if( dbSimplify::query( $query->exec(), $db_objs, TRUE ) ) { foreach ($db_objs as $item) $data[$item->id] = $item->$name_attr; } } return $data; } } interface iCache { const TABLE_NAME = 'cache'; public static function & get( $key ); public static function ifget( $key, & $ret_val ); public static function set( $key, $value ); } interface idbLocalizable {} interface idbMemoryTable { public function create(); public function truncate(); public function set( $array_id, $key, $value, $cache_id = NULL ); public function get( $array_id, $key, $cache_id = NULL ); public function clear( $array_id, $key = NULL ); public function clear_like( $array_id ); public function exists( $array_id ); public function & collection( $array_id ); } interface idbQuerier { public function parse( $expression ); public function plain( $sql ); public function all(); public function first(); public function last(); public function find( dbQuery & $query_params ); public function delete( dbQuery & $query_params ); public function update( dbQuery & $query_params ); public function select( $sql ); public function where( $sql ); public function join( & $query_params ); public function order( & $query_params ); public function group( & $query_params ); public function limit( & $query_params ); public function exec(); } interface idbQuery { public function parse( $argument, array $params = NULL ); public function or_( $relation = 'OR' ); public function cond( $attribute, $value = '', $relation = dbRelation::EQUAL ); public function join( $table_name, $class_name = null, $ignore = false ); public function add_field( $field, $alias = NULL ); public function count(); public function innerCount(); public function flush(); public function random( & $return_value = null); public function fields( $field_name, & $return_value = null ); public function & exec( & $return_value = null); public function & first( & $return_value = null ); } } namespace samson\js\core{ class SamsonJSConnector extends \samson\core\CompressableExternalModule { protected $id = 'samsonjs'; protected $requirements = array('core'); } } namespace samson\cms{ class CMS extends \samson\core\CompressableService { public static function getMaterialsCountByStructures($selectors, $selector = 'Url', $handler = null) { if(!is_array($selectors)) { $selectors = array($selectors); } $results = array_flip($selectors); $countData = null; $query = dbQuery('structure') ->cond($selector, $selectors) ->add_field('Count(material.materialid)', '__Count', false) ->join('structurematerial') ->join('material') ->cond('material_Active', 1) ->cond('material_Published', 1) ->cond('material_Draft', 0) ->group_by('structureid'); if (is_callable($handler)) { call_user_func($handler, array(& $query)); } if ($query->exec($countData)) { foreach ($countData as $result) { if (isset($results[$result->Url])) { $results[$result->Url.'Count'] = $result->__Count; } } } foreach ($selectors as $select) { unset($results[$select]); } return $results; } public static function getMaterialsByStructures($structures, & $materials = array(), $className = 'samson\cms\CMSMaterial', $handler = null, array $handlerParams = array()) { $structures = is_array($structures) ? $structures : array($structures); $query = dbQuery('samson\cms\CMSNavMaterial') ->cond('StructureID', $structures) ->join('material') ->cond('material_Active', 1) ->group_by('MaterialID'); if (is_callable($handler)) { if (call_user_func_array($handler, array_merge(array(&$query), $handlerParams)) === false) { return false; } } $ids = array(); if ($query->fieldsNew('MaterialID', $ids)) { if (dbQuery($className)->cond('MaterialID', $ids)->join('samson\cms\CMSGallery')->exec($materials)) { return true; } } return false; } protected $id = 'cmsapi'; public $material_fields = array(); public static $fields = array(); public static $materialAttributes = array(); public function prepare() { $sql_user = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."user` (
              `UserID` int(11) NOT NULL AUTO_INCREMENT,
		  `FName` varchar(255) NOT NULL,
		  `SName` varchar(255) NOT NULL,
		  `TName` varchar(255) NOT NULL,
		  `Email` varchar(255) NOT NULL,
		  `Password` varchar(255) NOT NULL,
		  `md5_email` varchar(255) NOT NULL,
		  `md5_password` varchar(255) NOT NULL,
		  `Created` datetime NOT NULL,
		  `Modyfied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `GroupID` int(11) NOT NULL,
		  `Active` int(11) NOT NULL,
		  `Online` int(11) NOT NULL,
		  `LastLogin` datetime NOT NULL,
		  PRIMARY KEY (`UserID`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_gallery = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."gallery` (
		  `PhotoID` int(11) NOT NULL AUTO_INCREMENT,
		  `MaterialID` int(11) NOT NULL,
		  `Path` varchar(255) NOT NULL,
		  `Src` varchar(255) NOT NULL,
		  `Loaded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `Description` text NOT NULL,
		  `Name` varchar(255) NOT NULL,
		  `Active` int(11) NOT NULL,
		  PRIMARY KEY (`PhotoID`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_group = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."group` (
		  `GroupID` int(20) NOT NULL AUTO_INCREMENT,
		  `Name` varchar(255) NOT NULL,
		  `Active` int(11) NOT NULL,
		  PRIMARY KEY (`GroupID`)
		) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_groupright ="CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."groupright` (
		  `GroupRightID` int(11) NOT NULL AUTO_INCREMENT,
		  `GroupID` int(10) NOT NULL,
		  `RightID` int(20) NOT NULL,
		  `Entity` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '_',
		  `Key` varchar(50) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
		  `Ban` int(10) NOT NULL,
		  `TS` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `Active` int(11) NOT NULL,
		  PRIMARY KEY (`GroupRightID`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;"; $sql_right = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."right` (
		  `RightID` int(20) NOT NULL AUTO_INCREMENT,
		  `Name` varchar(255) NOT NULL,
		  `Active` int(11) NOT NULL,
		  PRIMARY KEY (`RightID`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_relation_material = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."related_materials` (
		  `related_materials_id` int(11) NOT NULL AUTO_INCREMENT,
		  `first_material` int(11) NOT NULL,
		  `first_locale` varchar(10) NOT NULL,
		  `second_material` int(11) NOT NULL,
		  `second_locale` varchar(10) NOT NULL,
		  PRIMARY KEY (`related_materials_id`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_material = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."material` (
		  `MaterialID` int(11) NOT NULL AUTO_INCREMENT,
		  `Name` varchar(555) NOT NULL,
		  `Content` text NOT NULL,
		  `Published` int(11) NOT NULL,
		  `Created` datetime NOT NULL,
		  `UserID` int(11) NOT NULL,
		  `Modyfied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `Teaser` text NOT NULL,
		  `Url` varchar(255) NOT NULL,
		  `Keywords` varchar(255) NOT NULL,
		  `Description` varchar(255) NOT NULL,
		  `Title` varchar(255) NOT NULL,
		  `Draft` int(11) NOT NULL,
		  `Draftmaterial` int(11) NOT NULL,
		  `Active` int(11) NOT NULL DEFAULT '1',
		  `structure_id` int(11) NOT NULL,
		PRIMARY KEY (`MaterialID`),
		KEY `Url` (`Url`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_structure = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."structure` (
		  `StructureID` int(11) NOT NULL AUTO_INCREMENT,
		  `ParentID` int(11) NOT NULL,
		  `Name` varchar(255) NOT NULL,
		  `Created` datetime NOT NULL,
		  `UserID` int(11) NOT NULL,
		  `Modyfied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `Url` varchar(255) NOT NULL,
		  `MaterialID` int(11) NOT NULL,
		  `PriorityNumber` int(11) NOT NULL,
		  `Active` int(11) NOT NULL DEFAULT '1',
		PRIMARY KEY (`StructureID`),
		KEY `Url` (`Url`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_structurematerial = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."structurematerial` (
		  `StructureMaterialID` int(11) NOT NULL AUTO_INCREMENT,
		  `StructureID` int(11) NOT NULL,
		  `MaterialID` int(11) NOT NULL,
		  `Modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `Active` int(11) NOT NULL DEFAULT '1',
		  PRIMARY KEY (`StructureMaterialID`),
		  KEY `StructureID` (`StructureID`),
		  KEY `MaterialID` (`MaterialID`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_field = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."field` (
		  `FieldID` int(11) NOT NULL AUTO_INCREMENT,
		  `ParentID` int(11) NOT NULL,
		  `Name` varchar(255) NOT NULL,
		  `Type` int(11) NOT NULL,
		  `Value` text NOT NULL,
		  `Description` text NOT NULL,
		  `UserID` int(11) NOT NULL,
		  `Created` datetime NOT NULL,
		  `Modyfied` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `Active` int(11) NOT NULL,
		  PRIMARY KEY (`FieldID`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_navfield = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."structurefield` (
		  `StructureFieldID` int(11) NOT NULL AUTO_INCREMENT,
		  `StructureID` int(11) NOT NULL,
		  `FieldID` int(11) NOT NULL,
		  `Modified` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `Active` int(11) NOT NULL,
		  PRIMARY KEY (`StructureFieldID`),
		  KEY `StructureID` (`StructureID`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_materialfield = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."materialfield` (
		  `MaterialFieldID` int(11) NOT NULL AUTO_INCREMENT,
		  `FieldID` int(11) NOT NULL,
		  `MaterialID` int(11) NOT NULL,
		  `Value` text NOT NULL,
		  `Active` int(11) NOT NULL,
		  PRIMARY KEY (`MaterialFieldID`),
		  KEY `MaterialID` (`MaterialID`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_structure_relation = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."structure_relation` (
		  `structure_relation_id` int(11) NOT NULL AUTO_INCREMENT,
		  `parent_id` int(11) NOT NULL,
		  `child_id` int(11) NOT NULL,
		  PRIMARY KEY (`structure_relation_id`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; $sql_version = " CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."cms_version` ( `version` varchar(15) not null default '1')
				ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; db()->simple_query($sql_version); db()->simple_query($sql_field); db()->simple_query($sql_navfield); db()->simple_query($sql_materialfield); db()->simple_query($sql_material); db()->simple_query($sql_structure); db()->simple_query($sql_structurematerial); db()->simple_query($sql_user); db()->simple_query($sql_group); db()->simple_query($sql_right); db()->simple_query($sql_groupright); db()->simple_query($sql_relation_material); db()->simple_query($sql_gallery); db()->simple_query( $sql_structure_relation); db()->simple_query("INSERT INTO `".\samson\activerecord\dbMySQLConnector::$prefix."user` (`UserID`, `FName`, `SName`, `TName`, `Email`, `Password`, `md5_Email`, `md5_Password`, `Created`, `Modyfied`, `GroupID`, `Active`, `Online`, `LastLogin`) VALUES
	 (1, 'Виталий', 'Егоров', 'Игоревич', 'admin', 'vovan123', '21232f297a57a5a743894a0e4a801fc3', 'fa9bb23b40db7ccff9ccfafdac0f647c', '2011-10-25 14:59:06', '2013-05-22 11:52:38', 1, 1, 1, '2013-05-22 14:52:38')
			ON DUPLICATE KEY UPDATE Active=1"); db()->migration( get_class($this), array( $this, 'migrator' )); new \samson\activerecord\TableRelation( 'material', 'user', 'UserID' ); new \samson\activerecord\TableRelation( 'material', 'gallery', 'MaterialID', \samson\activerecord\TableRelation::T_ONE_TO_MANY ); new \samson\activerecord\TableRelation( 'material', 'materialfield', 'MaterialID', \samson\activerecord\TableRelation::T_ONE_TO_MANY ); new \samson\activerecord\TableRelation( 'material', 'field', 'materialfield.FieldID', \samson\activerecord\TableRelation::T_ONE_TO_MANY ); new \samson\activerecord\TableRelation( 'material', 'structurematerial', 'MaterialID', \samson\activerecord\TableRelation::T_ONE_TO_MANY ); new \samson\activerecord\TableRelation( 'material', 'structure', 'structurematerial.StructureID', \samson\activerecord\TableRelation::T_ONE_TO_MANY ); new \samson\activerecord\TableRelation( 'materialfield', 'field', 'FieldID' ); new \samson\activerecord\TableRelation( 'materialfield', 'material', 'MaterialID' ); new \samson\activerecord\TableRelation( 'structurematerial', 'structure', 'StructureID' ); new \samson\activerecord\TableRelation( 'structurematerial', 'materialfield', 'MaterialID', \samson\activerecord\TableRelation::T_ONE_TO_MANY ); new \samson\activerecord\TableRelation( 'structurematerial', 'material', 'MaterialID', \samson\activerecord\TableRelation::T_ONE_TO_MANY ); new \samson\activerecord\TableRelation( 'structure', 'material', 'structurematerial.MaterialID', \samson\activerecord\TableRelation::T_ONE_TO_MANY, null, 'manymaterials'); new \samson\activerecord\TableRelation( 'structure', 'gallery', 'structurematerial.MaterialID', \samson\activerecord\TableRelation::T_ONE_TO_MANY, null, 'manymaterials'); new \samson\activerecord\TableRelation( 'structure', 'user', 'UserID' ); new \samson\activerecord\TableRelation( 'structure', 'materialfield', 'material.MaterialID', \samson\activerecord\TableRelation::T_ONE_TO_MANY, 'MaterialID', '_mf'); new \samson\activerecord\TableRelation( 'structure', 'structurematerial', 'StructureID', \samson\activerecord\TableRelation::T_ONE_TO_MANY ); new \samson\activerecord\TableRelation( 'related_materials', 'material', 'first_material', \samson\activerecord\TableRelation::T_ONE_TO_MANY, 'MaterialID' ); new \samson\activerecord\TableRelation( 'related_materials', 'materialfield', 'first_material', \samson\activerecord\TableRelation::T_ONE_TO_MANY, 'MaterialID' ); new \samson\activerecord\TableRelation( 'field', 'structurefield', 'FieldID' ); new \samson\activerecord\TableRelation( 'field', 'structure', 'structurefield.StructureID' ); new \samson\activerecord\TableRelation( 'structurefield', 'field', 'FieldID' ); new \samson\activerecord\TableRelation( 'structurefield', 'materialfield', 'FieldID' ); new \samson\activerecord\TableRelation( 'structurefield', 'material', 'materialfield.MaterialID' ); new \samson\activerecord\TableRelation( 'structure', 'structure_relation', 'StructureID', \samson\activerecord\TableRelation::T_ONE_TO_MANY, 'parent_id', 'children_relations' ); new \samson\activerecord\TableRelation( 'structure', 'structure', 'children_relations.child_id', \samson\activerecord\TableRelation::T_ONE_TO_MANY, 'StructureID', 'children' ); new \samson\activerecord\TableRelation( 'structure', 'structure_relation', 'StructureID', \samson\activerecord\TableRelation::T_ONE_TO_MANY, 'child_id', 'parents_relations' ); new \samson\activerecord\TableRelation( 'structure', 'structure', 'parents_relations.parent_id', \samson\activerecord\TableRelation::T_ONE_TO_MANY, 'StructureID', 'parents' ); new \samson\activerecord\TableRelation( 'structurematerial', 'structure_relation', 'StructureID', \samson\activerecord\TableRelation::T_ONE_TO_MANY, 'parent_id' ); return true && parent::prepare(); } public function migrator($to_version = null) { if( func_num_args() ) { db()->simple_query("ALTER TABLE  `".\samson\activerecord\dbMySQLConnector::$prefix."cms_version` CHANGE  `version`  `version` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT  '".$to_version."';"); die('Database successfully migrated to ['.$to_version.']'); } else { $version_row = db()->query('SHOW COLUMNS FROM `'.\samson\activerecord\dbMySQLConnector::$prefix.'cms_version`'); return $version_row[0]['Default']; } } public function migrate_1_to_2() { elapsed('Removing `Relations` table'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'relations'); elapsed('Removing old localized tables if they exists table'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'enstructure'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'enstructurematerial'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'enstructurefield'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'enfield'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'enmaterial'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'enmaterialfield'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'uastructure'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'uastructurematerial'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'uastructurefield'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'uafield'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'uamaterial'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'uamaterialfield'); elapsed('Removing old group/right tables if they exists table'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'`group`'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'`right`'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'groupright'); db()->simple_query('DROP TABLE IF EXISTS '.\samson\activerecord\dbMySQLConnector::$prefix.'mem_cache'); elapsed('Adding `numeric_value` field into `materialfield` table'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'materialfield` ADD  `numeric_value` INT( 255 ) NOT NULL AFTER  `Value`'); elapsed('Adding `locale` field into `material` table'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` ADD  `locale` varchar( 2 ) NOT NULL AFTER `Name`'); elapsed('Removing `Draftmaterial` field from `material` table'); db()->simple_query('ALTER TABLE `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` DROP `Draftmaterial`'); elapsed('Changing `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` table columns order'); db()->simple_query('ALTER TABLE `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` MODIFY `Teaser` TEXT AFTER `Content`'); db()->simple_query('ALTER TABLE `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` MODIFY `Published` INT(1) UNSIGNED AFTER `Draft`'); db()->simple_query('ALTER TABLE `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` MODIFY `Active` INT(1) UNSIGNED AFTER `Published`'); db()->simple_query('ALTER TABLE `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` MODIFY `UserID` INT(11) AFTER `Title`'); db()->simple_query('ALTER TABLE `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` MODIFY `Modyfied` TIMESTAMP AFTER `Title`'); db()->simple_query('ALTER TABLE `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` MODIFY `Created` DATETIME AFTER `Title`'); } public function migrate_2_to_3() { elapsed('Adding `locale` field into `structure` table'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structure` ADD  `locale` VARCHAR( 10 ) NOT NULL AFTER  `Name` ;'); } public function migrate_3_to_4() { elapsed('Adding `locale` field into `materialfield` table'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'materialfield` ADD  `locale` VARCHAR( 10 ) NOT NULL AFTER  `numeric_value` ;'); elapsed('Adding `local` field into `field` table'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'field` ADD  `local` int( 10 ) NOT NULL AFTER  `Type` ;'); } public function migrate_4_to_5() { $this->materialColumnToField('Content', 'material'); } public function migrate_5_to_6() { $this->materialColumnToField('Teaser', 'material'); if (dbQuery('field')->Type(3)->fields('id',$fields)) { foreach (dbQuery('materialfield')->FieldID($fields)->exec() as $mf) { $mf->numeric_value = strtotime($mf->Value); $mf->save(); } } } public function migrate_6_to_7() { $db_structures = null; if (dbQuery('structure')->Active(1)->exec($db_structures)) { foreach ($db_structures as $db_structure) { $relation = new \samson\activerecord\structure_relation(false); $relation->parent_id = $db_structure->ParentID; $relation->child_id = $db_structure->id; $relation->save(); } } } public function migrate_7_to_8() { elapsed('Adding `StructureID` field into `material` table'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` ADD  `structure_id` INT( 255 ) NOT NULL AFTER  `Active`'); } public function migrate_8_to_9() { elapsed('Adding `filter` table'); elapsed('Adding `filtered` field into `field` table'); $sql_filter = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix."filter` (
		  `filter_id` int(11) NOT NULL AUTO_INCREMENT,
		  `field_id` int(11) NOT NULL,
		  `value` varchar(255) NOT NULL,
		  `locale` VARCHAR( 10 ) NOT NULL,
		  PRIMARY KEY (`filter_id`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; db()->simple_query($sql_filter); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'field` ADD  `filtered` INT( 10 ) NOT NULL AFTER  `local`'); } public function migrate_9_to_10() { db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'user`                ADD INDEX (`GroupID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'gallery`             ADD INDEX (`MaterialID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'groupright`          ADD INDEX (`GroupID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'groupright`          ADD INDEX (`RightID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'material`            ADD INDEX (`structure_id`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'material`            ADD INDEX (`UserID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structure`           ADD INDEX (`ParentID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structure`           ADD INDEX (`UserID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structure`           ADD INDEX (`MaterialID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'field`               ADD INDEX (`ParentID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structurefield`      ADD INDEX (`FieldID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'materialfield`       ADD INDEX (`FieldID`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structure_relation`  ADD INDEX (`parent_id`)'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structure_relation`  ADD INDEX (`child_id`)'); } public function migrate_10_to_11() { db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` ADD `system` INT(1) NOT NULL DEFAULT 0'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structure` ADD `system` INT(1) NOT NULL DEFAULT 0'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'field` ADD `system` INT(1) NOT NULL DEFAULT 0'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'user` ADD `system` INT(1) NOT NULL DEFAULT 0'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` DROP `locale`'); } public function migrate_11_to_12() { $this->materialColumnToField('Description', 'seo'); $structure = null; if(dbQuery('structure')->Name('material')->first($structure)) { $structure->system = 1; $structure->save(); } $structure = null; if(dbQuery('structure')->Name('seo')->first($structure)) { $structure->system = 1; $structure->save(); } $field = null; if(dbQuery('field')->Name('Content')->first($field)) { $field->system = 1; $field->save(); } $field = null; if(dbQuery('field')->Name('Teaser')->first($field)) { $field->system = 1; $field->save(); } } public function migrate_12_to_13() { $this->materialColumnToField('Keywords', 'seo'); } public function migrate_13_to_14() { $this->materialColumnToField('Title', 'seo'); } public function migrate_14_to_15() { db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` ADD `parent_id` INT(11) NOT NULL DEFAULT 0 AFTER `MaterialID`'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'material` ADD `type` INT(1) NOT NULL DEFAULT 0 AFTER `Draft`'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'structure` ADD `type` INT(1) NOT NULL DEFAULT 0 AFTER `PriorityNumber`'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'field` ADD `UserID` INT(11) NOT NULL DEFAULT 0 AFTER `PriorityNumber`'); } public function migrate_15_to_16() { db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'gallery` ADD `priority` INT(11) NOT NULL DEFAULT 0 AFTER `MaterialID`'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'gallery` ADD `size` INT(11) NOT NULL DEFAULT 0 AFTER `Src`'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'gallery` DROP `Thumbpath`'); db()->simple_query('ALTER TABLE  `'.\samson\activerecord\dbMySQLConnector::$prefix.'gallery` DROP `Thumbsrc`'); } public function materialColumnToField($column, $structure) { $user = null; if(dbQuery('user')->first($user)) { } $db_structure = null; if (!dbQuery('structure')->Url('__'.$structure)->Active(1)->first($db_structure)) { $db_structure = new \samson\activerecord\structure(false); $db_structure->Name = $structure; $db_structure->Url = '__'.$structure; $db_structure->Active = 1; $db_structure->UserID = $user->id; $db_structure->system = 1; $db_structure->save(); } $dbField = null; if (!dbQuery('field')->Name($column)->first($dbField)) { $dbField = new \samson\activerecord\field(false); $dbField->Name = $column; $dbField->Type = 8; $dbField->Active = 1; $dbField->system = 1; $dbField->save(); } $db_sf = null; if (!dbQuery('structurefield')->FieldID($dbField->id)->StructureID($db_structure->id)->Active(1)->first($db_sf)) { $db_sf = new \samson\activerecord\structurefield(false); $db_sf->FieldID = $dbField->id; $db_sf->StructureID = $db_structure->id; $db_sf->Active = 1; $db_sf->save(); } $db_materials = array(); if (dbQuery('material')->Active('1')->Draft('0')->exec($db_materials)) { trace('Found materials:'.sizeof($db_materials)); foreach ($db_materials as $db_material) { $db_sm = null; if (!dbQuery('structurematerial')->StructureID($db_structure->id)->MaterialID($db_material->id)->first($db_sm)) { $db_sm = new \samson\activerecord\structurematerial(false); $db_sm->StructureID = $db_structure->id; $db_sm->MaterialID = $db_material->id; $db_sm->Active = 1; $db_sm->save(); } $db_mf = null; if (!dbQuery('materialfield')->MaterialID($db_material->id)->FieldID($dbField->id)->Active(1)->first($db_mf)) { $db_mf = new \samson\activerecord\materialfield(false); $db_mf->MaterialID = $db_material->id; $db_mf->FieldID = $dbField->id; $db_mf->Active = 1; $db_mf->Value = $db_material[$column]; $db_mf->save(); } } } db()->simple_query('ALTER TABLE  `material` DROP  `'.$column.'`'); } public function & material($selector, $field = 'Url') { $db_cmsmat = null; if( $field == 'id' ) $field = 'MaterialID'; $classname = ns_classname('cmsmaterial', 'samson\cms'); if( $selector instanceof $classname ) return $selector; else if( isset( \samson\activerecord\dbRecord::$instances[$classname][$selector] )) $db_cmsmat = & \samson\activerecord\dbRecord::$instances[$classname][$selector]; else { $db_cmsmat = CMSMaterial::get( array( $field, $selector ), NULL, 0, 1 ); if( is_array( $db_cmsmat ) && sizeof( $db_cmsmat ) ) $db_cmsmat = array_shift($db_cmsmat); else $db_cmsmat = null; } return $db_cmsmat; } public function & navigation($selector, $field = 'Url') { $cmsnav = null; if( !isset($selector) ) return $cmsnav; if( $field == 'id' ) $field = 'StructureID'; $classname = \samson\core\AutoLoader::className('CMSNav', 'samson\cms'); if( is_a( $selector, $classname)) return $selector; else if( isset(\samson\activerecord\dbRecord::$instances[$classname][$selector]) ) {$cmsnav = & \samson\activerecord\dbRecord::$instances[$classname][$selector];} else if( dbQuery($classname) ->cond('Active',1) ->cond( $field, $selector ) ->join('children_relations') ->join('children', '\samson\cms\CMSNav') ->join('parents_relations') ->join('parents', '\samson\cms\CMSNav') ->first( $cmsnav )) { $cmsnav->prepare(); } return $cmsnav; } public function & navmaterials($selector, $field = 'Url', $handler = null) { $result = array(); if(null !== ($db_nav = $this->navigation($selector, $field))) { $ids = array(); if(dbQuery('samson\cms\CMSNavMaterial')->cond( 'StructureID', $db_nav->id )->fields( 'MaterialID', $ids )) { $q = cmsquery()->id($ids); if( isset( $handler ) ) $q->handler( $handler ); $result = $q->exec(); } } return $result; } public function e404() { $selector = url()->last(); s()->active( $this ); if( ifcmsmat( $selector, $db_material )) { $this->title = $db_material->Name; $this->keywords = $db_material->Keywords; $this->description = $db_material->Description; $this->set( $db_material ); cmsapi_template(); } } public function buildNavigation() { \samson\activerecord\dbRecord::$instances['samson\cms\CMSNav'] = array(); CMSNav::$top = new CMSNav( false ); CMSNav::$top->Name = 'Корень навигации'; CMSNav::$top->Url = 'NAVIGATION_BASE'; CMSNav::$top->StructureID = 0; { $cmsnavs = dbQuery('samson\cms\CMSNav')->cond('Active',1) ->order_by('PriorityNumber','asc')->exec(); foreach ( $cmsnavs as $cmsnav ) { \samson\activerecord\dbRecord::$instances['samson\cms\CMSNav'][ $cmsnav->Url ] = $cmsnav; } } CMSNav::build( CMSNav::$top, \samson\activerecord\dbRecord::$instances['samson\cms\CMSNav'] ); } public function afterCompress( & $obj = null, array & $code = null ) { self::$fields = array(); $t_name = '_mf'; self::$materialAttributes = CMSMaterial::$_attributes; if( dbQuery('field')->Active(1)->Name('', \samson\activerecord\dbRelation::NOT_EQUAL)->exec($this->material_fields)) foreach ($this->material_fields as $db_field) { if ($db_field->local==1) $equal = '(('.$t_name.'.FieldID = '.$db_field->id.')&&('.$t_name.".locale = '".locale()."'))"; else $equal = '(('.$t_name.'.FieldID = '.$db_field->id.')&&('.$t_name.".locale = ''))"; $v_col = 'Value'; if ( $db_field->Type == 7 ) { $v_col = 'numeric_value'; } else if( $db_field->Type == 3 ) { $v_col = 'numeric_value'; } self::$fields[$db_field->Name] = "\n".' MAX(IF('.$equal.','.$t_name.'.`'.$v_col.'`, NULL)) as `'.$db_field->Name.'`'; CMSMaterial::$_attributes[ $db_field->Name ] = $db_field->Name; CMSMaterial::$_map[ $db_field->Name ] = \samson\activerecord\dbMySQLConnector::$prefix.'material.'.$db_field->Name; } CMSMaterial::$_sql_select['this'] = ' STRAIGHT_JOIN '.CMSMaterial::$_sql_select['this']; if (sizeof(self::$fields)) { CMSMaterial::$_sql_select['this'] .= ','.implode(',', self::$fields); } CMSMaterial::$_sql_from['this'] .= "\n".'LEFT JOIN '.\samson\activerecord\dbMySQLConnector::$prefix.'materialfield as '.$t_name.' on '.\samson\activerecord\dbMySQLConnector::$prefix.'material.MaterialID = '.$t_name.'.MaterialID'; CMSMaterial::$_own_group[] = \samson\activerecord\dbMySQLConnector::$prefix.'material.MaterialID'; } public function init( array $params = array() ) { $this->afterCompress(); \samson\activerecord\dbRecord::$instances[ "samson\cms\CMSMaterial" ] = array(); } public function __construct( $path = null ) { parent::__construct( $path ); } } class Material extends \samson\activerecord\material { } class CMSMaterial extends Material implements \samson\core\iModuleViewable { public $class_name = 'material'; public static function usortGallery($a, $b) { return $a->PhotoID > $b->PhotoID; } public static function & get( array $field_value = null, $db_cmsnav = null, $draft = null, $published = null, $order_by = null, $limit = null, $group_by = null, $handler = null, $handler_params = array(), $class_name = null ) { $db_materials = array(); if (!isset($class_name)) { $class_name = 'samson\cms\CMSMaterial'; } $query = dbQuery($class_name) ->cond('Active', 1) ->join('samson\cms\CMSGallery') ->join('user') ->join('samson\cms\CMSNavMaterial') ; if (isset($limit)) { $query->limit($limit[0], $limit[1]); } if (isset($group_by)) { $query->group_by($group_by); } if (isset($field_value)) { $query->cond($field_value[0], $field_value[1]); } if (isset($draft)) { $query->cond('Draft', $draft); } if (isset($published)) { $query->cond('Published', $published); } if (is_array($order_by)) { $query->order_by($order_by[0], $order_by[1]); } elseif (!isset($order_by)) { $query->order_by('MaterialID', 'DESC'); } if (isset($db_cmsnav)) { $navId = 0; if (!is_array($db_cmsnav)) { $navId = $db_cmsnav->id; } else { $navId = $db_cmsnav; } $query ->cond('structurematerial_StructureID', $navId) ->cond('structurematerial_Active', 1); } if (is_callable($handler)) { array_unshift($handler_params, $query); call_user_func_array($handler, $handler_params); } if ($query->exec($db_materials)) { foreach ($db_materials as & $db_material) { \samson\activerecord\dbRecord::$instances[ 'samson\cms\CMSMaterial' ][ $db_material->Url ] = $db_material; $db_material->user = $db_material->onetoone['_user']; $db_material->gallery = array(); if (isset($db_material->onetomany['_gallery'])) { usort($db_material->onetomany['_gallery'], '\samson\cms\CMSMaterial::usortGallery'); foreach ($db_material->onetomany['_gallery'] as $db_gallery) { $db_material->gallery[] = $db_gallery->Src; } } if (isset($db_material->onetomany['_structurematerial'])) { $db_material->structure = $db_material->onetomany['_structurematerial']; } $db_material->onetoone = array(); $db_material->onetomany = array(); } } return $db_materials; } public $gallery; public $user; public function toView($key_prefix = '', array $restricted = array()) { $restricted = array_merge(self::$restricted, $restricted, array('fields')); $values = parent::toView($key_prefix, $restricted); if (isset($_SESSION['__CMS_EDITOR__'])) { foreach (get_object_vars($this) as $var => $value) { if (!in_array($var, $restricted) && !is_array($value) && !is_object($value)) { $values['__dm__'.$key_prefix.$var] = $this->value($var, true); } } } return $values; } public function save() { parent::save(); } public function __call( $name, $arguments ) { if( !isset($arguments[0]) ) $arguments = array( false ); return $this->value( $name, $arguments[0]); } public function value( $name, $returnValue = false ) { if( isset( $this[ $name ] ) || $this->$name ) { $html = $this->$name; if( isset($_SESSION['__CMS_EDITOR__']) ) { $html = m('cmsapi') ->set('field',$name) ->set('id',$this->id) ->set('value',$this->$name) ->set('entity','cmsmaterial') ->output('app/view/editor/material.php'); } if( $returnValue === false ) echo $html; else return $html; } } public function cmsnavs() { $cmsnavs = array(); if(dbQuery('samson\cms\CMSNavMaterial')->MaterialID($this->id)->exec($db_nms)) { foreach ($db_nms as $db_nm) $cmsnavs[] = cms()->navigation( $db_nm->StructureID, 'id' ); } return $cmsnavs; } public function & related( $handler = null ) { $db_materials = array(); $q = dbQuery('samson\cms\cmsrelatedmaterial'); if( isset($handler)) $q->handler($handler); if( $q->first_material( $this->id )->fields( 'second_material', $ids ) ) { $db_materials = cmsquery()->MaterialID($ids)->published(); } return $db_materials; } public function & relates( $handler = null ) { $db_materials = array(); $q = dbQuery('samson\cms\cmsrelatedmaterial'); if( isset($handler)) $q->handler($handler); if( $q->second_material( $this->id )->fields( 'first_material', $ids ) ) { $db_materials = array_merge( $db_materials, cmsquery()->MaterialID($ids)->published()); } return $db_materials; } } class CMSField extends \samson\activerecord\field {} class CMSGallery extends \samson\activerecord\gallery {} class CMSGroup extends \samson\activerecord\group {} class CMSGroupRight extends \samson\activerecord\groupright {} class CMSMaterialField extends \samson\activerecord\materialfield {} class CMSMaterialQuery extends \samson\activerecord\dbQuery { public function & exec( & $return_value = null) { $this->_callHandlers(); $return_value = db()->find( $this->class_name, $this ); $this->flush(); $return = null; if( func_num_args() ) $return = (is_array( $return_value ) && sizeof( $return_value )); else $return = & $return_value; foreach ( $return_value as & $db_material ) { \samson\activerecord\dbRecord::$instances[ 'samson\cms\CMSMaterial' ][ $db_material->Url ] = $db_material; $db_material->user = $db_material->onetoone['_user']; if( isset($db_material->onetomany['_gallery']) ) { $db_material->gallery = array(); foreach ( $db_material->onetomany['_gallery'] as $db_gallery ) $db_material->gallery[] = $db_gallery->Src; } } return $return; } public function published( & $return_value = null ) { $this->cond( 'Draft', 0 )->cond( 'Published', 1 ); return func_num_args() ? $this->exec( $return_value ) : $this->exec(); } public function drafts( & $return_value = null ) { $this->cond( 'Draft', 0, \samson\activerecord\dbRelation::NOT_EQUAL ); return func_num_args() ? $this->exec( $return_value ) : $this->exec(); } public function originals( & $return_value = null ) { $this->cond( 'Draft', 0, \samson\activerecord\dbRelation::EQUAL ); return func_num_args() ? $this->exec( $return_value ) : $this->exec(); } public function __construct() { parent::__construct( 'samson\cms\CMSMaterial' ); $this ->cond( 'Active', 1 ) ->join( 'samson\cms\CMSGallery') ->join( 'user') ->join( 'samson\cms\CMSNavMaterial'); } } class CMSNavField extends \samson\activerecord\structurefield {} class CMSNavMaterial extends \samson\activerecord\structurematerial {} class CMSRelatedMaterial extends \samson\activerecord\related_materials {} class ClosureTable { private $name = 'samson\activerecord\\'; private $entity = null; public function __construct($name, $entity) { $this->name = $this->name.$name; $this->entity = $entity; } public static function prepare($name) { $sqlTable = "CREATE TABLE IF NOT EXISTS `".\samson\activerecord\dbMySQLConnector::$prefix.$name."` (
		  `id` int(11) NOT NULL AUTO_INCREMENT,
		  `parent_id` int(11) NOT NULL,
		  `child_id` int(11) NOT NULL,
		  `level` int(11) NOT NULL,
		  `info` varchar(50) NOT NULL,
		  PRIMARY KEY (`id`),
		  KEY `parent_id` (`parent_id`),
		  KEY `child_id` (`child_id`),
		  KEY `level` (`level`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 ;"; db()->simple_query($sqlTable); } private function isObject($obj) { $value = null; if (is_object($obj)) { $value = $obj->id; } else { $value = $obj; } return $value; } public function add($obj, $parentObj) { $childId = $this->isObject($obj); $parentId = $this->isObject($parentObj); $parents = null; $temp = null; dbQuery($this->name)->cond('child_id', $parentId)->exec($parents); foreach ($parents as $parent) { $temp = new $this->name(); $temp->parent_id = $parent->parent_id; $temp->child_id = $childId; $temp->level = $parent->level + 1; $temp->save(); } $temp = new $this->name(); $temp->parent_id = $parentId; $temp->child_id = $childId; $temp->level = 1; $temp->save(); } public function delete($obj) { $parentId = $this->isObject($obj); $children = null; $name = substr($this->name, 20); dbQuery($this->name)->cond('parent_id', $parentId)->cond('level', 1)->fields('child_id', $children); db()->simple_query('DELETE FROM `'.$name.'` WHERE parent_id ='.$parentId.' OR child_id='.$parentId); foreach ($children as $child) { $this->delete($child); } } public function moveTo($obj, $parentObj) { $currentId = $this->isObject($obj); $newParentId = $this->isObject($parentObj); $children = null; $name = substr($this->name, 20); db()->simple_query('DELETE FROM `'.$name.'` WHERE child_id='.$currentId); dbQuery($this->name)->cond('parent_id', $currentId)->cond('level', 1)->fields('child_id', $children); $this->add($currentId, $newParentId); foreach ($children as $child) { $this->moveTo($child, $currentId); } } public function getChildren($obj, $level) { $parentId = $this->isObject($obj); $children = null; $childrenEntities = null; dbQuery($this->name)->cond('parent_id', $parentId)->cond('level', $level)->fields('child_id', $children); $childrenEntities = dbQuery($this->entity)->cond('id', $children); return $childrenEntities; } public function getParents($obj, $level = null) { $childId = $this->isObject($obj); $parents = null; $child = array(); if (dbQuery($this->entity)->cond('id', $childId)->first($child)) { if (dbQuery($this->name)->cond('child_id', $childId)->cond('level', 1)->fields('parent_id', $parents)) { if ($level == null || $level > 0) { if ($level > 0) { $level = $level - 1; } foreach ($parents as $parent) { $child[$parent] = $this->getParents($parent, $level); } } } return $child; } return null; } } class Filter { public $class_name = 'filter'; private static $filterCollection = array(); public static function add($filterId) { $filter = null; if (dbQuery('filter')->cond('filter_id', $filterId)->first($filter)) { self::$filterCollection[] = $filter; } return $filter; } public static function performFilters( &$materials, $structures = null, $filters = null, $handler = null, $handlerParams = null ) { $fields = null; $structures = is_array($structures) ? $structures : $structures = array($structures); if (is_array($filters)) { foreach ($filters as $filter) { self::add($filter); } } dbQuery('field')->cond('filtered', 0, \samson\activerecord\dbRelation::NOT_EQUAL)->exec($fields); $query = dbQuery('materialfield')->cond('FieldID', array_keys($fields)); $materialsIDs = array(); $orCondition = new \samson\activerecord\Condition('OR'); foreach (self::$filterCollection as $filter) { if (!empty($fields[$filter->field_id]['filtered'])) { $andCondition = self::getFilterCondition($filter, $fields[$filter->field_id]['filtered']); $orCondition->add($andCondition); } } $query->cond($orCondition)->fields('MaterialID', $materialsIDs); $queryMaterials = dbQuery('material')->cond('MaterialID', $materialsIDs)->join('structurematerial'); if (!empty($structures)) { $queryMaterials->cond('StructureID', $structures); } if (is_callable($handler)) { if (empty($handlerParams) || !isset($handlerParams)) { $handlerParams = array(); } if (call_user_func_array( $handler, array_merge(array(&$queryMaterials), array(self::$filterCollection), $handlerParams) ) === false) { return false; } } if ($queryMaterials->exec($materials)) { return true; } return false; } private static function getFilterCondition($filter, $filterType = 1) { $condition = new \samson\activerecord\Condition(); switch ($filterType) { case '1': $condition ->add(new \samson\activerecord\Argument('FieldID', $filter->field_id)) ->add(new \samson\activerecord\Argument('Value', $filter->value)); break; case '2': $condition ->add(new \samson\activerecord\Argument('FieldID', $filter->field_id)) ->add(new \samson\activerecord\Argument('Value', $filter->value, \samson\activerecord\dbRelation::NOT_EQUAL)); break; case '3': $condition ->add(new \samson\activerecord\Argument('FieldID', $filter->field_id)) ->add(new \samson\activerecord\Argument('Value', $filter->value, \samson\activerecord\dbRelation::LOWER)); break; case '4': $condition ->add(new \samson\activerecord\Argument('FieldID', $filter->field_id)) ->add(new \samson\activerecord\Argument('Value', $filter->value, \samson\activerecord\dbRelation::GREATER)); break; } return $condition; } public static function createFilter($fieldId, $fieldValue) { if (!empty($fieldId) && !empty($fieldValue) && !dbQuery('filter')->cond('field_id', $fieldId)->cond('value', $fieldValue)->first()) { $filter = new \samson\activerecord\filter(); $filter->filter_id = $fieldId; $filter->value = $fieldValue; $filter->save(); } } public static function resetFilters() { $filters = null; if (dbQuery('materialfield') ->join('field') ->cond('filtered', 1) ->group_by('Value') ->exec($filters)) { db()->simple_query('TRUNCATE TABLE `'.\samson\activerecord\dbMySQLConnector::$prefix.'filter`'); foreach ($filters as $filter) { $newFilter = new filter(); $newFilter->field_id = $filter->FieldID; $newFilter->value = $filter->Value; $newFilter->save(); } } } public static function getFiltersByField($fieldId) { $values = array(); if (!empty($fieldId)) { dbQuery('filter')->cond('field_id', $fieldId)->exec($values); } return $values; } } abstract class GenericMaterialCollection implements \Iterator, \samson\core\iModuleViewable { protected $collection = array(); public abstract function render(); public abstract function fill(); public function toView($prefix = null, array $restricted = array()) { return array($prefix.'html' => $this->render()); } public function __construct() { $this->collection = call_user_func_array(array($this, 'fill'), func_get_args()); } public function current() { return current($this->collection); } public function next() { return next($this->collection); } public function key() { return key($this->collection); } public function valid() { $key = key($this->collection); return ( $key !== NULL && $key !== FALSE); } public function rewind() { reset($this->collection); } } class MaterialCollection extends GenericMaterialCollection { protected $indexRenderer; protected $itemRenderer; public function __construct($indexRenderer, $itemRenderer) { $this->indexRenderer = $indexRenderer; $this->itemRenderer = $itemRenderer; parent::__construct(); } public function render() { $html = ''; if (sizeof($this->collection)) { foreach ($this->collection as &$item) { $html .= call_user_func_array($this->itemRenderer, array(&$item)); } $html = call_user_func_array($this->indexRenderer, array(&$html)); } return $html; } public function fill(){ return $this->collection; } } class Navigation extends \samson\activerecord\structure implements \Iterator { public static function build( CMSNav & $parent, array & $records, $level = 0 ) { foreach ($records as & $record ) { if( $record->StructureID == $parent->StructureID ) continue; if( $record->ParentID == $parent->StructureID ) { $record->parent = & $parent; $current = & $record; $url_base = ''; while( isset( $current ) ) { $record->parents[] = & $current; $url_base = trim($current->Url.'/'.$url_base); $record->url_base[ $current->StructureID ] = $url_base; $record->url_base[ $current->StructureID.'_'.locale() ] = locale().'/'.$url_base; $current = & $current->parent; } $record->level = $level; $parent->children[ 'id_'.$record->StructureID ] = $record; self::build( $record, $records, ( $level + 1 ) ); } } } public static $top; public $parent = NULL; public $parentsnav = array(); protected $parents = array(); public $children = array(); public $Url; protected $url_base = ''; protected $level = 0; protected $base = false; public function tree(){ $tree = array(); $s_rs = array(); if(dbQuery('structure_relation')->exec($s_r)){ } } public function toView( $key_prefix = '', array $restricted = array() ) { return parent::toView( $key_prefix, array( 'parent','parents','children', ) ); } public function materials( array $order_by = NULL ){ return CMSMaterial::get( NULL, $this, 0, 1, $order_by ); } public function random_materials( $count = 1 ){ return CMSMaterial::get( NULL, $this, 0, 1, array( 'RAND()', ''), array( 0, $count) ); } public function fields() { $fields = array(); if( dbQuery('samson\cms\CMSNavField')->StructureID($this->id)->Active(1)->exec( $db_fields ) ) { $id = array(); foreach ( $db_fields as $db_field ) $id[] = $db_field->FieldID; $fields = dbQuery('field')->FieldID( $id )->exec(); } return $fields; } public function url( CMSNav & $parent = NULL ) { if( ! isset($parent) ) $parent = & $this; echo (isset($this->url_base[ $parent->id ]) ? $this->url_base[ $parent->id ]:''); } public function parents( CMSNav & $bound = NULL) { $parents = array(); $this->base(); if (sizeof($this->parentsnav)>0) { $parent = current($this->parentsnav); $parents[] = $parent; if( !(isset( $bound ) && ( $bound == $this->parentsnav[0] )) ){ $parents = array_merge($parents, $parent->parents($bound)); } } return $parents; } public function children() { $this->base(); return $this->children; } public function parent() { $this->base(); return $this->parent; } public function priority( $direction = NULL ) { if( isset($this->parent) ) { $p_index = 0; foreach ( $this->parent as $id => $child ) { if( $child->PriorityNumber != $p_index) { $child->PriorityNumber = $p_index; $child->save(); } $p_index++; } $children = array_values( $this->parent->children ); $old_index = $this->PriorityNumber; $new_index = $old_index - $direction; $new_index = $new_index == sizeof($children) ? 0 : $new_index; $new_index = $new_index == -1 ? sizeof($children) - 1 : $new_index; if( isset($children[ $new_index ] ) ) { $second_nav = $children[ $new_index ]; $second_nav->PriorityNumber = $old_index; $second_nav->save(); $this->PriorityNumber = $new_index; $this->save(); } } } public function toHTML( & $parent = NULL, $view = NULL, $limit = null, $ulClass = null, $liClass = null, $counterFunc = null, $level = -1, & $html = '' ) { if (!isset( $parent )) { $parent = & $this; } if(($limit > $level) || !isset($limit)) { $last = isset($limit)?($limit-$level):0; if ($level != -1) { if ($parent->base || ($last == 1)){ $children = $parent->children(); } else { $children = $parent->baseChildren(); } } else { $children = $parent->baseChildren(); } if (sizeof($children)) { $level++; $html .= '<ul class="'.$ulClass.' level-'.$level.'")>'; foreach ( $children as $id => $child ) { $currClass = ''; if (url()->last == '') { $currClass = 'currentSamsonCMS'; } $html .= '<li class="'.$liClass.' '.$currClass.'">'; $counter = 0; if (is_callable($counterFunc)) { $counter = call_user_func($counterFunc, $child); } if (isset($view)) { $html .= m()->view($view) ->counter($counter) ->cmsmaterial($child) ->output() ; } else { $html .= $child->Name; } if (!isset($level) || $level < $limit) { $this->toHTML( $child, $view, $limit, $ulClass, $liClass, null, $level, $html ); } $html .= '</li>'; } $html .='</ul>'; } } return $html; } public function & def() { $db_cmsmat = null; if( ! ifcmsmat( $this->MaterialID, $db_cmsmat, 'id') ) { } return $db_cmsmat; } public function isCurrent( $output = '' ){ if( in_array( url()->text().'/', $this->url_base) ) { echo $output; return TRUE; } return FALSE; } public function __call( $name, $arguments ) { if( isset( $this[ $name ] ) || $this->$name ) { $html = $this->$name; if( isset($_SESSION['__CMS_EDITOR__']) ) $html = m('cmsapi') ->set('field',$name) ->set('id',$this->id) ->set('value',$this->$name) ->set('entity','cmsnav') ->output('app/view/editor/material.php'); echo $html; } } public function prepare() { $this->base = true; if (isset($this->onetomany['_children'])) { foreach ($this->onetomany['_children'] as & $child) { $this->children[$child->id] = & $child; } unset($this->onetomany['_children']); } if (isset($this->onetomany['_parents'])) { foreach ($this->onetomany['_parents'] as & $parent) { $this->parentsnav[$parent->id] = & $parent; $this->parent = & $parent; } unset($this->onetomany['_parents']); } } protected function base() { if (!$this->base){ $classname = get_class($this); $cmsnav = null; if( dbQuery($classname) ->cond('Active',1) ->StructureID( $this->id) ->join('children_relations',null, true) ->join('children', get_class($this)) ->join('parents_relations', null, true) ->join('parents', get_class($this)) ->first( $cmsnav )) { if (isset($cmsnav->onetomany['_children'])) { $this->onetomany['_children'] = & $cmsnav->onetomany['_children']; } if (isset($cmsnav->onetomany['_parents'])) { $this->onetomany['_parents'] = & $cmsnav->onetomany['_parents']; } $this->prepare(); } } } protected function baseChildren() { $this->base(); $classname = get_class($this); $cmsnavs = null; $children_id = array_keys($this->children); if (sizeof($children_id)){ if( dbQuery($classname) ->cond('Active',1) ->cond('StructureID', $children_id) ->join('children_relations', null, true) ->join('children', $classname) ->join('parents_relations', null, true) ->join('parents', $classname) ->exec( $cmsnavs )) { $this->children = array(); foreach ($cmsnavs as & $cmsnav) { $cmsnav->prepare(); $this->children[] = & $cmsnav; } } } return$this->children; } public function __sleep() { $_attributes = null; eval('$_attributes = '.get_class($this).'::$_attributes;'); return $_attributes; } public function rewind(){$this->base(); reset( $this->children ); } public function next(){$this->base(); return next( $this->children ); } public function current(){$this->base(); return current( $this->children ); } public function key(){$this->base();return key( $this->children ); } public function valid(){$this->base(); $key = key( $this->children ); return ( $key !== NULL && $key !== FALSE ); } } class CMSNav extends Navigation { } } namespace { function time_difference( $enddate, $startdate = null ) { if(!isset($startdate)) $startdate = time(); else $startdate = strtotime($startdate); $difference = strtotime($enddate) - $startdate; $minutes_delimeter = 60; $hours_delimeter = $minutes_delimeter * 60; $days_delimiter = $hours_delimeter * 24; $month_delimiter = $days_delimiter * 30; $year_delimiter = $month_delimiter * 12; $year = round( $difference / $year_delimiter ); $year_ms = $year * $year_delimiter; $month = round( ($difference - $year_ms) / $month_delimiter ); $month_ms = abs($month * $month_delimiter); $days = round( ($difference - $year_ms - $month_ms) / $days_delimiter ); $days_ms = abs($days * $days_delimiter); $hours = round( ($difference - $year_ms - $month_ms - $days_ms) / $hours_delimeter ); $hours_ms = abs($hours * $hours_delimeter); $minutes = round( ($difference - $year_ms - $month_ms - $days_ms - $hours_ms) / $minutes_delimeter ); $minutes_ms = abs($minutes * $minutes_delimeter); $seconds = ($difference - $year_ms - $month_ms - $days_ms - $hours_ms - $minutes); return array( 'year' => $year, 'month' => $month, 'day' => $days, 'hour' => $hours, 'minute' => $minutes, 'second' => $seconds ); } function replace_url( $str, $replacement = null ) { if( !isset($replacement) ) $replacement = "<a href=\"\\0\" rel=\"nofollow\" target=\"_blank\">\\0</a>"; $pattern = '(?xi)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`\!()\[\]{};:\'".,<>?«»“”‘’]))'; return preg_replace("!$pattern!i", $replacement, $str); } function array_power_set( array $array, $size = null) { $results = array(array()); foreach ($array as $element) { foreach ($results as $combination) { array_push($results, array_merge(array($element), $combination)); } } $_results = array(); if(isset($size)) foreach ($results as $combination) { if( sizeof($combination) == $size) $_results[] = $combination; } else $_results = & $results; return $_results; } function pathname( $path ) { if( ($p = strrpos( $path, __NS_SEPARATOR__ )) === false ) { $p = strrpos( $path, '/' ); } return $p !== false ? substr( $path, 0, $p ) : $path; } function normalizepath( $path ){ return str_replace( array('\\\\','///', '//','\\'), '/', $path );} function & array_change_key_case_unicode( array $arr, $c = CASE_LOWER) { $ret = array(); $c = ($c == CASE_LOWER) ? MB_CASE_LOWER : MB_CASE_UPPER; foreach ( $arr as $k => $v ) $ret[ mb_convert_case( $k, $c, "UTF-8" ) ] = $v; return $ret; } function array_filter_recursive( array & $input ) { foreach ( $input as & $value ) { if ( is_array( $value ) ) { $value = array_values( array_filter_recursive( $value ) ); } } return array_filter($input); } function mapping_renew_indeces( $mapper_selector ) { $e = array(); foreach ( $mapper_selector()->all() as $r) { if( ! isset( $e[ $r->Entity ] ) )$e[ $r->Entity ] = array(); $key = $r->Entity . '_' . sizeof($e[ $r->Entity ]); $e[ $r->Entity ][] = $key; $r->EntityID = $key; $r->save(); } } function print_a( $data, $return = FALSE ) { $out = str_replace( array("\n"," "), array('<br>','&nbsp;'), print_r( $data, TRUE )); if( !$return ) echo $out; return $out; } function debug_parse_markers( $pattern, array & $args = NULL ) { $a_ind = 0; $a_count = sizeof( $args ); $l_pos = 0; if( strlen( $pattern ) > 0 && $a_count > 0 ) { while( ($l_pos = strpos( $pattern, '##', $l_pos )) !== FALSE ) { if( $a_ind < $a_count ) { $a_value = '<b>' . $args[ $a_ind++ ] . '</b>'; $pattern = substr_replace( $pattern, $a_value, $l_pos, 2 ); } } } return $pattern; } function trace( $text = '', $totextarea = false ) { if( !$totextarea ) echo '' .print_a($text,TRUE).'<br>'."\n"; else echo '<textarea style="z-index:1000; position:relative;">'.print_r( $text,true).'</textarea>'; return FALSE; } function & debug_parse_args( array $args ) { $result = array(); $args_count = sizeof( $args ); for ($j = 0; $j < $args_count; $j++ ) { $arg = & $args[ $j ]; switch( gettype($arg) ) { case 'array': $array_values = array_slice( $arg, 0, 5 ); $result[] = 'Array#'.sizeof($arg).'(' . implode(', ', debug_parse_args($array_values)). ')'; break; case 'string': $result[] = '&#34;' . $arg . '&#34;'; break; case 'object': $class = 'Class:' . get_class( $arg ); if(get_parent_class($arg) == 'dbRecord') $class .= '('.$arg->id.')'; else if(get_class($arg) == 'Module') $class .= '('.$arg->id().')'; $result[] = $class; break; case 'NULL': $result[] = 'NULL'; break; default: $result[] = $arg; } } return $result; } function debug_to_string( $errno = NULL, $file = NULL, $line = NULL, $class = NULL, $function = NULL, $args = NULL ) { if( is_array( $errno ) ) { extract( $errno ); $errno = NULL; } $html = ''; if( isset( $errno ) ) $html .= $errno.', '; if( isset( $file ) ) $html .= $file.', '; if( isset( $line ) ) $html .= '<b>стр. '.$line.'</b>, '; if( isset( $class ) ) $html .= '<b>'.$class.'::</b>'; if( isset( $function ) ) $html .= '<b>'.$function.'</b>( '; if( isset( $args ) ) $html .= implode( ', ', debug_parse_args( $args ) ) . ' )'; return $html; } function debug_backtrace_html( $message, array $backtrace = NULL ) { $html = array(); $stack_size = sizeof( $backtrace ); for ($i = 1; $i < $stack_size; $i++) $html[] = debug_to_string( $backtrace[ $i ] ); $id = '__error_backtrace_'.rand(0, 1000); return '<ul class="_core_error_text">
				<li class="_core_error_function">
					<input type="checkbox" class="elapsed_click" id="'.$id.'">
					<label for="'.$id.'"></label>' . $message . '
					<ul class="_core_error_stack"><li>' . implode( '</li>
						<li>' ,$html ) . '</li>
					</ul>
				</li>
			</ul>'; } function elapsed( $text = '' ) { static $l = __SAMSON_T_STARTED__; $c = microtime(TRUE); e( number_format($c-__SAMSON_T_STARTED__,5).' - '.number_format($c-$l,5).' -- '.print_a($text,TRUE), D_SAMSON_DEBUG ); $l = $c; } function & uniset( & $value = NULL, $value1 = NULL, $value2 = NULL ) { if( ! isset($value) ) { $value = ( isset( $value1 ) ? $value1 : $value2); } return $value; } function html_locale_ul() { $result = ''; $desc = array( 'UA' => 'title="Відкрити українську версію сайта"', 'RU' => 'title="Открыть русскую версию сайта"', 'EN' => 'title="Open English version"', ); foreach( \samson\core\SamsonLocale::get() as $locale ) { $class = locale() == $locale ? 'class="active"' : ''; $locale_name = $locale == '' ? 'RU' : strtoupper($locale); $result .= '<li '.$desc[ $locale_name ].' id="'.$locale_name.'_locale"><a '.$class.' href="'.url()->build( url()->text(), 'locale', $locale).'">'.$locale_name.'</a></li>'; } return $result; } function utf8_ucfirst( $string, $encoding = 'utf-8' ) { $strlen = mb_strlen($string, $encoding); $firstChar = mb_substr($string, 0, 1, $encoding); $then = mb_substr($string, 1, $strlen - 1, $encoding); return mb_strtoupper($firstChar, $encoding) . $then; } function utf8_wordwrap($string, $width=75, $break="\n", $cut=FALSE) { if($cut) { $search = '/(.{1,'.$width.'})(?:\s|$)|(.{'.$width.'})/uS'; $replace = '$1$2'.$break; } else { $search = '/(?=\s)(.{1,'.$width.'})(?:\s|$)/uS'; $replace = '$1'.$break; } return preg_replace($search, $replace, $string); } function utf8_limit_string( $str, $length, $limit_marker = '...' ) { if( strlen( $str ) > $length ) $str = mb_substr( $str, 0, $length, 'UTF-8' ).$limit_marker; return $str; } function utf8_translit( $str ) { $converter = array('а' => 'a', 'б' => 'b', 'в' => 'v', 'г' => 'g', 'д' => 'd', 'е' => 'e', 'ё' => 'je', 'ж' => 'zh', 'з' => 'z', 'и' => 'i', 'й' => 'j', 'к' => 'k', 'л' => 'l', 'м' => 'm', 'н' => 'n', 'о' => 'o', 'п' => 'p', 'р' => 'r', 'с' => 's', 'т' => 't', 'у' => 'y', 'ф' => 'f', 'х' => 'h', 'ц' => 'ts', 'ч' => 'ch', 'ш' => 'sh', 'щ' => 'sch', 'ь' => "", 'ы' => 'u', 'ъ' => "i", 'э' => 'e', 'ю' => 'ju', 'я' => 'ja', ' '=>'-', 'ї'=>'gi', 'і'=>'i'); $str = mb_strtolower($str,'UTF-8'); $str = strtr($str, $converter); $str = preg_replace('/[\-]+/ui', '-', $str); $str = trim(preg_replace('/[^a-z0-9\-\_]/ui', '', $str), '-'); $str = str_replace('--', '-', $str); return $str; } function mail_encode( $str, $charset ) { return '=?' . $charset . '?B?' . base64_encode($str) . '?='; } function mail_send( $to, $from = 'info@samsonos.com', $message = '', $subject = '', $from_user = '' ) { $from_user = mail_encode( $from_user, 'UTF-8'); $subject = mail_encode( $subject, 'UTF-8' ); $session = md5(uniqid(time())); $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n"; $headers .= 'From: '.$from_user.'<'.$from.'>'."\r\n"; $message = '<html><head></head><body>'.$message.'</body></html>'; return mail( $to, $subject, $message, $headers ); } function incline_word($words,$n){ if($n%100>4 && $n%100<20){ return $words[2]; } $a = array(2,0,1,1,1,2); return $words[$a[min($n%10,5)]]; } function date_format_ru($date) { $date = strtotime($date); $day=date("d", $date); $month_en=date("F", $date); $year=date("Y", $date); $days_of_week_en=date("l", $date); $month_ru=array( 'January'=>'января', 'February'=>'февраля', 'March'=>'марта', 'April'=>'апреля', 'May'=>'мая', 'June'=>'июня', 'July'=>'июля', 'August'=>'августа', 'September'=>'сентября', 'October'=>'октября', 'November'=>'ноября', 'December'=>'декабря', ); $days_of_week_ru=array( 'Monday'=>'Понедельник', 'Tuesday'=>'Вторник', 'Wednesday'=>'Среда', 'Thursday'=>'Четверг', 'Friday'=>'Пятница', 'Saturday'=>'Суббота', 'Sunday'=>'Воскресенье', ); $month= $month_ru[$month_en]; $days_of_week=$days_of_week_ru[$days_of_week_en]; $date="$days_of_week, $day $month $year года"; return $date; } function get_child_classes( $parent ) { $ancestors = array(); foreach ( get_declared_classes() as $class ) { if( in_array( $parent, class_parents( $class ) )) $ancestors[] = $class; } return $ancestors; } function generate_password( $count ) { $symbols = array('a','b','c','d','e','f', 'g','h','i','j','k','l', 'm','n','o','p','r','s', 't','u','v','x','y','z', 'A','B','C','D','E','F', 'G','H','I','J','K','L', 'M','N','O','P','R','S', 'T','U','V','X','Y','Z', '1','2','3','4','5','6', '7','8','9','0'); $pass = ""; for($i = 0; $i < $count; $i++) { $index = rand(0, sizeof($symbols) - 1); $pass .= $symbols[$index]; } return $pass; } function v( $name, $realName = NULL ) { $m = & m(); if( is_bool( $realName ) && ($realName === true)) $realName = '__dm__'.$name; else $realName = '__dm__'.$realName; if( isset($realName) && $m->offsetExists( $realName ))echo $m[ $realName ]; else if ( $m->offsetExists( $name )) echo $m[ $name ]; else echo $name; } function iv( $name, $realName = NULL ) { $m = & m(); if ( isvalue( $m, $name) ) echo $m[ $name ]; } function vi( $name ){ $m = & m(); if( $m->offsetExists( $name )) echo htmlentities($m[ $name ], ENT_QUOTES,'UTF-8');} function isvalue( $m, $name, $value = null ) { if( isset($m[ $name ]) ) { $var = $m[ $name ]; switch( gettype( $var ) ) { case 'boolean': return (isset($value) ? $var == $value : $var); case 'integer': return (isset($value) ? $var === intval($value): $var); case 'double': return (isset($value) ? $var === doubleval($value): $var); case 'float': return (isset($value) ? $var === floatval($value): $var); case 'array': return sizeof($var); case 'string': return (!isset($value) && isset($var{0})) || (isset($value) && $var === strval($value)) ; case 'object': return true; case 'NULL': case 'unknown type': default: return false; } } } function isval( $name, $value = null, $success = null, $failure = null, $inverse = false) { $m = & m(); $ok = isvalue( $m, $name, $value ); if( $inverse ) $ok = ! $ok; if( $ok && isset( $success) ) v($success); else if( isset($failure)) v($failure); return $ok; } function isv( $name, $success = null, $failure = null ){ return isval($name, null, $success, $failure ); } function isnv( $name, $success = null, $failure = null ){ return isval( $name, null, $success, $failure, true ); } function isnval( $name, $value = null, $success = null, $failure = null ){ return isval($name, $value, $success, $failure, true ); } function vhref( $name, $href = null, $class = null, $id = null, $title = null ) { $m = & m(); if( isvalue( $m, $name ) || isvalue( $m, $href ) ) { $name = isset( $m[ $name ] ) ? $m[ $name ] : $name; $href = isset( $m[ $href ] ) ? $m[ $href ] : $href; echo '<a id="'.$id.'" class="'.$class.'" href="'.$href.'" title="'.$title.'" >'.$name.'</a>'; } } function vimg( $src, $id='', $class='', $alt = '', $dummy = null ) { $m = & m(); if( $m->offsetExists( $src )) $src = $m[ $src ]; elseif( isset($dummy))$src = $dummy; if( $src{0} != '/' ) $src = '/'.$src; echo '<img src="'.$src.'" id="'.$id.'" class="'.$class.'" alt="'.$alt.'" title="'.$alt.'">'; } function vdate( $name, $format = 'h:i d.m.y', $function = 'date' ) { $m = & m(); if ( $m->offsetExists( $name )) echo $function( $format, strtotime($m[ $name ])); } function ism( $name ){ return (m()->id() == $name); }; function & mout(){ return m(); } function output( $view, array $vars = NULL, $prefix = NULL ) { return s()->render($view,$vars); } function classname( $class_name ) { return \samson\core\AutoLoader::getOnlyClass($class_name); } function nsname( $class_name ) { return \samson\core\AutoLoader::getOnlyNameSpace($class_name); } function html_db_form_select_from_array( $entity_name, array $db_array, $db_obj = NULL, $name_attr = 'Name', $desc_attr = 'Description', $id_attr = NULL ) { if(Samson\ActiveRecord\dbSimplify::parse( $entity_name, $db_obj, $db_obj )) $obj_id = $db_obj->id; else $obj_id = $db_obj; $select_data = array(array('id' => 0, 'name' => 'Не выбрано')); $db_objs_count = sizeof( $db_array ); for ($i = 0; $i < $db_objs_count; $i++) { $obj = & $db_array[ $i ]; if (isset($id_attr)) $id_vall = $obj[$name_attr]; else $id_vall = $obj->id; $select_data[] = array ( 'id' => $id_vall, 'name' => $obj[$name_attr], 'description' => $obj[$desc_attr] ); } return html_form_select_options( $select_data, $obj_id ); } function html_form_select_from_list( $list, $object_id = NULL ) { $data = array(); foreach ( explode( ',', $list ) as $value ) { $value = explode( ':', $value ); if( is_array($value) ) { $id = uniset( $value[0], '' ); $name = uniset( $value[1], $id, '' ); $desc = uniset( $value[2], '' ); $data[] = array( 'id' => $id, 'name' => $name, 'description' => $desc ); } } return html_form_select_options( $data, $object_id ); } function html_db_form_select_options( $entity_name, $db_obj = NULL, $name_attr = 'Name', $desc_attr = 'Description', $add_unselected = 'Не выбрано' ) { $entity_name = ns_classname( $entity_name, 'samson\activerecord' ); if( ! class_exists( $entity_name )) return FALSE; $obj_id = NULL; if (is_array($db_obj)) { foreach ($db_obj as $item) if (is_object($item)) $obj_id[] = $item->id; elseif(dbQuery( $entity_name )->id($item)->first($db_item) ) $obj_id[] = $db_item->id; } elseif (is_object($db_obj)) $obj_id = $db_obj->id; elseif(dbQuery( $entity_name )->id($db_obj)->first($db_obj) ) $obj_id = $db_obj->id; $query = dbQuery( $entity_name )->cond( 'Active', 1 )->exec(); if(dbQuery( $entity_name )->cond( 'Active', 1 )->exec($db_objs) ) { $select_data = array(); if( isset($add_unselected) ) $select_data[] = array('id' => 0, 'name' => $add_unselected ); foreach ($db_objs as $obj) { $select_data[] = array ( 'id' => $obj->id, 'name' => isset($obj->$name_attr) ? $obj->$name_attr : '-', 'description' => isset($obj->$desc_attr) ? $obj->$desc_attr : '-' ); } return html_form_select_options( $select_data, $obj_id ); } } function html_form_select_options( array $data, $object_id ) { $html = ''; $data_count = sizeof( $data ); for ($i = 0; $i < $data_count; $i++) { $obj = & $data[ $i ]; $id = uniset( $obj['id'], ''); $name = uniset( $obj['name'], '' ); $description = uniset( $obj['description'], ''); if (is_array($object_id)) $selected = (in_array($id, $object_id)) ? 'selected' : ''; else $selected = ($id == $object_id) ? 'selected' : ''; $html .= '<option title="'.$description.'" '.$selected.' value="'.$id.'">'.$name.'</option>'; } return $html; } function html_ul_from_array( array $a ) { $html = ''; if( is_array( $a ) && sizeof($a) ) { foreach ( $a as $v ) $html .= '<li>'.$v.'</li>'; $html = '<ul>'.$html.'</ul>'; } return $html; } function html_li( $array, $id_field = 'id', $name_field = 'Name', $selected_id = NULL, $id_field_name = 'value', $limit = -1, $class = 'class="item"' ) { $result = ''; if( is_array( $array ) ) { if( $limit > 0 ) $array = array_slice( $array, 0, $limit ); foreach ( $array as $k => $item ) { $class = ($item[ $id_field ] == $selected_id) ? 'class="selected"' : ''; $id = is_array( $item ) || is_object( $item ) ? $item[ $id_field ] : $k; $value = is_string( $item ) ? $item : $item[ $name_field ]; $result .= '<li '.$id_field_name.'="'.$id.'" '.$class.'>'.$value.'</li>'; } } return $result; } function path( $path, iModule & $module = NULL ) { $m = isset($module) ? $module : s()->module(); return $m->path().$path; } function url_locale_base( $url = '' ) { $args = func_get_args(); return call_user_func_array( 'url_base', $args ); } function ajax_handler( $action_handler, $action_params = NULL, $success_handler = NULL, $success_params = NULL ) { s()->async(TRUE); $responce = array(); if( !is_array( $action_params ) ) $action_params = array( $action_params ); $returnValue = ''; $action_params['returnValue'] = & $returnValue; if( !is_array( $success_params ) ) $success_params = array( $success_params ); if( is_array($action_handler) && sizeof($action_handler) ) { $a_class = $action_handler[0]; $a_method = $action_handler[1]; } else $a_method = $action_handler; if( is_array($success_handler) && sizeof($success_handler) ) { $s_class = $success_handler[0]; $s_method = $success_handler[1]; } else $s_method = $success_handler; if( function_exists( $a_method ) || method_exists( $a_class, $a_method) ) { if( ! call_user_func_array( $action_handler, $action_params ) ) { $responce['error'] = $action_params['returnValue']; } else if( function_exists( $s_method ) || method_exists( $s_class, $s_method) ) { $responce['data'] = call_user_func_array( $success_handler, $success_params ); } } return json_encode( $responce ); } function ns_classname($class_name, $ns = null) { return \samson\core\AutoLoader::className($class_name, $ns); } function uni_classname( $class_name ) { return \samson\core\AutoLoader::oldClassName($class_name); } function classnameToComposer($classname) { $namespace = nsname($classname); $moduleName = str_replace( '\\', '_', str_replace('samson\\', '', $namespace)); return \samson\core\ExternalModule::COMPOSER_VENDOR.'/'.$moduleName; } ('constants.php'); date_default_timezone_set(date_default_timezone_get()); set_time_limit( __SAMSON_MAX_EXECUTION__ ); ini_set('max_execution_time', __SAMSON_MAX_EXECUTION__); session_start(); $old_umask = umask(0); ('AutoLoader.php'); ('Config.php'); ('shortcuts.php'); ('Utils2.php'); ('View.php'); ('deprecated.php'); function & s() { static $_v; if( ! isset($_v) ) { if( isset( $GLOBALS["__CORE_SNAPSHOT"]) ) { $_v = unserialize(base64_decode($GLOBALS["__CORE_SNAPSHOT"])); } else { $_v = new samson\core\Core(); } } return $_v; } function & m( $module = NULL ) { static $_s; if( !isset($_s)) $_s = & s(); return $_s->module( $module ); } function & error(){static $_error; return ( $_error = isset($_error) ? $_error : new \samson\core\Error());} function e( $error_msg = '', $error_code = E_USER_NOTICE, $args = NULL, & $ret_val = false ) { static $_e; $_e = isset( $_e ) ? $_e : error(); $args = is_array( $args ) ? $args : array( $args ); if( isset( $args ) ) $error_msg = debug_parse_markers( $error_msg, $args ); error()->handler( $error_code, $error_msg, NULL, NULL, NULL, debug_backtrace() ); return $ret_val; } error(); function setlocales(){ $args = func_get_args(); \samson\core\SamsonLocale::set($args); } function locale( $locale = NULL ){ return \samson\core\SamsonLocale::current( $locale ); } function islocale( $locale, $output = '' ){ if( \samson\core\SamsonLocale::$current_locale == $locale) { echo $output; return true; } return false; } function locale_path( $l = null ) { $l = !isset($l) ? locale() : $l; return ($l != \samson\core\SamsonLocale::DEF)? $l.'/' : ''; } function & url(){ static $_v; return ( $_v = isset($_v) ? $_v : new \samson\core\URL()); } function url_build() { static $_v; $_v = isset($_v) ? $_v : url(); $args = func_get_args(); if (\samson\core\SamsonLocale::current() != \samson\core\SamsonLocale::DEF) { array_unshift($args, \samson\core\SamsonLocale::current()); } return call_user_func_array( array( $_v, 'build' ), $args ); } function url_base() { $args = func_get_args(); echo call_user_func_array('url_build', $args); } function module_url() { $args = func_get_args(); echo call_user_func_array('url_build', array_merge(array(url()->module), $args)); } function _cms_version(){ return new \samson\activerecord\dbQuery("cms_version"); } function _field(){ return new \samson\activerecord\dbQuery("field"); } function _filter(){ return new \samson\activerecord\dbQuery("filter"); } function _gallery(){ return new \samson\activerecord\dbQuery("gallery"); } function _group(){ return new \samson\activerecord\dbQuery("group"); } function _groupright(){ return new \samson\activerecord\dbQuery("groupright"); } function _material(){ return new \samson\activerecord\dbQuery("material"); } function _materialfield(){ return new \samson\activerecord\dbQuery("materialfield"); } function _related_materials(){ return new \samson\activerecord\dbQuery("related_materials"); } function _right(){ return new \samson\activerecord\dbQuery("right"); } function _scmstable(){ return new \samson\activerecord\dbQuery("scmstable"); } function _structure(){ return new \samson\activerecord\dbQuery("structure"); } function _structure_relation(){ return new \samson\activerecord\dbQuery("structure_relation"); } function _structurefield(){ return new \samson\activerecord\dbQuery("structurefield"); } function _structurematerial(){ return new \samson\activerecord\dbQuery("structurematerial"); } function _unitable(){ return new \samson\activerecord\dbQuery("unitable"); } function _user(){ return new \samson\activerecord\dbQuery("user"); } function & db( $link_id = NULL ){ static $_db; return ( $_db = isset($_db) ? $_db : new \samson\activerecord\dbMySQL()); } function dbQuery( $class_name, & $link = null ){ return new \samson\activerecord\dbQuery( $class_name, $link ); } function & cms(){ static $_v; return ( $_v = isset($_v) ? $_v : m('cmsapi'));} function & cmsmat( $selector, $field = 'Url' ){ static $_c; $_c = isset($_c) ? $_c : cms(); return $_c->material( $selector, $field ); } function & cmsnav( $selector, $field = 'Url' ){static $_c; $_c = isset($_c) ? $_c : cms(); return $_c->navigation( $selector, $field );} function & cmsnavmaterials( $selector, $handler = null, $field = 'Url' ) { static $_c; $_c = isset($_c) ? $_c : cms(); return $_c->navmaterials( $selector, $field, handler ); } function ifcmsnav( $selector, & $cmsnav = NULL, $field = 'Url' ) { static $_c; $_c = isset($_c) ? $_c : cms(); $cmsnav = $_c->navigation( $selector, $field ); if( $cmsnav === null ) return false; return true; } function ifcmsmat( $selector, & $cmsmat = NULL, $field = 'Url' ) { static $_c; $_c = isset($_c) ? $_c : cms(); $cmsmat = $_c->material( $selector, $field ); if( $cmsmat === null ) return false; return true; } function cmsquery(){ return new samson\cms\CMSMaterialQuery(); } function _cmsmaterial(){ return new \samson\activerecord\dbQuery('samson\cms\CMSMaterial'); } function _cmsmaterialfield(){ return new \samson\activerecord\dbQuery('samson\cms\CMSMaterialField'); } function _cmsnav(){ return new \samson\activerecord\dbQuery('\samson\cms\CMSNav'); } function _cmsnavfield(){ return new \samson\activerecord\dbQuery('samson\cms\CMSNavField');} function _cmsnavmaterial(){return new \samson\activerecord\dbQuery('samson\cms\CMSNavMaterial');} function create() { $countryList = array('sy'=>'Syria', 'dz'=>'Algeria', 'ma'=>'Morocco', 'tn'=>'Tunisia', 'tr'=>'Turkey', 'gr'=>'Greece', 'al'=>'Albania', 'me'=>'Montenegro', 'mk'=>'Macedonia', 'bg'=>'Bulgaria', 'ro'=>'Romania', 'rs'=>'Serbia', 'ba'=>'Bosnia and Herzegovina', 'hr'=>'Croatia', 'pt'=>'Portugal', 'es'=>'Spain', 'mc'=>'Monaco', 'de'=>'Germany', 'be'=>'Belgium', 'nl'=>'Netherlands', 'ck'=>'Czech Republic', 'sk'=>'Slovakia', 'hu'=>'Hungary', 'si'=>'Slovenia', 'at'=>'Austria', 'ch'=>'Switzerland', 'fr'=>'France', 'it'=>'Italy', 'pl'=>'Poland', 'md'=>'Moldova', 'by'=>'Belarus', 'lt'=>'Lithuania', 'lv'=>'Latvia', 'ee'=>'Estonia', 'ua'=>'Ukraine', 'dk'=>'Denmark', 'gb'=>'United Kingdom', 'ie'=>'Ireland', 'li'=>'Liechtenstein', 'lu'=>'Luxembourg', 'ru'=>'Russia', 'fi'=>'Finland', 'se'=>'Sweden', 'no'=>'Norway' ); foreach ($countryList as $iso=>$name) { $dbMat = new samson\activerecord\material(false); $dbMat->Active = 1; $dbMat->UserID = 1; $dbMat->Published = 1; $dbMat->Name = $name; $dbMat->Url = $iso; $dbMat->save(); $dbStrMat = new samson\activerecord\structurematerial(false); $dbStrMat->Active = 1; $dbStrMat->MaterialID = $dbMat->id; $dbStrMat->StructureID = 2; $dbStrMat->save(); createField(2, $dbMat->id, 'COTIF/CIV, SMPS, PRR'); createField(3, $dbMat->id, 'PRR Art. 11, 17, 18, 19 (1)'); createField(4, $dbMat->id, 'assistance dogs are allowed according to the GTC of SNCF; PRM provisions according to national law only'); } } function createField($fieldID, $matID, $value) { $dbMatField = new samson\activerecord\materialfield(false); $dbMatField->Active = 1; $dbMatField->MaterialID = $matID; $dbMatField->FieldID = $fieldID; $dbMatField->Value = $value; $dbMatField->save(); } function main() { $html = ''; $htmlStyle = ''; $htmlPreload = ''; $nav = cmsnav('country'); foreach ($nav->materials() as $dbMat){ $html.=m()->view('popup')->mat($dbMat)->iso($dbMat->Url)->output(); } m()->list($html)->style($htmlStyle)->block($htmlPreload); } $GLOBALS["__compressor_files"] = array(); $GLOBALS["__compressor_files"]["app/view/index.php"] = <<<'EOT'
<!DOCTYPE html><html><head>
<base href="/">
<script type="text/javascript">var __SAMSONPHP_STARTED = new Date().getTime();</script>
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]--><meta
http-equiv="Content-Type" content="text/html; charset=utf-8" ><title>Map</title><link
rel="icon" type="image/png" href="/favicon.png" ><style><?php //v('style');?></style>
<link type="text/css" rel="stylesheet" href="/08a26b5c9d15c444282fe5064a71ec78.css">
</head><body
id="<?php v('id')?>"><div
class="map">
<img
id="image-map" src="../img/map-new.png" usemap="#Map"/><map
name="Map" id="Map"><area
alt="ma" title="" href="" shape="poly" coords="183,693,177,689,166,687,161,682,154,685,145,684,135,686,125,680,124,673,119,675,115,674,112,687,109,692,110,700,181,699" style="outline:none;" target="_self"     /><area
alt="es" title="" href="" shape="poly" coords="125,667,127,660,136,659,145,654,157,654,163,653,171,651,179,654,182,646,197,640,198,631,204,626,205,621,204,620,213,614,203,600,219,576,224,574,225,570,231,565,239,564,253,556,253,544,255,539,247,536,234,537,227,533,219,536,206,534,205,533,193,527,189,528,186,520,182,520,176,520,170,517,165,517,162,519,155,519,152,517,148,517,141,518,133,516,119,515,117,513,108,514,99,514,97,516,89,512,82,513,79,517,78,520,72,521,67,522,63,525,71,534,69,547,78,544,85,547,94,551,100,548,108,556,104,564,101,566,101,579,97,584,98,594,88,596,97,605,96,615,92,618,95,630,89,636,91,645,102,645,104,654,112,666,120,669" style="outline:none;" target="_self"     /><area
alt="pt" title="" href="" shape="poly" coords="69,545,78,545,79,554,87,549,98,548,106,552,107,560,102,567,100,578,96,588,93,595,88,596,96,606,92,617,93,623,93,629,90,637,90,644,82,650,73,646,65,647,68,620,62,621,65,611,58,612,65,593,72,575" style="outline:none;" target="_self"     /><area
alt="fr" title="" href="" shape="poly" coords="255,540,254,525,271,510,278,518,287,518,301,527,308,523,310,516,310,510,319,507,321,503,315,498,312,490,313,480,317,476,311,469,315,465,309,458,303,457,300,463,295,463,297,459,294,460,299,455,300,449,305,444,311,437,308,432,317,430,325,427,319,416,324,409,327,401,319,396,310,396,306,396,303,392,296,389,291,386,287,387,278,383,271,379,268,377,265,372,259,370,254,365,250,360,251,357,246,356,240,358,236,362,233,372,225,379,213,383,211,387,207,394,194,391,188,390,185,386,180,387,182,403,180,408,166,409,159,404,152,404,140,409,136,412,139,421,149,425,160,428,170,433,177,441,181,456,191,470,191,484,189,501,185,513,184,517,191,525,206,531,219,535" style="outline:none;" target="_self"     /><area
alt="mc" title="" href="" shape="poly" coords="309,523,306,514,310,508,320,506,328,507,314,517" style="outline:none;" target="_self"     /><area
alt="gb" title="" href="" shape="poly" coords="120,378,127,371,138,362,144,355,162,354,166,344,154,348,145,342,135,340,129,339,127,333,139,329,145,325,144,316,138,312,140,309,150,302,157,304,159,295,159,285,152,274,158,263,143,266,136,270,126,277,109,288,108,280,99,275,89,281,89,269,98,265,107,260,118,256,122,250,124,237,113,222,107,223,98,214,102,198,106,184,114,183,114,193,117,206,124,209,125,197,129,191,135,184,130,182,134,179,145,177,155,179,143,194,147,202,161,199,175,200,163,225,159,230,152,238,168,241,177,256,186,267,199,277,204,289,210,302,210,313,231,309,235,324,226,335,222,345,233,348,220,360,192,367,163,366,152,377" style="outline:none;" target="_self"     /><area
alt="ie" title="" href="" shape="poly" coords="112,287,100,274,96,282,87,276,96,265,100,258,97,252,83,256,78,264,80,276,73,279,63,276,56,276,57,281,54,290,63,304,72,304,62,316,56,322,47,325,48,334,56,342,69,343,88,338,100,329,111,330,112,318,116,304" style="outline:none;" target="_self"     /><area
alt="be" title="" href="" shape="poly" coords="291,387,283,388,278,380,270,378,266,377,265,370,259,369,254,367,248,361,249,358,248,354,249,350,254,346,267,350,273,348,284,350,291,357,295,367" style="outline:none;" target="_self"     /><area
alt="nl" title="" href="" shape="poly" coords="291,356,293,349,294,341,297,337,304,335,309,331,311,325,307,323,304,318,310,316,314,312,315,307,309,304,302,304,299,301,294,303,284,309,273,316,272,318,266,327,262,335,263,343,260,347,275,346" style="outline:none;" target="_self"     /><area
alt="lu" title="" href="" shape="poly" coords="293,373,288,380,292,389,302,392,301,384,300,380" style="outline:none;" target="_self"     /><area
alt="ch" title="" href="" shape="poly" coords="326,430,334,426,345,427,355,438,364,440,368,450,362,454,360,461,353,458,346,458,346,466,337,460,333,456,329,462,321,464,317,466,314,468,311,463,307,453,303,456,298,462,295,460,297,453,300,446,304,437,308,431,311,428,319,429,332,431" style="outline:none;" target="_self"     /><area
alt="li" title="" href="" shape="poly" coords="356,439,354,435,352,437,354,442" style="outline:none;" target="_self"     /><area
alt="de" title="" href="" shape="poly" coords="324,430,319,421,323,409,328,401,316,396,306,394,301,388,297,378,294,370,294,358,291,353,294,344,297,337,308,334,307,327,308,324,304,320,307,315,312,312,315,308,312,299,311,296,318,295,326,302,329,296,335,289,338,285,335,271,331,266,331,262,340,265,349,267,352,275,365,285,370,278,375,286,385,283,389,278,399,280,415,290,421,299,422,322,427,337,431,347,430,353,419,358,408,359,393,362,379,368,387,375,400,390,413,400,411,413,404,420,406,429,388,428,368,433,354,434,340,426" style="outline:none;" target="_self"     /><area
alt="dk" title="" href="" shape="poly" coords="340,268,334,264,330,264,329,251,322,255,322,251,325,241,323,234,325,228,331,223,331,219,327,214,337,204,346,201,355,197,362,203,355,219,364,234,361,242,354,251,363,256,362,266,348,266" style="outline:none;" target="_self"     /><area
alt="dk1" title="" href="" shape="poly" coords="329,263,342,265,350,266,359,267,382,269,385,259,389,248,388,242,380,241,374,242,364,246,355,243,356,235,367,233,359,227,352,216,356,209,360,202,360,197,353,201,339,204,332,214,322,221,318,233,321,253,329,254" style="outline:none;" target="_self"     /><area
alt="se" title="" href="" shape="poly" coords="396,252,394,246,394,234,387,234,395,224,388,222,382,213,378,199,372,186,369,176,364,165,368,159,372,167,373,154,372,143,375,137,386,138,381,129,380,123,377,111,377,106,383,102,383,93,380,88,377,87,374,83,372,62,374,56,373,47,372,36,373,28,378,25,391,26,394,17,391,12,394,3,395,2,496,1,503,8,495,17,491,26,486,32,481,36,477,43,469,46,464,46,460,53,455,59,450,59,455,69,447,71,449,88,446,104,450,115,457,122,466,129,477,140,473,155,465,167,487,174,489,191,481,206,479,213,475,216,454,210,454,221,451,228,439,235,428,235,418,235,413,246,414,252" style="outline:none;" target="_self"     /><area
alt="no" title="" href="" shape="poly" coords="374,165,375,160,372,146,372,137,379,137,382,130,382,121,376,108,383,103,384,95,380,89,376,83,374,64,373,47,372,34,377,27,384,23,393,22,394,15,391,9,394,0,364,1,357,11,347,17,340,25,339,36,341,44,353,39,347,48,331,45,321,44,317,38,309,45,305,52,303,59,285,67,278,69,273,79,269,83,270,98,273,112,273,128,276,146,280,173,292,182,306,193,336,176,340,163,336,151,350,157,348,165" style="outline:none;" target="_self"     /><area
alt="ck" title="" href="" shape="poly" coords="385,368,395,371,409,364,420,359,435,356,455,363,472,372,489,375,497,384,498,393,484,404,475,406,460,407,448,407,440,399,433,403,425,408,417,408,410,395,397,384,399,390" style="outline:none;" target="_self"     /><area
alt="at" title="" href="" shape="poly" coords="417,406,431,406,437,398,452,403,465,406,468,421,465,433,463,444,461,450,450,452,440,455,434,455,421,456,415,457,405,451,397,447,393,441,386,441,375,440,372,444,367,441,356,439,352,435,357,431,371,431,385,430,396,428,406,428,400,423,408,416" style="outline:none;" target="_self"     /><area
alt="it" title="" href="" shape="poly" coords="313,467,324,464,334,459,335,456,342,463,349,456,363,460,367,454,370,442,376,445,385,445,390,442,395,440,408,450,416,457,414,471,403,474,398,479,397,493,402,503,415,509,426,525,434,539,451,547,464,552,461,556,475,563,489,572,503,582,500,593,492,581,476,579,474,591,472,597,480,609,475,621,464,635,450,642,452,657,439,656,412,641,405,638,414,630,434,631,452,626,461,623,465,611,467,602,456,588,449,584,444,575,431,574,421,561,416,565,406,561,399,553,357,610,349,610,342,613,339,604,342,593,339,583,339,575,334,574,335,565,343,567,348,564,356,569,358,590,393,546,389,537,382,533,374,522,371,512,368,510,354,502,345,499,331,502,324,512,310,521,324,510,324,502,321,491,319,480" style="outline:none;" target="_self"     /><area
alt="si" title="" href="" shape="poly" coords="418,477,421,470,417,465,421,457,430,457,444,453,459,450,460,447,467,452,463,461,447,469,443,471,437,476,425,478" style="outline:none;" target="_self"     /><area
alt="hr" title="" href="" shape="poly" coords="485,527,475,513,460,499,453,485,453,476,463,480,474,480,494,479,505,484,506,479,501,472,499,470,494,469,484,467,475,459,467,463,454,461,445,466,438,472,435,477,426,476,418,477,423,493,427,486,447,505,460,518,474,529" style="outline:none;" target="_self"     /><area
alt="ba" title="" href="" shape="poly" coords="486,532,482,521,474,512,463,501,454,489,452,486,453,480,460,482,469,482,483,481,497,482,509,487,507,499,515,504,509,509,505,516,506,530,503,532,497,534" style="outline:none;" target="_self"     /><area
alt="me" title="" href="" shape="poly" coords="511,551,506,543,497,535,503,525,506,523,507,518,504,515,512,513,517,521,526,526,525,537,516,539" style="outline:none;" target="_self"     /><area
alt="al" title="" href="" shape="poly" coords="530,595,525,594,523,589,520,586,515,584,515,578,517,565,517,557,516,556,515,548,513,548,516,540,523,535,533,541,537,550,539,570,545,579,534,587" style="outline:none;" target="_self"     /><area
alt="mk" title="" href="" shape="poly" coords="544,574,539,568,537,559,537,547,548,544,564,540,575,552,577,561,558,563" style="outline:none;" target="_self"     /><area
alt="gr" title="" href="" shape="poly" coords="560,652,571,661,578,670,593,683,603,687,614,689,632,689,636,685,643,683,653,678,665,666,666,662,655,664,641,663,635,659,636,656,637,653,639,643,642,636,629,630,627,622,627,617,632,613,634,607,632,602,626,604,623,604,622,599,618,592,613,586,612,582,617,575,620,572,626,567,629,564,629,558,633,554,629,550,626,549,620,559,607,560,591,561,588,561,581,561,571,561,558,566,544,571,539,586,534,588,530,593,527,599,518,599,532,624,544,639" style="outline:none;" target="_self"     /><area
alt="bg" title="" href="" shape="poly" coords="651,546,648,536,648,526,654,520,653,519,660,513,656,509,653,505,643,505,636,500,620,501,612,506,595,509,578,510,568,507,562,502,561,505,564,513,564,524,570,522,568,531,563,538,572,547,577,560,588,561,605,559,624,560,631,547,640,544" style="outline:none;" target="_self"     /><area
alt="rs" title="" href="" shape="poly" coords="536,554,537,548,546,544,559,541,566,540,565,531,562,528,570,522,565,518,563,510,564,495,564,490,554,489,548,487,539,477,530,467,521,460,511,464,504,465,503,476,509,488,504,497,513,503,510,509,522,524,530,525,528,535,535,544" style="outline:none;" target="_self"     /><area
alt="hu" title="" href="" shape="poly" coords="525,463,526,460,531,455,538,454,542,444,549,431,553,426,560,422,557,416,551,408,551,400,546,407,537,410,528,409,519,411,518,415,517,420,511,418,508,414,498,422,488,423,476,428,467,428,460,433,462,444,466,454,474,464,495,470,506,464,516,460" style="outline:none;" target="_self"     /><area
alt="sk" title="" href="" shape="poly" coords="510,414,515,421,519,413,526,409,537,408,549,409,550,400,553,396,542,393,532,391,520,391,511,392,501,396,493,400,483,407,471,405,465,405,467,420,477,427,490,426,502,423" style="outline:none;" target="_self"     /><area
alt="tn" title="" href="" shape="poly" coords="374,700,385,692,385,684,385,675,379,674,375,670,375,663,381,661,383,654,381,649,374,653,369,652,363,644,350,648,338,652,346,662,344,674,343,686,341,698" style="outline:none;" target="_self"     /><area
alt="tr" title="" href="" shape="poly" coords="795,669,802,666,804,656,805,649,822,652,836,650,835,561,825,565,813,565,794,560,785,556,783,546,774,549,768,548,760,542,745,544,728,547,717,550,709,556,706,561,697,563,679,562,670,562,663,562,656,555,652,549,645,546,639,543,629,548,626,558,626,567,632,574,630,584,628,597,640,597,638,608,635,620,636,626,643,633,650,647,662,650,658,656,684,662,693,666,705,660,706,650,726,653,730,665,763,663,772,650,786,656,796,650,791,662" style="outline:none;" target="_self"     /><area
alt="sy" title="" href="" shape="poly" coords="837,650,816,653,806,653,800,662,794,672,792,669,793,689,800,696,807,699,836,699" style="outline:none;" target="_self"     /><area
alt="ro" title="" href="" shape="poly" coords="565,499,570,511,578,507,601,508,618,507,632,501,647,503,658,507,660,496,658,490,666,486,673,481,670,472,660,476,650,472,646,464,646,445,639,435,632,424,624,416,622,416,614,416,603,422,589,424,578,422,571,418,557,416,552,425,546,435,537,447,533,459,524,462,540,477,545,486,542,485,560,489,552,490,562,485" style="outline:none;" target="_self"     /><area
alt="pl" title="" href="" shape="poly" coords="551,395,557,392,558,384,561,376,570,368,572,360,573,351,567,340,562,337,559,321,561,313,567,307,564,299,560,285,558,278,552,273,548,271,539,270,532,269,515,269,503,271,493,278,486,276,478,269,484,266,472,262,462,264,446,271,432,284,420,289,418,298,420,310,422,320,423,338,434,347,432,353,442,356,453,362,461,366,474,373,490,381,506,388,513,396,527,388,546,392" style="outline:none;" target="_self"     /><area
alt="ru" title="" href="" shape="poly" coords="525,248,537,254,546,258,545,269,526,272,511,273,506,268,504,262,506,256,521,256" style="outline:none;" target="_self"     /><area
alt="md" title="" href="" shape="poly" coords="676,450,663,454,657,460,650,467,645,467,647,452,644,441,637,432,628,424,622,416,617,410,620,404,632,406,646,410,657,416,664,433,674,438" style="outline:none;" target="_self"     /><area
alt="ua" title="" href="" shape="poly" coords="567,335,583,332,598,331,606,330,628,336,644,336,658,336,665,336,671,333,677,325,684,321,696,323,696,318,713,318,723,319,727,332,741,340,747,345,752,357,761,360,779,359,782,356,788,366,805,372,815,373,826,375,826,386,820,388,827,403,822,414,813,417,806,424,810,432,794,434,809,433,805,445,802,444,799,451,795,462,789,470,785,476,768,482,759,487,735,493,718,475,728,454,718,457,702,447,689,446,683,455,677,465,673,472,660,476,653,473,651,468,656,463,660,457,667,451,675,449,677,436,661,427,664,417,657,417,652,412,636,408,629,403,619,406,618,415,606,419,586,424,572,420,563,416,555,413,548,405,551,397,556,390,556,382,564,378,572,365,576,358,574,351,566,346" style="outline:none;" target="_self"     /><area
alt="by" title="" href="" shape="poly" coords="651,340,642,337,630,336,615,336,607,333,594,329,582,334,571,333,568,328,561,317,567,310,565,296,561,287,563,283,574,280,583,277,593,273,591,269,593,259,597,250,603,246,609,242,616,237,625,230,642,234,653,237,658,238,667,243,669,258,677,269,685,276,696,289,696,298,688,301,682,300,682,313,688,320,681,325,673,335,668,338,657,337" style="outline:none;" target="_self"     /><area
alt="lt" title="" href="" shape="poly" coords="558,285,557,275,553,272,545,270,547,266,547,260,541,255,532,254,526,250,524,246,519,246,519,236,522,233,531,227,551,223,561,229,572,229,588,231,599,238,599,243,595,256,591,262,593,271,584,275,578,283,564,282" style="outline:none;" target="_self"     /><area
alt="lv" title="" href="" shape="poly" coords="623,232,619,224,617,214,614,204,613,198,603,199,598,200,588,194,583,188,575,186,566,187,559,195,560,205,549,212,546,207,546,201,539,192,530,194,520,205,513,213,516,230,522,231,529,227,537,224,556,226,555,230,569,230,578,229,590,233,597,242,609,241" style="outline:none;" target="_self"     /><area
alt="ee" title="" href="" shape="poly" coords="610,199,611,190,613,183,608,169,608,158,610,150,612,145,596,145,587,145,578,143,572,143,563,148,552,149,543,153,540,158,535,159,525,166,519,180,523,189,535,185,547,177,559,183,561,178,565,188,579,184,591,190,601,201" style="outline:none;" target="_self"     /><area
alt="fi" title="" href="" shape="poly" coords="614,115,613,104,625,99,638,81,643,63,647,50,642,40,635,35,631,28,629,14,624,2,622,0,541,0,531,14,523,26,516,36,511,45,500,42,500,53,503,66,506,83,509,102,507,110,508,121,526,125,535,132,542,134,560,130,583,118,601,121" style="outline:none;" target="_self"     /><area
alt="ru" title="" href="" shape="poly" coords="624,2,632,14,629,24,631,31,642,41,644,53,642,71,633,83,623,102,613,112,619,120,636,125,638,135,616,134,613,144,609,162,610,177,612,196,617,215,622,227,633,234,653,235,663,240,670,251,674,261,680,272,689,282,701,293,694,299,690,302,683,300,683,313,690,324,699,319,703,318,718,317,726,319,729,330,738,338,749,344,754,352,760,361,778,360,785,359,802,369,822,374,831,380,826,387,822,392,827,405,823,414,812,421,808,429,820,432,809,441,803,445,801,457,809,451,802,463,800,470,790,473,795,481,802,485,813,486,827,498,837,509,837,0" style="outline:none;" target="_self"     /><area
alt="ml" title="" href="" shape="poly" coords="438, 672, 445, 672, 444, 679, 437, 679" style="outline:none;" target="_self"/></map>
<?php iv('list')?></div>
<?php //v('block');?>
<script type="text/javascript" src="/4c1143b72dfd84b121eed9073e45cfbc.js"></script>
</body></html><!-- This site is working under SamsonPHP framework http://samsonphp.com  -->
EOT;
$GLOBALS["__compressor_files"]["app/view/popup.php"] = <<<'EOT'
<div
id="<?php v('iso');?>" class="popup">
<img
src="../img/crop/<?php v('iso');?>.png" id="map-<?php v('iso');?>" class="popup-img" usemap="#"><div
class="content"><h1><?php v('mat_Name');?></h1>
<?php if(isval('mat_Provision')):?>
<span
class="title">Applicable legal provisions:</span>
<span
class="text"><?php iv('mat_Provision');?></span>
<?php endif;?>
<?php if(isval('mat_Exception')):?>
<span
class="title">Exceptions:</span>
<span
class="text"><?php iv('mat_Exception');?></span>
<?php endif;?>
<?php if(isval('mat_Case')):?>
<span
class="title">Special cases:</span>
<span
class="text"><?php iv('mat_Case');?></span>
<?php endif;?></div><div
class="popup-close"></div></div>
<img
src="../img/country/<?php v('iso');?>.png" id="hover-<?php v('iso');?>" class="hover-img" usemap="#">
EOT;
$GLOBALS["__compressor_files"]["app/view/preload/block.php"] = <<<'EOT'

EOT;
$GLOBALS["__compressor_files"]["app/view/preload/style.php"] = <<<'EOT'
#preload-<?php v('iso');?> { background: url("../img/map/<?php v('iso');?>.jpg") no-repeat -9999px -9999px; }
EOT;
\samson\core\Error::$OUTPUT = false; $GLOBALS["__CORE_SNAPSHOT"] = 'TzoxNjoic2Ftc29uXGNvcmVcQ29yZSI6Mzp7czoxMjoibW9kdWxlX3N0YWNrIjthOjc6e3M6NDoiY29yZSI7TzoxODoic2Ftc29uXGNvcmVcU3lzdGVtIjoxMjp7czo1OiIAKgBpZCI7czo0OiJjb3JlIjtzOjY6InBhcmVudCI7TjtzOjY6IgAqAHZpZCI7czo0OiJjb3JlIjtzOjE1OiIAKgByZXF1aXJlbWVudHMiO2E6MDp7fXM6MzoidWlkIjtzOjIzOiIzODExNDg5XzE0MTYyMjE0MTkuODU2NyI7czoxNDoiACoAY29udHJvbGxlcnMiO2E6MDp7fXM6ODoiACoAdmlld3MiO2E6MDp7fXM6NzoiACoAcGF0aCI7czo1OiJjb3JlLyI7czoxMDoiACoAdmVyc2lvbiI7czo1OiIwLjAuMSI7czo3OiIAKgBkYXRhIjthOjM6e3M6ODoiX19odG1sX18iO3M6MDoiIjtzOjI6ImlkIjtzOjQ6ImNvcmUiO3M6MDoiIjthOjA6e319czoxNToiACoAdmlld19jb250ZXh0IjtzOjA6IiI7czoxMzoiACoAY2FjaGVfcGF0aCI7czo0MjoiL3Zhci93d3cua290ZW5rby9rYXJ0YS5kZXYvd3d3L2NhY2hlL2NvcmUvIjt9czoxMjoiYWN0aXZlcmVjb3JkIjtPOjQxOiJzYW1zb25cYWN0aXZlcmVjb3JkXEFjdGl2ZVJlY29yZENvbm5lY3RvciI6MTk6e3M6NToiACoAaWQiO3M6MTI6ImFjdGl2ZXJlY29yZCI7czo2OiJwcmVmaXgiO047czo0OiJuYW1lIjtzOjEwOiJwb250dXNfbWFwIjtzOjU6ImxvZ2luIjtzOjEwOiJwb250dXNfbWFwIjtzOjM6InB3ZCI7czo4OiJyNDIzODZnaiI7czo0OiJob3N0IjtzOjI3OiJwb250dXMubXlzcWwudWtyYWluZS5jb20udWEiO3M6NDoicG9ydCI7czowOiIiO3M6OToicmVsYXRpb25zIjthOjA6e31zOjY6InBhcmVudCI7TjtzOjY6IgAqAHZpZCI7czoxMjoiYWN0aXZlcmVjb3JkIjtzOjE1OiIAKgByZXF1aXJlbWVudHMiO2E6MDp7fXM6MzoidWlkIjtzOjIzOiIyMzQyNDUyXzE0MTYyMjE0MTkuODY5MiI7czoxNDoiACoAY29udHJvbGxlcnMiO2E6MDp7fXM6ODoiACoAdmlld3MiO2E6MDp7fXM6NzoiACoAcGF0aCI7czoxMzoiYWN0aXZlcmVjb3JkLyI7czoxMDoiACoAdmVyc2lvbiI7czo1OiIwLjAuMSI7czo3OiIAKgBkYXRhIjthOjM6e3M6ODoiX19odG1sX18iO3M6MDoiIjtzOjI6ImlkIjtzOjEyOiJhY3RpdmVyZWNvcmQiO3M6MDoiIjthOjA6e319czoxNToiACoAdmlld19jb250ZXh0IjtzOjA6IiI7czoxMzoiACoAY2FjaGVfcGF0aCI7czo1MDoiL3Zhci93d3cua290ZW5rby9rYXJ0YS5kZXYvd3d3L2NhY2hlL2FjdGl2ZXJlY29yZC8iO31zOjg6InNhbXNvbmpzIjtPOjMyOiJzYW1zb25canNcY29yZVxTYW1zb25KU0Nvbm5lY3RvciI6MTI6e3M6NToiACoAaWQiO3M6ODoic2Ftc29uanMiO3M6MTU6IgAqAHJlcXVpcmVtZW50cyI7YToxOntpOjA7czo0OiJjb3JlIjt9czo2OiJwYXJlbnQiO047czo2OiIAKgB2aWQiO3M6ODoic2Ftc29uanMiO3M6MzoidWlkIjtzOjIyOiIxMDg4MzBfMTQxNjIyMTQxOS44OTA4IjtzOjE0OiIAKgBjb250cm9sbGVycyI7YTowOnt9czo4OiIAKgB2aWV3cyI7YTowOnt9czo3OiIAKgBwYXRoIjtzOjk6InNhbXNvbmpzLyI7czoxMDoiACoAdmVyc2lvbiI7czo1OiIwLjAuMSI7czo3OiIAKgBkYXRhIjthOjM6e3M6ODoiX19odG1sX18iO3M6MDoiIjtzOjI6ImlkIjtzOjg6InNhbXNvbmpzIjtzOjA6IiI7YTowOnt9fXM6MTU6IgAqAHZpZXdfY29udGV4dCI7czowOiIiO3M6MTM6IgAqAGNhY2hlX3BhdGgiO3M6NDY6Ii92YXIvd3d3LmtvdGVua28va2FydGEuZGV2L3d3dy9jYWNoZS9zYW1zb25qcy8iO31zOjY6ImNtc2FwaSI7TzoxNDoic2Ftc29uXGNtc1xDTVMiOjE0OntzOjU6IgAqAGlkIjtzOjY6ImNtc2FwaSI7czoxNToibWF0ZXJpYWxfZmllbGRzIjthOjc6e2k6MTtPOjI1OiJzYW1zb25cYWN0aXZlcmVjb3JkXGZpZWxkIjoxODp7czo3OiJGaWVsZElEIjtzOjE6IjEiO3M6ODoiUGFyZW50SUQiO3M6MToiMCI7czo0OiJOYW1lIjtzOjc6IkNvbnRlbnQiO3M6NDoiVHlwZSI7czoxOiI4IjtzOjU6ImxvY2FsIjtzOjE6IjAiO3M6ODoiZmlsdGVyZWQiO3M6MToiMCI7czo1OiJWYWx1ZSI7czowOiIiO3M6MTE6IkRlc2NyaXB0aW9uIjtzOjA6IiI7czo2OiJVc2VySUQiO3M6MToiMCI7czo3OiJDcmVhdGVkIjtzOjE5OiIwMDAwLTAwLTAwIDAwOjAwOjAwIjtzOjg6Ik1vZHlmaWVkIjtzOjE5OiIyMDE0LTExLTEyIDEyOjM0OjA2IjtzOjY6IkFjdGl2ZSI7czoxOiIxIjtzOjY6InN5c3RlbSI7czoxOiIxIjtzOjI6ImlkIjtzOjE6IjEiO3M6MTA6ImNsYXNzX25hbWUiO3M6MjU6InNhbXNvblxhY3RpdmVyZWNvcmRcZmllbGQiO3M6ODoib25ldG9vbmUiO2E6MDp7fXM6OToib25ldG9tYW55IjthOjA6e31zOjg6ImF0dGFjaGVkIjtiOjE7fWk6MjtPOjI1OiJzYW1zb25cYWN0aXZlcmVjb3JkXGZpZWxkIjoxODp7czo3OiJGaWVsZElEIjtzOjE6IjIiO3M6ODoiUGFyZW50SUQiO3M6MToiMCI7czo0OiJOYW1lIjtzOjk6IlByb3Zpc2lvbiI7czo0OiJUeXBlIjtzOjE6IjAiO3M6NToibG9jYWwiO3M6MToiMCI7czo4OiJmaWx0ZXJlZCI7czoxOiIwIjtzOjU6IlZhbHVlIjtzOjA6IiI7czoxMToiRGVzY3JpcHRpb24iO3M6Mjc6IkFwcGxpY2FibGUgbGVnYWwgcHJvdmlzaW9ucyI7czo2OiJVc2VySUQiO3M6MToiMSI7czo3OiJDcmVhdGVkIjtzOjE5OiIyMDE0LTA1LTIyIDAwOjAwOjAwIjtzOjg6Ik1vZHlmaWVkIjtzOjE5OiIyMDE0LTA1LTIyIDE1OjEyOjE5IjtzOjY6IkFjdGl2ZSI7czoxOiIxIjtzOjY6InN5c3RlbSI7czoxOiIwIjtzOjI6ImlkIjtzOjE6IjIiO3M6MTA6ImNsYXNzX25hbWUiO3M6MjU6InNhbXNvblxhY3RpdmVyZWNvcmRcZmllbGQiO3M6ODoib25ldG9vbmUiO2E6MDp7fXM6OToib25ldG9tYW55IjthOjA6e31zOjg6ImF0dGFjaGVkIjtiOjE7fWk6MztPOjI1OiJzYW1zb25cYWN0aXZlcmVjb3JkXGZpZWxkIjoxODp7czo3OiJGaWVsZElEIjtzOjE6IjMiO3M6ODoiUGFyZW50SUQiO3M6MToiMCI7czo0OiJOYW1lIjtzOjk6IkV4Y2VwdGlvbiI7czo0OiJUeXBlIjtzOjE6IjAiO3M6NToibG9jYWwiO3M6MToiMCI7czo4OiJmaWx0ZXJlZCI7czoxOiIwIjtzOjU6IlZhbHVlIjtzOjA6IiI7czoxMToiRGVzY3JpcHRpb24iO3M6MTA6IkV4Y2VwdGlvbnMiO3M6NjoiVXNlcklEIjtzOjE6IjEiO3M6NzoiQ3JlYXRlZCI7czoxOToiMjAxNC0wNS0yMiAwMDowMDowMCI7czo4OiJNb2R5ZmllZCI7czoxOToiMjAxNC0wNS0yMiAxNToxMjo1NyI7czo2OiJBY3RpdmUiO3M6MToiMSI7czo2OiJzeXN0ZW0iO3M6MToiMCI7czoyOiJpZCI7czoxOiIzIjtzOjEwOiJjbGFzc19uYW1lIjtzOjI1OiJzYW1zb25cYWN0aXZlcmVjb3JkXGZpZWxkIjtzOjg6Im9uZXRvb25lIjthOjA6e31zOjk6Im9uZXRvbWFueSI7YTowOnt9czo4OiJhdHRhY2hlZCI7YjoxO31pOjQ7TzoyNToic2Ftc29uXGFjdGl2ZXJlY29yZFxmaWVsZCI6MTg6e3M6NzoiRmllbGRJRCI7czoxOiI0IjtzOjg6IlBhcmVudElEIjtzOjE6IjAiO3M6NDoiTmFtZSI7czo0OiJDYXNlIjtzOjQ6IlR5cGUiO3M6MToiMCI7czo1OiJsb2NhbCI7czoxOiIwIjtzOjg6ImZpbHRlcmVkIjtzOjE6IjAiO3M6NToiVmFsdWUiO3M6MDoiIjtzOjExOiJEZXNjcmlwdGlvbiI7czoxMzoiU3BlY2lhbCBjYXNlcyI7czo2OiJVc2VySUQiO3M6MToiMSI7czo3OiJDcmVhdGVkIjtzOjE5OiIyMDE0LTA1LTIyIDAwOjAwOjAwIjtzOjg6Ik1vZHlmaWVkIjtzOjE5OiIyMDE0LTA1LTIyIDE1OjEzOjM4IjtzOjY6IkFjdGl2ZSI7czoxOiIxIjtzOjY6InN5c3RlbSI7czoxOiIwIjtzOjI6ImlkIjtzOjE6IjQiO3M6MTA6ImNsYXNzX25hbWUiO3M6MjU6InNhbXNvblxhY3RpdmVyZWNvcmRcZmllbGQiO3M6ODoib25ldG9vbmUiO2E6MDp7fXM6OToib25ldG9tYW55IjthOjA6e31zOjg6ImF0dGFjaGVkIjtiOjE7fWk6NTtPOjI1OiJzYW1zb25cYWN0aXZlcmVjb3JkXGZpZWxkIjoxODp7czo3OiJGaWVsZElEIjtzOjE6IjUiO3M6ODoiUGFyZW50SUQiO3M6MToiMCI7czo0OiJOYW1lIjtzOjExOiJEZXNjcmlwdGlvbiI7czo0OiJUeXBlIjtzOjE6IjgiO3M6NToibG9jYWwiO3M6MToiMCI7czo4OiJmaWx0ZXJlZCI7czoxOiIwIjtzOjU6IlZhbHVlIjtzOjA6IiI7czoxMToiRGVzY3JpcHRpb24iO3M6MDoiIjtzOjY6IlVzZXJJRCI7czoxOiIwIjtzOjc6IkNyZWF0ZWQiO3M6MTk6IjAwMDAtMDAtMDAgMDA6MDA6MDAiO3M6ODoiTW9keWZpZWQiO3M6MTk6IjIwMTQtMTEtMTIgMTI6MzQ6MDYiO3M6NjoiQWN0aXZlIjtzOjE6IjEiO3M6Njoic3lzdGVtIjtzOjE6IjEiO3M6MjoiaWQiO3M6MToiNSI7czoxMDoiY2xhc3NfbmFtZSI7czoyNToic2Ftc29uXGFjdGl2ZXJlY29yZFxmaWVsZCI7czo4OiJvbmV0b29uZSI7YTowOnt9czo5OiJvbmV0b21hbnkiO2E6MDp7fXM6ODoiYXR0YWNoZWQiO2I6MTt9aTo2O086MjU6InNhbXNvblxhY3RpdmVyZWNvcmRcZmllbGQiOjE4OntzOjc6IkZpZWxkSUQiO3M6MToiNiI7czo4OiJQYXJlbnRJRCI7czoxOiIwIjtzOjQ6Ik5hbWUiO3M6ODoiS2V5d29yZHMiO3M6NDoiVHlwZSI7czoxOiI4IjtzOjU6ImxvY2FsIjtzOjE6IjAiO3M6ODoiZmlsdGVyZWQiO3M6MToiMCI7czo1OiJWYWx1ZSI7czowOiIiO3M6MTE6IkRlc2NyaXB0aW9uIjtzOjA6IiI7czo2OiJVc2VySUQiO3M6MToiMCI7czo3OiJDcmVhdGVkIjtzOjE5OiIwMDAwLTAwLTAwIDAwOjAwOjAwIjtzOjg6Ik1vZHlmaWVkIjtzOjE5OiIyMDE0LTExLTEyIDEyOjM0OjA4IjtzOjY6IkFjdGl2ZSI7czoxOiIxIjtzOjY6InN5c3RlbSI7czoxOiIxIjtzOjI6ImlkIjtzOjE6IjYiO3M6MTA6ImNsYXNzX25hbWUiO3M6MjU6InNhbXNvblxhY3RpdmVyZWNvcmRcZmllbGQiO3M6ODoib25ldG9vbmUiO2E6MDp7fXM6OToib25ldG9tYW55IjthOjA6e31zOjg6ImF0dGFjaGVkIjtiOjE7fWk6NztPOjI1OiJzYW1zb25cYWN0aXZlcmVjb3JkXGZpZWxkIjoxODp7czo3OiJGaWVsZElEIjtzOjE6IjciO3M6ODoiUGFyZW50SUQiO3M6MToiMCI7czo0OiJOYW1lIjtzOjU6IlRpdGxlIjtzOjQ6IlR5cGUiO3M6MToiOCI7czo1OiJsb2NhbCI7czoxOiIwIjtzOjg6ImZpbHRlcmVkIjtzOjE6IjAiO3M6NToiVmFsdWUiO3M6MDoiIjtzOjExOiJEZXNjcmlwdGlvbiI7czowOiIiO3M6NjoiVXNlcklEIjtzOjE6IjAiO3M6NzoiQ3JlYXRlZCI7czoxOToiMDAwMC0wMC0wMCAwMDowMDowMCI7czo4OiJNb2R5ZmllZCI7czoxOToiMjAxNC0xMS0xMiAxMjozNDoxMCI7czo2OiJBY3RpdmUiO3M6MToiMSI7czo2OiJzeXN0ZW0iO3M6MToiMSI7czoyOiJpZCI7czoxOiI3IjtzOjEwOiJjbGFzc19uYW1lIjtzOjI1OiJzYW1zb25cYWN0aXZlcmVjb3JkXGZpZWxkIjtzOjg6Im9uZXRvb25lIjthOjA6e31zOjk6Im9uZXRvbWFueSI7YTowOnt9czo4OiJhdHRhY2hlZCI7YjoxO319czoxODoiZ2F0aGVyQW5jZXN0b3JEYXRhIjtiOjE7czo2OiJwYXJlbnQiO047czo2OiIAKgB2aWQiO3M6NjoiY21zYXBpIjtzOjE1OiIAKgByZXF1aXJlbWVudHMiO2E6MDp7fXM6MzoidWlkIjtzOjIzOiI1MDU4MDM1XzE0MTYyMjE0MTkuOTAwMiI7czoxNDoiACoAY29udHJvbGxlcnMiO2E6MDp7fXM6ODoiACoAdmlld3MiO2E6MDp7fXM6NzoiACoAcGF0aCI7czo3OiJjbXNhcGkvIjtzOjEwOiIAKgB2ZXJzaW9uIjtzOjU6IjAuMC4xIjtzOjc6IgAqAGRhdGEiO2E6Mjp7czo4OiJfX2h0bWxfXyI7czowOiIiO3M6MjoiaWQiO3M6NjoiY21zYXBpIjt9czoxNToiACoAdmlld19jb250ZXh0IjtzOjA6IiI7czoxMzoiACoAY2FjaGVfcGF0aCI7czo0NDoiL3Zhci93d3cua290ZW5rby9rYXJ0YS5kZXYvd3d3L2NhY2hlL2Ntc2FwaS8iO31zOjU6ImxvY2FsIjtPOjM1OiJzYW1zb25cY29yZVxDb21wcmVzc2FibGVMb2NhbE1vZHVsZSI6Njp7czo1OiIAKgBpZCI7czo1OiJsb2NhbCI7czo3OiIAKgBwYXRoIjtzOjA6IiI7czoxMDoiACoAdmVyc2lvbiI7czo1OiIwLjAuMSI7czo3OiIAKgBkYXRhIjthOjI6e3M6ODoiX19odG1sX18iO3M6MDoiIjtzOjI6ImlkIjtzOjU6ImxvY2FsIjt9czoxNDoiACoAY29udHJvbGxlcnMiO2E6MDp7fXM6ODoiACoAdmlld3MiO2E6NDp7aTowO3M6MTg6ImFwcC92aWV3L2luZGV4LnBocCI7aToxO3M6MTg6ImFwcC92aWV3L3BvcHVwLnBocCI7aToyO3M6MjY6ImFwcC92aWV3L3ByZWxvYWQvYmxvY2sucGhwIjtpOjM7czoyNjoiYXBwL3ZpZXcvcHJlbG9hZC9zdHlsZS5waHAiO319czo2OiJjcmVhdGUiO086MzU6InNhbXNvblxjb3JlXENvbXByZXNzYWJsZUxvY2FsTW9kdWxlIjo2OntzOjU6IgAqAGlkIjtzOjY6ImNyZWF0ZSI7czo3OiIAKgBwYXRoIjtzOjA6IiI7czoxMDoiACoAdmVyc2lvbiI7czo1OiIwLjAuMSI7czo3OiIAKgBkYXRhIjthOjI6e3M6ODoiX19odG1sX18iO3M6MDoiIjtzOjI6ImlkIjtzOjY6ImNyZWF0ZSI7fXM6MTQ6IgAqAGNvbnRyb2xsZXJzIjthOjE6e3M6NjoiX19iYXNlIjtzOjY6ImNyZWF0ZSI7fXM6ODoiACoAdmlld3MiO2E6NDp7aTowO3M6MTg6ImFwcC92aWV3L2luZGV4LnBocCI7aToxO3M6MTg6ImFwcC92aWV3L3BvcHVwLnBocCI7aToyO3M6MjY6ImFwcC92aWV3L3ByZWxvYWQvYmxvY2sucGhwIjtpOjM7czoyNjoiYXBwL3ZpZXcvcHJlbG9hZC9zdHlsZS5waHAiO319czo0OiJtYWluIjtPOjM1OiJzYW1zb25cY29yZVxDb21wcmVzc2FibGVMb2NhbE1vZHVsZSI6Njp7czo1OiIAKgBpZCI7czo0OiJtYWluIjtzOjc6IgAqAHBhdGgiO3M6MDoiIjtzOjEwOiIAKgB2ZXJzaW9uIjtzOjU6IjAuMC4xIjtzOjc6IgAqAGRhdGEiO2E6Mjp7czo4OiJfX2h0bWxfXyI7czowOiIiO3M6MjoiaWQiO3M6NDoibWFpbiI7fXM6MTQ6IgAqAGNvbnRyb2xsZXJzIjthOjE6e3M6NjoiX19iYXNlIjtzOjQ6Im1haW4iO31zOjg6IgAqAHZpZXdzIjthOjQ6e2k6MDtzOjE4OiJhcHAvdmlldy9pbmRleC5waHAiO2k6MTtzOjE4OiJhcHAvdmlldy9wb3B1cC5waHAiO2k6MjtzOjI2OiJhcHAvdmlldy9wcmVsb2FkL2Jsb2NrLnBocCI7aTozO3M6MjY6ImFwcC92aWV3L3ByZWxvYWQvc3R5bGUucGhwIjt9fX1zOjExOiJyZW5kZXJfbW9kZSI7aTozO3M6MTI6IgAqAHZpZXdfcGF0aCI7czowOiIiO30='; setlocales( ); url(); s()->start('main'); } ?>
