public function __construct($config = array(), $id = null) { if (!empty($config['pid']) && $config['pid'] == 'root') { $config['pid'] = \CB\Browser::getRootFolderId(); } if (!empty($config['realNodeId']) && $config['realNodeId'] == 'root') { $config['realNodeId'] = \CB\Browser::getRootFolderId(); } $this->config = $config; $this->guid = @$config['guid']; $this->id = $id; }
public function getChildren(&$pathArray, $requestParams) { $rez = array(); $this->path = $pathArray; $this->lastNode = @$pathArray[sizeof($pathArray) - 1]; $this->requestParams = $requestParams; $this->rootId = \CB\Browser::getRootFolderId(); if (!$this->acceptedPath()) { return; } $this->createDefaultFilter(); return $this->getRootNodes(); }
public function getChildren(&$pathArray, $requestParams) { $rez = array(); $this->path = $pathArray; $this->lastNode = @$pathArray[sizeof($pathArray) - 1]; $this->requestParams = $requestParams; $this->rootId = \CB\Browser::getRootFolderId(); if (!$this->acceptedPath()) { return; } $this->createDefaultFilter(); if (get_class($this->lastNode) == 'Demosrc\\TreeNode\\TaskTypes') { $rez = $this->getRootNodes(); } else { $rez = $this->getTasks(); } return $rez; }
/** * executing preimporting changes to target core * @return void */ protected function prepare() { //update template types DB\dbQuery("ALTER TABLE `templates`\n CHANGE `type` `type` enum('case','object','file','task','user','email','template','field','search','comment','shortcut','menu')\n COLLATE utf8_general_ci NULL after `is_folder`") or die(DB\dbQueryError()); // set templates template id in config $ids = DM\Templates::getIdsByType('template'); $id = array_shift($ids); BBM::$cfg['templatesTemplateId'] = $id; $this->cfg['templates']['Menu rule']['fields']['template_ids']['cfg']['templates'] = $id; $this->cfg['templates']['Menu rule']['fields']['menu']['cfg']['templates'] = $id; // detect fields template id $ids = DM\Templates::getIdsByType('field'); $id = array_shift($ids); BBM::$cfg['fieldTemplateId'] = $id; //detect folderTemplateId $ids = Config::get('folder_templates'); if (!empty($ids)) { BBM::$cfg['folderTemplateId'] = array_shift($ids); } //create "Menu" folder under templates to store our menu templates there //and update BBM::$cfg['templatesFolderId'] to our folder id $o = new \CB\Objects\Object(); $rootId = Browser::getRootFolderId(); $pid = Objects::getChildId($rootId, 'Templates'); if (empty($pid)) { $pid = Objects::getChildId($rootId, 'System'); if (!empty($pid)) { $pid = Objects::getChildId($pid, 'Templates'); } } $id = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'Menu', 'data' => array('_title' => 'Menu'))); BBM::$cfg['templatesFolderId'] = $id; //create System/Menus folder for transferring menu rules to it $pid = Objects::getChildId($rootId, 'System'); if (empty($pid)) { $pid = $o->create(array('id' => null, 'pid' => $rootId, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'System', 'data' => array('_title' => 'System'))); } $this->cfg['menusFolderId'] = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'Menus', 'data' => array('_title' => 'Menus'))); }
/** * update create menus * @return void */ protected function updateCreateMenus() { $rootId = \CB\Browser::getRootFolderId(); $pid = Objects::getChildId($rootId, 'System'); if (!empty($pid)) { $pid = Objects::getChildId($pid, 'Menus'); if (!empty($pid)) { $res = DB\dbQuery('SELECT id FROM tree WHERE pid = $1 AND dstatus = 0', $pid) or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { $o = Objects::getCachedObject($r['id']); $d = $o->getData(); $d['data']['menu'] = $this->templateIds['Case'] . ',' . $this->templateIds['Contact'] . ',' . $this->templateIds['Organization'] . ',' . $d['data']['menu']; $o->update($d); } $res->close(); } } }
/** * get login info for current loged user * @return array json responce */ public function getLoginInfo() { $coreName = Config::get('core_name'); $filesConfig = Config::get('files'); $webdavFiles = empty($filesConfig['edit']['webdav']) ? Config::get('webdav_files') : $filesConfig['edit']['webdav']; $filesEdit = empty($filesConfig['edit']) ? array() : $filesConfig['edit']; $filesEdit['webdav'] = $webdavFiles; //transform element values in array of file extensions foreach ($filesEdit as $k => $v) { $filesEdit[$k] = Util\toTrimmedArray($v); } @($rez = array('success' => true, 'config' => array('coreName' => $coreName, 'rtl' => Config::get('rtl'), 'folder_templates' => Config::get('folder_templates'), 'default_task_template' => Config::get('default_task_template'), 'default_event_template' => Config::get('default_event_template'), 'files.edit' => $filesEdit, 'template_info_column' => Config::get('template_info_column'), 'leftRibbonButtons' => Config::get('leftRibbonButtons')), 'user' => $_SESSION['user'])); $rez['config']['files.edit'] = $filesEdit; $rez['user']['cfg']['short_date_format'] = $rez['user']['cfg']['short_date_format']; $rez['user']['cfg']['long_date_format'] = $rez['user']['cfg']['long_date_format']; $rez['user']['cfg']['time_format'] = $rez['user']['cfg']['time_format']; /* default root node config */ $root = Config::get('rootNode'); if (is_null($root)) { $root = Browser::getRootProperties(Browser::getRootFolderId())['data']; } else { $root = Util\toJSONArray($root); if (isset($root['id'])) { $root['nid'] = $root['id']; unset($root['id']); } } $rez['config']['rootNode'] = $root; /* end of default root node config */ unset($rez['user']['TSV_checked']); return $rez; }
/** * sync config table ids with those from tree * @return void */ protected function syncConfigIds() { echo "Sync config ids .. "; $rootId = Browser::getRootFolderId(); $pid = Objects::getChildId($rootId, 'System'); $pid = Objects::getChildId($pid, 'Config'); $ref = array(); $left = array(); $lastLength = 0; $rows = DM\Config::readAll(); //add root nodes foreach ($rows as &$r) { if (empty($r['pid'])) { $tr = DM\Tree::getChildByName($pid, $r['param']); if (empty($tr)) { DM\Config::delete($r['id']); } else { $ref[$r['id']] =& $r; $r['treeRecord'] = $tr; } } else { $left[] =& $r; } } while (!empty($left) && sizeof($left) != $lastLength) { $rows = $left; $lastLength = sizeOf($left); $left = array(); foreach ($rows as &$r) { if (isset($ref[$r['pid']]) && !empty($ref[$r['pid']]['treeRecord'])) { $ref[$r['id']] =& $r; $r['treeRecord'] = DM\Tree::getChildByName($ref[$r['pid']]['treeRecord']['id'], $r['param']); } else { $left[] =& $r; } } } //iterate and update config table foreach ($ref as &$r) { $tr = $r['treeRecord']; $pid = empty($ref[$r['pid']]['treeRecord']) ? null : $ref[$r['pid']]['treeRecord']['id']; DB\dbQuery('UPDATE config SET id = $2 ,pid = $3 WHERE id = $1', array($r['id'], $tr['id'], $pid)); } echo "Ok \n"; }
} } /* end of try to find user from database that corresponds to this mail */ if (preg_match('/(\\([\\s]*(.+)[\\s]*\\))\\s*$/i', $subject, $matches)) { $subject = str_replace($matches[0], '', $subject); $path = $matches[2]; } else { /*STORE IN /<USER_ID>/Emails folder*/ $pid = User::getEmailFolderId($user_id); } /* end of try to get target folder from subject*/ /* locate the corresponding folder in our database */ if (empty($pid)) { echo 'processing path ' . $path; $path = explode('/', $path); $rootFolderId = Browser::getRootFolderId(); $rootFolderName = null; $sql = 'SELECT name FROM tree WHERE id = $1'; $res = DB\dbQuery($sql, $rootFolderId) or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { $rootFolderName = $r['name']; } $res->close(); while (!empty($path) && empty($path[0])) { array_shift($path); } while (!empty($path) && empty($path[sizeof($path) - 1])) { array_pop($path); } //check if first folder name in specified path is equal to root name from tree if (empty($path)) {
public static function getRootFolderId() { if (defined('CB\\ROOT_FOLDER_ID')) { return constant('CB\\ROOT_FOLDER_ID'); } $id = null; $res = DB\dbQuery('SELECT id FROM tree WHERE pid IS NULL AND `system` = 1 AND `is_main` = 1') or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { $id = $r['id']; } $res->close(); if ($id == null) { Browser::checkRootFolder(); return Browser::getRootFolderId(); } define('CB\\ROOT_FOLDER_ID', $id); return $id; }
/** * try to detect real target id from a given path/path element * $p path or path element * @return int | null */ public static function detectRealTargetId($p) { $rootId = Browser::getRootFolderId(); $rez = $rootId; if (empty($p)) { return $rez; } $treeNodeConfigs = Config::get('treeNodes', array('Dbnode' => array())); $GUIDConfigs = array(); $guids = static::getGUIDs(array_keys($treeNodeConfigs)); foreach ($treeNodeConfigs as $plugin => $cfg) { $class = empty($cfg['class']) ? '\\CB\\TreeNode\\' . $plugin : $cfg['class']; $cfg['guid'] = $guids[$plugin]; //static::getGUID($plugin); $cfg['class'] = $class; $GUIDConfigs[$cfg['guid']] = $cfg; } $path = explode('/', @$p); while (!empty($path) && empty($path[0])) { array_shift($path); } while (!empty($path) && empty($path[sizeof($path) - 1])) { array_pop($path); } if (empty($path)) { return $rez; } $rez = null; while (is_null($rez) && !empty($path)) { $el = array_pop($path); if (is_numeric($el)) { //it's a real node id $rez = $el; } else { list($guid, $el) = explode('-', $el); if (!empty($GUIDConfigs[$guid]['realNodeId'])) { $rez = $GUIDConfigs[$guid]['realNodeId']; } } } if (empty($rez) || $rez == 'root') { $rez = $rootId; } return $rez; }