Example #1
0
 public function objectsAction()
 {
     $manager = new Db_Object_Manager();
     $objects = $manager->getRegisteredObjects();
     $data = array();
     if (!empty($objects)) {
         foreach ($objects as $name) {
             $data[] = array('name' => $name, 'title' => Db_Object_Config::getInstance($name)->getTitle());
         }
     }
     Response::jsonSuccess($data);
 }
Example #2
0
 protected static function _buildAssociations()
 {
     if (!is_null(self::$_objectAssociations)) {
         return;
     }
     $manager = new Db_Object_Manager();
     $objects = $manager->getRegisteredObjects();
     foreach ($objects as $name) {
         $config = Db_Object_Config::getInstance($name);
         $links = $config->getLinks();
         self::$_objectAssociations[$name] = $links;
     }
 }
Example #3
0
 /**
  * List permissions action
  */
 public function permissionsAction()
 {
     $user = Request::post('user_id', 'int', 0);
     $group = Request::post('group_id', 'int', 0);
     if ($user && $group) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     if ($group) {
         $data = Model::factory('acl_simple')->getGroupPermissions($group);
     }
     if (!empty($data)) {
         $data = Utils::rekey('object', $data);
     }
     $manager = new Db_Object_Manager();
     $objects = $manager->getRegisteredObjects();
     foreach ($objects as $name) {
         if (!isset($data[$name])) {
             $data[$name] = array('object' => $name, 'create' => false, 'view' => false, 'edit' => false, 'delete' => false, 'user_id' => null, 'publish' => false, 'group_id' => $group);
         }
     }
     foreach ($data as $k => &$v) {
         if (!Db_Object_Config::configExists($k)) {
             unset($data[$k]);
             continue;
         }
         $cfg = Db_Object_Config::getInstance($k);
         if ($cfg->isRevControl()) {
             $v['rc'] = true;
         } else {
             $v['rc'] = false;
         }
         $v['title'] = $cfg->getTitle();
     }
     unset($v);
     Response::jsonSuccess(array_values($data));
 }
Example #4
0
 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();
 }
Example #5
0
 /**
  * Create new module
  */
 public function createAction()
 {
     $this->_checkCanEdit();
     $object = Request::post('object', 'string', false);
     if (!$object) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $object = Utils_String::formatClassName($object);
     $class = 'Backend_' . $object . '_Controller';
     if (class_exists($class)) {
         Response::jsonError($this->_lang->FILL_FORM, array('id' => 'name', 'msg' => $this->_lang->SB_UNIQUE));
     }
     $designerConfig = Config::factory(Config::File_Array, $this->_configMain['configs'] . 'designer.php');
     $projectFile = $designerConfig->get('configs') . strtolower($object) . '.designer.dat';
     if (file_exists($projectFile)) {
         Response::jsonError($this->_lang->FILE_EXISTS . '(' . $projectFile . ')');
     }
     $actionFile = $designerConfig->get('actionjs_path') . strtolower($object) . '.js';
     if (file_exists($actionFile)) {
         Response::jsonError($this->_lang->FILE_EXISTS . '(' . $actionFile . ')');
     }
     $objectConfig = Db_Object_Config::getInstance($object);
     // Check ACL permissions
     $acl = $objectConfig->getAcl();
     if ($acl) {
         if (!$acl->can(Db_Object_Acl::ACCESS_CREATE, $object) || !$acl->can(Db_Object_Acl::ACCESS_VIEW, $object)) {
             Response::jsonError($this->_lang->get('ACL_ACCESS_DENIED'));
         }
     }
     $manager = new Db_Object_Manager();
     if (!$manager->objectExists($object)) {
         Response::jsonError($this->_lang->FILL_FORM, array('id' => 'object', 'msg' => $this->_lang->INVALID_VALUE));
     }
     $codeGenadApter = $this->_configBackend->get('modules_codegen');
     $codeGen = new $codeGenadApter();
     try {
         if ($objectConfig->isRevControl()) {
             $codeGen->createVcModule($object, $projectFile, $actionFile);
         } else {
             $codeGen->createModule($object, $projectFile, $actionFile);
         }
     } catch (Exception $e) {
         Response::jsonError($e->getMessage());
     }
     $userInfo = User::getInstance()->getInfo();
     $per = Model::factory('Permissions');
     if (!$per->setGroupPermissions($userInfo['group_id'], $object, 1, 1, 1, 1)) {
         Response::jsonError($this->_lang->CANT_EXEC);
     }
     Response::jsonSuccess(array('class' => $class, 'name' => $object, 'active' => true, 'dev' => false, 'title' => $objectConfig->getTitle(), 'designer' => $projectFile));
 }
Example #6
0
 /**
  * Check and fix config files
  */
 public function fixconfigsAction()
 {
     $manager = new Db_Object_Manager();
     $names = $manager->getRegisteredObjects();
     foreach ($names as $objectName) {
         $cfg = Db_Object_Config::getInstance($objectName);
         $cfg->save();
     }
     Response::jsonSuccess();
 }
Example #7
0
 /**
  * Set default externals experts
  * @param Externals_Expert $expert
  */
 public static function setExternalsExpert(Externals_Expert $expert)
 {
     self::$_externalsExpert = $expert;
 }
Example #8
0
 /**
  * Run backend application
  */
 protected function _runBackend()
 {
     if ($this->_cache) {
         Blockmanager::setDefaultCache($this->_cache);
     }
     /*
      * Prepare objects
      */
     Db_Object_Builder::useForeignKeys($this->_config->get('foreign_keys'));
     /*
      * Inject Externals exper ino Objects Manager
      */
     if ($this->_config->get('allow_externals')) {
         Db_Object_Manager::setExternalsExpert($this->_getExternalsExpert());
     }
     $cfgBackend = Config::factory(Config::File_Array, $this->_config->get('configs') . 'backend.php');
     Registry::set('backend', $cfgBackend, 'config');
     self::$_templates = $this->_config->get('templates') . 'system/' . $cfgBackend->get('theme') . '/';
     $page = Page::getInstance();
     $page->setTemplatesPath(self::$_templates);
     $user = User::getInstance();
     /*
      * Update "Users Online" statistics
      */
     if ($this->_config->get('usersOnline') && $user->isAuthorized()) {
         Model::factory('Online')->addOnline(session_id(), $user->id);
     }
     /*
      * Start routing
      */
     $router = new Backend_Router();
     $router->route();
     $controller = Request::getInstance()->getPart(1);
     /*
      * Define frontent JS variables
      */
     $res = Resource::getInstance();
     $res->addInlineJs('
         app.wwwRoot = "' . $this->_config->get('wwwroot') . '";
     	app.admin = "' . $this->_config->get('wwwroot') . $this->_config->get('adminPath') . '";
     	app.delimiter = "' . $this->_config->get('urlDelimiter') . '";
     	app.root = "' . $this->_config->get('wwwroot') . $this->_config->get('adminPath') . $this->_config->get('urlDelimiter') . $controller . $this->_config->get('urlDelimiter') . '";
     ');
     /*
      * Load template
      */
     $template = new Template();
     $template->disableCache();
     $template->setProperties(array('wwwRoot' => $this->_config->get('wwwroot'), 'page' => $page, 'urlPath' => $controller, 'resource' => $res, 'path' => self::$_templates, 'adminPath' => $this->_config->get('adminPath'), 'development' => $this->_config->get('development'), 'version' => Config::factory(Config::File_Array, $this->_config->get('configs') . 'versions.php')->get('core'), 'lang' => $this->_config->get('language'), 'modules' => Config::factory(Config::File_Array, $this->_config->get('backend_modules')), 'userModules' => $user->getAvailableModules(), 'useCSRFToken' => $cfgBackend->get('use_csrf_token')));
     Response::put($template->render(self::$_templates . 'layout.php'));
 }