public function __construct() { $this->_configMain = Registry::get('main', 'config'); $this->_lang = Lang::lang(); $this->_db = Application::getDbConnection(); $this->_config = Config::factory(Config::File_Array, $this->_configMain['configs'] . 'designer.php'); $this->_session = Store_Session::getInstance('Designer'); $this->_storage = Designer_Storage::getInstance($this->_config->get('storage'), $this->_config); }
/** * Create new report */ public function fsmakefileAction() { $name = Request::post('name', 'string', ''); $path = Request::post('path', 'string', ''); if (!strlen($name)) { Response::jsonError($this->_lang->WRONG_REQUEST . ' [code 1]'); } $configsPath = $this->_config->get('configs'); $actionsPath = $this->_config->get('actionjs_path'); if (strlen($path)) { $savePath = $path . DIRECTORY_SEPARATOR . $name . '.designer.dat'; $actionFilePath = $actionsPath . str_replace($configsPath, '', $path) . DIRECTORY_SEPARATOR . $name . '.js'; } else { $savePath = $configsPath . $name . '.designer.dat'; $actionFilePath = $actionsPath . $name . '.js'; } if (file_exists($savePath)) { Response::jsonError($this->_lang->FILE_EXISTS); } $obj = new Designer_Project(); $obj->actionjs = $actionFilePath; if ($this->_storage->save($savePath, $obj)) { Response::jsonSuccess(array('file' => $savePath)); } else { Response::jsonError($this->_lang->CANT_WRITE_FS . ' ' . $savePath); } }
/** * Get object fields translation * @param boolean $autoCreate , otional default - true * @return Config_Abstract | boolean false */ public function getTranslation($autoCreate = true) { if ($this->_translation) { return $this->_translation; } if (!file_exists($this->_mainConfig)) { if (!$autoCreate) { return false; } //create translation config if (!Config_File_Array::create($this->_mainConfig)) { return false; } } $this->_translation = Config::factory(Config::File_Array, $this->_mainConfig); if (!empty($this->_extTranslations)) { foreach ($this->_extTranslations as $path) { $extCfg = Config::factory(Config::File_Array, $path); foreach ($extCfg as $k => $v) { if (!$this->_translation->offsetExists($k)) { $this->_translation->set($k, $v); } } } } return $this->_translation; }
/** * Create dictionary * @param string $name * @return boolean */ public function create($name) { if (!file_exists($this->_path . $name . '.php') && Config_File_Array::create($this->_path . $name . '.php')) { self::$_validDictionary[$name] = true; $this->resetCache(); return true; } return false; }
/** * Scan files and create class map for autoloader * @param array $startPaths - paths for scan (relative paths) * @param string $mapFile - output php file path * @param string $mapPackagesFile - output php file path (with packages) * @param Config_File_Array - $packagesConfig * @return boolean */ public static function createClassMap(array $startPaths, $mapFile, $mapPackagesFile, Config_File_Array $packagesConfig) { $packages = $packagesConfig->get('packages'); $packPath = $packagesConfig->get('path'); $packMap = array(); if (!empty($packages)) { foreach ($packages as $key => $items) { if (!empty($items)) { foreach ($items['paths'] as $index => $path) { $packMap[$path] = $key; } } } } $map = array(); $mapPackaged = array(); foreach ($startPaths as $v) { self::_scanClassDir($v, $map, $mapPackaged, $v, $packMap, $packagesConfig); } ksort($map); ksort($packMap); $res1 = @file_put_contents($mapFile, '<?php return ' . var_export($map, true) . '; '); $vars = ''; $varNames = array(); $varValues = array(); foreach ($packagesConfig->get('packages') as $key => $item) { if (!$item['active']) { continue; } $varName = '$_pkg_' . $key; $packPath = $packagesConfig->get('path') . $key . '.php'; $vars .= $varName . " ='" . $packPath . "';\n"; $varNames[] = $varName; $varValues[] = "'" . $packPath . "'"; } $s = str_replace($varValues, $varNames, var_export($mapPackaged, true)) . ';'; $res2 = @file_put_contents($mapPackagesFile, '<?php ' . "\n" . $vars . ' return ' . $s); if ($res1 && $res2) { return true; } else { return false; } }
/** * Compilation of Layout Designer code * System method used by platform developers */ public function compileAction() { if (!$this->_config->get('development')) { die('Use development mode'); } $s = ''; $totalSize = 0; foreach (self::$_scripts as $filePath) { $s .= file_get_contents('.' . $filePath) . "\n"; $totalSize += filesize('.' . $filePath); } $time = microtime(true); file_put_contents('.' . $this->_config->get('compiled_js'), Code_Js_Minify::minify($s)); echo ' Compilation time: ' . number_format(microtime(true) - $time, 5) . ' sec<br> Files compiled: ' . sizeof(self::$_scripts) . ' <br> Total size: ' . Utils::formatFileSize($totalSize) . '<br> Compiled File size: ' . Utils::formatFileSize(filesize('.' . $this->_config->get('compiled_js'))) . ' <br> '; exit; }
public function createConnection($id) { foreach ($this->_config as $devType => $data) { if ($this->connectionExists($devType, $id)) { return false; } } foreach ($this->_config as $devType => $data) { if (!Config_File_Array::create($this->_config[$devType]['dir'] . $id . '.php')) { return false; } $c = $this->getConnection($devType, $id); $c->setData(array('username' => '', 'password' => '', 'dbname' => '', 'host' => '', 'charset' => 'UTF8', 'prefix' => '', 'adapter' => 'Mysqli', 'adapterNamespace' => 'Db_Adapter')); if (!$c->save()) { return false; } } return true; }
public function fieldslistAction() { $connectionId = Request::post('connId', 'integer', false); $table = Request::post('table', 'string', false); if ($connectionId === false || !$table) { Response::jsonError($this->_lang->WRONG_REQUEST); } $config = $this->_connConfig->get($connectionId); $config = array('username' => $config['user'], 'password' => $config['pass'], 'dbname' => $config['base'], 'host' => $config['host'], 'charset' => 'UTF8'); try { $db = Zend_Db::factory('Mysqli', $config); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_CONNECT); } $data = array(); $desc = $db->describeTable($table); foreach ($desc as $v => $k) { $data[] = array('name' => $v, 'type' => $k['DATA_TYPE']); } Response::jsonSuccess($data); }
/** * Rebuild all packages */ public function rebuildallAction() { $this->_checkCanEdit(); $dest = $this->_packagesConfig->get('path'); /* * Returning a reference from a function */ $data =& $this->_packagesConfig->dataLink(); if ($this->_packagesConfig->get('all_in_one')) { $s = ''; foreach ($data['packages'] as $item) { if (!$item['active']) { continue; } $s .= $this->_compilePackage($item); } Utils::exportCode($dest . $this->_packagesConfig->get('main_package') . '.php', $s); } else { foreach ($data['packages'] as $name => $item) { $s = $this->_compilePackage($item); $data['packages'][$name]['checksum'] = md5($s); if (Utils::exportCode($dest . $name . '.php', $s) === false) { Response::jsonError($this->_lang->CANT_WRITE_FS); } $data['packages'][$name]['fchecksum'] = md5_file($dest . $name . '.php'); } } if ($this->buildmapAction() === false) { Response::jsonError($this->_lang->CANT_WRITE_FS); } if (!$this->_packagesConfig->save()) { Response::jsonError($this->_lang->CANT_WRITE_FS); } else { Response::jsonSuccess(); } }
public function connectobjectAction() { $connectionId = Request::post('connId', 'string', false); $connectionType = Request::post('type', 'integer', false); $table = Request::post('table', 'string', false); if ($connectionId === false || $connectionType === false || $table === false) { Response::jsonError($this->_lang->WRONG_REQUEST); } $cfg = $this->_manager->getConnection($connectionType, $connectionId); if (!$cfg) { Response::jsonError($this->_lang->WRONG_REQUEST); } $cfg = $cfg->__toArray(); try { $db = Zend_Db::factory($cfg['adapter'], $cfg); $db->query('SET NAMES ' . $cfg['charset']); $tables = $db->listTables(); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_CONNECT . ' ' . $e->getMessage()); } $import = new Db_Object_Import(); if (!$import->isValidPrimaryKey($db, $table)) { $errors = $import->getErrors(); if (!empty($errors)) { $errors = '<br>' . implode('<br>', $errors); } else { $errors = ''; } Response::jsonError($this->_lang->DB_CANT_CONNECT_TABLE . ' ' . $this->_lang->DB_MSG_UNIQUE_PRIMARY . ' ' . $errors); } $manager = new Db_Object_Manager(); $newObjectName = strtolower(str_replace('_', '', $table)); if ($manager->objectExists($newObjectName)) { $newObjectName = strtolower(str_replace('_', '', $cfg['dbname'])) . $newObjectName; if ($manager->objectExists($newObjectName)) { $k = 0; $alphabet = Utils_String::alphabetEn(); while ($manager->objectExists($newObjectName)) { if (!isset($alphabet[$k])) { Response::jsonError('Can not create unique object name' . $errors); } $newObjectName .= $alphabet[$k]; $k++; } } } $config = $import->createConfigByTable($db, $table, $cfg['prefix']); $config['connection'] = $connectionId; if (!$config) { $errors = $import->getErrors(); if (!empty($errors)) { $errors = '<br>' . implode('<br>', $errors); } else { $errors = ''; } Response::jsonError($this->_lang->DB_CANT_CONNECT_TABLE . ' ' . $errors); } else { $path = $this->_configMain->get('object_configs') . $newObjectName . '.php'; if (!Config_File_Array::create($path)) { Response::jsonError($this->_lang->CANT_WRITE_FS . ' ' . $path); } $cfg = Config::factory(Config::File_Array, $path); $cfg->setData($config); if (!$cfg->save()) { Response::jsonError($this->_lang->CANT_WRITE_FS . ' ' . $path); } } Response::jsonSuccess(); }
/** * Create Db_Object * @param string $name - object name * @param array $data - object config */ protected function _createObject($name, array $data) { $usePrefix = $data['use_db_prefix']; $connectionManager = new Db_Manager($this->_configMain); $connection = $connectionManager->getDbConnection($data['connection']); $connectionCfg = $connectionManager->getDbConfig($data['connection']); //$db = Model::getGlobalDbConnection(); $db = $connection; $tables = $db->listTables(); $oConfigPath = Db_Object_Config::getConfigPath(); $tableName = $data['table']; if ($usePrefix) { $tableName = $connectionCfg->get('prefix') . $tableName; } if (in_array($tableName, $tables, true)) { Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'table', 'msg' => $this->_lang->SB_UNIQUE))); } if (file_exists($oConfigPath . strtolower($name) . '.php')) { Response::jsonError($this->_lang->FILL_FORM, array(array('id' => 'name', 'msg' => $this->_lang->SB_UNIQUE))); } /* * Write object config */ if (!Config_File_Array::create($oConfigPath . $name . '.php')) { Response::jsonError($this->_lang->CANT_WRITE_FS); } $cfg = Config::factory(Config::File_Array, $oConfigPath . strtolower($name) . '.php'); /* * Add fields config */ $data['fields'] = array(); $cfg->setData($data); $cfg->save(); try { $cfg = Db_Object_Config::getInstance($name); $cfg->setObjectTitle($data['title']); if (!$cfg->save()) { Response::jsonError($this->_lang->CANT_WRITE_FS); } /* * Build database */ $builder = new Db_Object_Builder($name); $builder->build(); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_EXEC . 'code 2'); } Response::jsonSuccess(); }
public function dbcheckAction() { $host = Request::post('host', 'str', ''); $port = Request::post('port', 'int', 0); $prefix = Request::post('prefix', 'str', ''); $installDocs = Request::post('install_docs', 'boolean', false); $this->_session->set('install_docs', $installDocs); $params = array('host' => $host, 'username' => Request::post('username', 'str', false), 'password' => Request::post('password', 'str', false), 'dbname' => Request::post('dbname', 'str', false), 'adapter' => 'Mysqli', 'adapterNamespace' => 'Db_Adapter'); if ($port != 0) { $params['port'] = $port; } $flag = false; if ($params['host'] && $params['username'] && $params['dbname']) { try { $zendDb = Zend_Db::factory('Mysqli', $params); $zendDb->getServerVersion(); $data['success'] = true; $data['msg'] = $this->_dictionary['SUCCESS_DB_CHECK']; $flag = true; } catch (Exception $e) { $data['success'] = false; $data['msg'] = $this->_dictionary['FAILURE_DB_CHECK']; } } else { $data['success'] = false; $data['msg'] = $this->_dictionary['REQUIRED_DB_SETTINGS']; } if ($flag) { try { $configs = array($this->_docRoot . 'system/config/db/prod/default.php', $this->_docRoot . 'system/config/db/dev/default.php', $this->_docRoot . 'system/config/db/prod/error.php', $this->_docRoot . 'system/config/db/dev/error.php'); foreach ($configs as $path) { if (Config_File_Array::create($path) === false) { throw new Exception(); } $config = Config::factory(Config::File_Array, $path); $config->setData($params); $config->set('charset', 'UTF8'); $config->set('prefix', $prefix); if (!$config->save()) { throw new Exception(); } } } catch (Exception $e) { $data['success'] = false; $data['msg'] = $this->_dictionary['CONNECTION_SAVE_FAIL']; } } Response::jsonSuccess($data); }