/** * method to get and format the log data as needed * @param array &$p * @return array */ protected static function getLogData(&$p) { $rez = array(); $fields = array('id' => 1, 'name' => 1, 'iconCls' => 1, 'pids' => 1, 'path' => 1, 'template_id' => 1, 'case_id' => 1, 'date' => 1, 'size' => 1, 'cid' => 1, 'oid' => 1, 'uid' => 1, 'cdate' => 1, 'udate' => 1); $oldData = empty($p['old']) ? array() : $p['old']->getData(); $newData = empty($p['new']) ? array() : $p['new']->getData(); $oldData = array_intersect_key($oldData, $fields); $newData = array_intersect_key($newData, $fields); $rez = $newData + $oldData; //return empty result for other than object actions (login, logout, etc) if (empty($rez['id'])) { return; } Util\unsetNullValues($rez); $rez['name'] = htmlspecialchars($rez['name'], ENT_COMPAT); if (empty($rez['iconCls'])) { $rez['iconCls'] = Browser::getIcon($rez); } if (!empty($p['mentioned'])) { $rez['mentioned'] = $p['mentioned']; } $rez['pids'] = empty($rez['pids']) ? Objects::getPids($rez['id']) : Util\toNumericArray($rez['pids']); $rez['path'] = htmlspecialchars(@Util\coalesce($rez['pathtext'], $rez['path']), ENT_COMPAT); switch ($p['type']) { case 'comment': case 'comment_update': $rez['comment'] = $p['comment']; break; case 'file_upload': case 'file_update': $rez['file'] = $p['file']; break; case 'completion_decline': case 'completion_on_behalf': if (!empty($p['forUserId'])) { $rez['forUserId'] = $p['forUserId']; } break; default: // setting old and new properties of linear custom data if (!empty($p['old'])) { $rez['old'] = $p['old']->getAssocLinearData(); } if (!empty($p['new'])) { $rez['new'] = $p['new']->getAssocLinearData(); } //unset identical values if (!empty($rez['old']) && !empty($rez['new'])) { foreach ($rez['old'] as $k => $v) { if (isset($rez['new'][$k]) && $rez['new'][$k] == $v) { unset($rez['old'][$k]); unset($rez['new'][$k]); } } } } return $rez; }
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; }
public function create($p) { $rez = array('succes' => false, 'data' => array()); if (empty($p['node_id']) || empty($p['data'])) { return $rez; } $data = array('name' => Purify::filename($p['data']['name']), 'path' => $p['data']['path'], 'pathText' => empty($p['data']['pathText']) ? '' : $p['data']['pathText']); if (is_numeric($p['node_id'])) { $data['template_id'] = Objects::getTemplateId($p['node_id']); $data['iconCls'] = Browser::getIcon($data); } elseif (!empty($p['data']['iconCls'])) { $data['iconCls'] = $p['data']['iconCls']; } $d = array('user_id' => User::getId(), 'node_id' => $p['node_id'], 'data' => Util\jsonEncode($data)); $id = DM\Favorites::create($d); $rez = array('success' => true, 'data' => array('id' => $id, 'node_id' => $d['node_id'], 'data' => $data)); return $rez; }
public function getChildren($p) { $p['from'] = 'tree'; $rez = parent::getChildren($p); //collect resulting record ids and get their children $ids = array(); foreach ($rez['data'] as &$d) { $ids[] = $d['nid']; } $children = DM\Tree::getChildCount($ids); foreach ($rez['data'] as &$d) { if (!isset($d['loaded'])) { if (!isset($d['has_childs'])) { $d['has_childs'] = !empty($children[$d['nid']]); } $d['loaded'] = empty($d['has_childs']); } } return $rez['data']; }
/** * 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; }
/** * formats a value for display according to it's field definition * @param array | int $field array of field properties or field id * @param variant $value field value to be formated * @param boolean $html default true - format for html, otherwise format for text display * @return varchar formated value */ public static function formatValueForDisplay($field, $value, $html = true) { $cacheVarName = ''; if (is_numeric($field)) { $field = $this->data->fields[$field]; } //condition is specified for values from search templates $condition = null; if (is_array($value)) { if (isset($value['cond'])) { $condition = Template::formatConditionForDisplay($field, $value['cond'], $html) . ' '; } if (isset($value['value'])) { $value = $value['value']; } else { $value = null; } } //we'll cache scalar by default, but will exclude textual fields $cacheValue = is_scalar($value); if ($cacheValue) { $fid = empty($field['id']) ? $field['name'] : $field['id']; $cacheVarName = 'dv' . $html . '_' . $fid . '_' . $value; //check if value is in cache and return if (Cache::exist($cacheVarName)) { return Cache::get($cacheVarName); } } /*check if field is not rezerved field for usernames (cid, oid, uid, did)*/ if (!empty($field['name']) && in_array($field['name'], array('cid', 'oid', 'uid', 'did'))) { $value = Util\toNumericArray($value); for ($i = 0; $i < sizeof($value); $i++) { $value[$i] = User::getDisplayName($value[$i]); } $value = implode(', ', $value); } else { switch ($field['type']) { case 'boolean': case 'checkbox': $value = empty($value) ? '' : ($value < 0 ? L\get('no') : L\get('yes')); break; case '_sex': switch ($value) { case 'm': $value = L\get('male'); break; case 'f': $value = L\get('female'); break; default: $value = ''; } break; case '_language': @($value = @\CB\Config::get('language_settings')[\CB\Config::get('languages')[$value - 1]][0]); break; case 'combo': case '_objects': if (empty($value)) { $value = ''; break; } $ids = Util\toNumericArray($value); if (empty($ids)) { if (empty($field['cfg']['source']) || !is_array($field['cfg']['source'])) { $value = ''; } break; } $value = array(); if (in_array(@$field['cfg']['source'], array('users', 'groups', 'usersgroups'))) { $udp = UsersGroups::getDisplayData($ids); foreach ($ids as $id) { if (empty($udp[$id])) { continue; } $r =& $udp[$id]; $label = @htmlspecialchars(Util\coalesce($r['title'], $r['name']), ENT_COMPAT); if ($html) { switch (@$field['cfg']['renderer']) { case 'listGreenIcons': $label = '<li class="icon-padding icon-element">' . $label . '</li>'; break; // case 'listObjIcons': // case 'listObjIcons': default: $icon = empty($r['iconCls']) ? 'icon-none' : $r['iconCls']; $label = '<li class="icon-padding ' . $icon . '">' . $label . '</li>'; break; } } $value[] = $label; } } else { $objects = \CB\Objects::getCachedObjects($ids); foreach ($ids as $id) { if (empty($objects[$id])) { continue; } $obj =& $objects[$id]; $d = $obj->getData(); $label = $obj->getHtmlSafeName(); $pids = $d['pids']; if ($html && !empty($pids)) { $pids = str_replace(',', '/', $pids); $linkType = empty($field['cfg']['linkType']) ? '' : 'link-type-' . $field['cfg']['linkType']; $label = '<a class="click ' . $linkType . '" template_id="' . $d['template_id'] . '" path="' . $pids . '" nid="' . $id . '">' . $label . '</a>'; } switch (@$field['cfg']['renderer']) { case 'listGreenIcons': $value[] = $html ? '<li class="icon-padding icon-element">' . $label . '</li>' : $label; break; // case 'listObjIcons': // case 'listObjIcons': default: $icon = \CB\Browser::getIcon($d); if (empty($icon)) { $icon = 'icon-none'; } $value[] = $html ? '<li class="icon-padding ' . $icon . '">' . $label . '</li>' : $label; break; } } } $value = $html ? '<ul class="clean">' . implode('', $value) . '</ul>' : implode(', ', $value); break; case '_fieldTypesCombo': $value = L\get(@static::$fieldTypeNames[$value]); break; case 'date': $value = Util\formatMysqlDate(Util\dateISOToMysql($value)); break; case 'datetime': $value = Util\UTCTimeToUserTimezone($value); break; case 'time': if (empty($value)) { continue; } $format = empty($field['format']) ? 'H:i' : $field['format']; if (is_numeric($value)) { $s = $value % 60; $value = floor($value / 60); $m = $value % 60; $value = floor($value / 60); if (strlen($value) < 2) { $value = '0' . $value; } if (strlen($m) < 2) { $m = '0' . $m; } $value .= ':' . $m; if (!empty($s)) { if (strlen($s) < 2) { $s = '0' . $s; } $value .= ':' . $s; } } else { $date = \DateTime::createFromFormat($format, $value); if (is_object($date)) { $value = $date->format($format); } } break; case 'html': $cacheValue = false; // $value = trim(strip_tags($value)); // $value = nl2br($value); break; case 'varchar': case 'memo': case 'text': $cacheValue = false; $renderers = ''; if (!empty($field['cfg']['linkRenderers'])) { $renderers = $field['cfg']['linkRenderers']; } elseif (!empty($field['cfg']['text_renderer'])) { $renderers = $field['cfg']['text_renderer']; } $value = empty($renderers) ? nl2br(htmlspecialchars($value, ENT_COMPAT)) : nl2br(Comment::processAndFormatMessage($value), $renderers); break; default: if (is_array($value)) { $cacheValue = false; $value = Util\jsonEncode($value); } else { $value = htmlspecialchars($value, ENT_COMPAT); } } } if ($cacheValue) { Cache::set($cacheVarName, $condition . $value); } return $condition . $value; }
/** * 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 getRootProperties($id) { $rez = array('success' => true, 'data' => array()); $res = DB\dbQuery('SELECT t.id `nid` ,t.`system` ,t.`type` ,t.`name` ,t.`cfg` ,ti.acl_count FROM tree t JOIN tree_info ti on t.id = ti.id WHERE t.id = $1', $id) or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { $r['cfg'] = Util\toJSONArray($r['cfg']); $rez['data'] = array($r); Browser::updateLabels($rez['data']); $rez['data'] = $rez['data'][0]; } $res->close(); return $rez; }
public static function getRootProperties($id) { $rez = array('success' => true, 'data' => array()); $r = DM\Tree::getProperties($id); if (!empty($r)) { $rez['data'] = array($r); Browser::updateLabels($rez['data']); $rez['data'] = $rez['data'][0]; } return $rez; }
/** * 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; }