/** * load next set of comments (not all are loaded by default) * @param array $p * @return json response */ public function loadMore($p) { $rez = array('success' => true, 'data' => array()); if (empty(parent::getData($p['id']))) { return $rez; } $commentTemplateIds = DM\Templates::getIdsByType('comment'); if (empty($commentTemplateIds)) { return $rez; } $limit = empty($p['beforeId']) ? 4 : 10; $limit = Config::get('max_load_comments', $limit); $params = array('pid' => $this->id, 'system' => '[0 TO 2]', 'fq' => array('template_id:(' . implode(' OR ', $commentTemplateIds) . ')'), 'fl' => 'id,pid,template_id,cid,cdate,content', 'strictSort' => 'cdate desc', 'rows' => $limit); if (!empty($p['beforeId']) && is_numeric($p['beforeId'])) { $params['fq'][] = 'id:[* TO ' . ($p['beforeId'] - 1) . ']'; } $s = new \CB\Search(); $sr = $s->query($params); if (empty($p['beforeId'])) { $rez['total'] = $sr['total']; } foreach ($sr['data'] as $d) { $d['cdate_text'] = Util\formatAgoTime($d['cdate']); $d['user'] = User::getDisplayName($d['cid'], true); //data in solr has already encoded html special chars // so we need to decode it and to format the message (where the chars will be encoded again) $d['content'] = htmlspecialchars_decode($d['content'], ENT_COMPAT); $d['content'] = \CB\Objects\Comment::processAndFormatMessage($d['content']); array_unshift($rez['data'], $d); } static::addAttachmentLinks($rez); return $rez; }
protected function createDefaultFilter() { $this->fq = array(); //select only case templates $templates = DM\Templates::getIdsByType('case'); if (!empty($templates)) { $this->fq[] = 'template_id:(' . implode(' OR ', $templates) . ')'; } $this->user_id = $_SESSION['user']['id']; // add office filter $parentNode = null; switch (get_class($this->lastNode)) { case 'Demosrc\\TreeNode\\OfficeCases': if (is_numeric($this->lastNode->id)) { $parentNode = $this->lastNode->parent->parent; // $this->fq[] = 'category_id:'.$this->lastNode->parent->parent->id; $this->fq[] = 'status:' . $this->lastNode->id; } else { $parentNode = $this->lastNode->parent; // $this->fq[] = 'category_id:'.$this->lastNode->parent->id; } break; default: $parentNode = $this->lastNode; } switch (get_class($parentNode)) { case 'Demosrc\\TreeNode\\OfficeUsers': $this->fq[] = '(role_ids2:' . $parentNode->id . ' OR role_ids3:' . $parentNode->id . ')'; // $this->fq[] = 'category_id:'.$parentNode->parent->parent->id; break; case 'Demosrc\\TreeNode\\Offices': // $this->fq[] = 'category_id:'.$parentNode->id; break; } }
protected function createDefaultFilter() { $this->fq = array(); //select only task templates $taskTemplates = DM\Templates::getIdsByType('task'); if (!empty($taskTemplates)) { $this->fq[] = 'template_id:(' . implode(' OR ', $taskTemplates) . ')'; } // add office filter switch (get_class($this->lastNode)) { case 'Demosrc\\TreeNode\\OfficeUsers': $this->fq[] = 'user_ids:' . $this->lastNode->id; break; case 'Demosrc\\TreeNode\\Offices': // $this->fq[] = 'category_id:'.$this->lastNode->id; break; } if (get_class($this->lastNode) == 'Demosrc\\TreeNode\\OfficeUsers') { // $this->fq[] = 'category_id:'.$this->lastNode->parent->parent->id; $this->fq[] = 'user_ids:' . $this->lastNode->id; } else { // $this->fq[] = 'category_id:'.$this->lastNode->id; } $this->user_id = $_SESSION['user']['id']; }
protected function createDefaultFilter() { $this->fq = array(); //select only task templates $taskTemplates = DM\Templates::getIdsByType('task'); if (!empty($taskTemplates)) { $this->fq[] = 'template_id:(' . implode(' OR ', $taskTemplates) . ')'; } }
/** * return templates list * @param array $p * @return json response */ public function readAll($p) { $rez = DM\Templates::readAllWithData(); foreach ($rez as &$r) { $r['title'] = Util\detectTitle($r['data']); unset($r['data']); unset($r['cfg']['source']['fn']); } return $rez; }
protected function createDefaultFilter() { $this->fq = array(); //select only case templates $caseTemplates = DM\Templates::getIdsByType('case'); if (!empty($caseTemplates)) { $this->fq[] = 'template_id:(' . implode(' OR ', $caseTemplates) . ')'; } $this->user_id = $_SESSION['user']['id']; $this->fq[] = sprintf('(role_ids1:%1$d OR role_ids2:%1$d OR role_ids3:%1$d)', $this->user_id); }
/** * 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'))); }
public static function getTemplateId() { $rez = null; $r = DM\Templates::getIdsByType('user'); $rez = array_shift($r); return $rez; }
protected function copyCustomDataTo($targetId) { DM\Templates::copy($this->id, $targetId); }
/** * add comments for an objects * @param array $p input params (id, msg) */ public function addComment($p) { $rez = array('success' => false); if (empty($p['id']) || !is_numeric($p['id']) || empty($p['msg'])) { $rez['msg'] = L\get('Wrong_input_data'); return $rez; } if (!Security::canRead($p['id'])) { throw new \Exception(L\get('Access_denied')); } $commentTemplates = DM\Templates::getIdsByType('comment'); if (empty($commentTemplates)) { $rez['msg'] = 'No comment templates found'; return $rez; } $co = new Objects\Comment(); $data = array('pid' => $p['id'], 'draftId' => @$p['draftId'], 'template_id' => array_shift($commentTemplates), 'system' => 2, 'data' => array('_title' => $p['msg'])); $id = $co->create($data); Solr\Client::runCron(); return array('success' => true, 'data' => \CB\Objects\Plugins\Comments::loadComment($id)); }
/** * set the flags for actions that could be made to the tasks by a specific or current user * @param reference $object_records * @return void */ public static function setTasksActionFlags(&$tasksDataArray, $userId = false) { $userId = $userId; // dummy codacy assignment $taskTemplates = DM\Templates::getIdsByType('task'); foreach ($tasksDataArray as &$d) { if (!in_array(@$d['template_id'], $taskTemplates) || empty($d['status'])) { continue; } $task = Objects::getCachedObject($d['id']); $d['can'] = $task->getActionFlags(); } }
// System::notifyAdmin('Casebox: check mail Exception for core' . $coreName, $e->getMessage()); echo " Error connecting to email\n" . $e->getMessage(); } } // iterate each core and add comment items if there is smth foreach ($mailServers as $mailConf) { $deleteMailIds = array(); foreach ($mailConf['cores'] as $coreName => $core) { if (empty($core['mails'])) { continue; } $_GET['core'] = $coreName; $_SERVER['SERVER_NAME'] = $coreName . '.casebox.org'; include $site_path . DIRECTORY_SEPARATOR . 'config.php'; include $site_path . DIRECTORY_SEPARATOR . 'lib/language.php'; $templateIds = DM\Templates::getIdsByType('comment'); if (empty($templateIds)) { \CB\debug('receive comments cron: no comment template defined'); continue; } $templateId = array_shift($templateIds); $commentsObj = Objects::getCustomClassByType('comment'); foreach ($core['mails'] as $mail) { if (!Objects::idExists($mail['pid'])) { \CB\debug('receive comments cron: target id not found for mail "' . $mail['subject'] . '"'); continue; } $emailFrom = extractEmailFromText($mail['from']); // user email $emailTo = extractEmailFromText($mail['to']); // <*****@*****.**>
/** * get environment variables from given config * @return void */ private static function getEnvironmentVars($config) { $coreName = $config['core_name']; $ds = DIRECTORY_SEPARATOR; $filesDir = DATA_DIR . 'files' . $ds . $coreName . $ds; $rez = array('db_name' => empty($config['db_name']) ? PREFIX . $coreName : $config['db_name'], 'solr_core' => empty($config['solr_core']) ? PREFIX . $coreName : $config['solr_core'], 'core_dir' => empty($config['core_dir']) ? DOC_ROOT . 'cores' . $ds . $coreName . $ds : $config['core_dir'], 'files_dir' => $filesDir, 'files_preview_dir' => $filesDir . 'preview' . $ds, 'photos_path' => $filesDir . '_photo' . $ds, 'core_url' => $config['server_name'] . $coreName . '/', 'upload_temp_dir' => TEMP_DIR . $coreName . $ds, 'incomming_files_dir' => TEMP_DIR . $coreName . $ds . 'incomming' . $ds, 'error_log' => LOGS_DIR . PREFIX . $coreName . '_error_log', 'debug_log' => LOGS_DIR . PREFIX . $coreName . '_debug_log'); /* Define folder templates */ $rez['folder_templates'] = empty($config['folder_templates']) ? array() : explode(',', $config['folder_templates']); $rez['default_folder_template'] = empty($rez['folder_templates']) ? 0 : $rez['folder_templates'][0]; if (empty($config['default_file_template'])) { $a = DM\Templates::getIdsByType('file'); $rez['default_file_template'] = array_shift($a); } else { $rez['default_file_template'] = $config['default_file_template']; } if (empty($config['default_shortcut_template'])) { $a = DM\Templates::getIdsByType('shortcut'); $rez['default_shortcut_template'] = array_shift($a); } else { $rez['default_shortcut_template'] = $config['default_shortcut_template']; } foreach ($config as $k => $v) { if (strlen($k) == 11 && substr($k, 0, 9) == 'language_') { $rez['language_settings'][substr($k, 9)] = Util\toJSONArray($v); } } /* Define Core available languages */ $rez['languages'] = implode(',', array_keys($rez['language_settings'])); if (!empty($config['languages'])) { $rez['languages'] = Util\toTrimmedArray($config['languages']); // define default core language $rez['language'] = empty($config['default_language']) || !in_array($config['default_language'], $rez['languages']) ? $rez['languages'][0] : $config['default_language']; } $rez['languagesUI'] = empty($config['languagesUI']) ? $rez['languages'] : Util\toTrimmedArray($config['languagesUI']); // Default row count limit used for solr results $rez['max_rows'] = empty($config['max_rows']) ? 50 : $config['max_rows']; return $rez; }
//check script options $options = getopt('c:at:', array('core', 'all', 'template')); $core = empty($options['c']) ? @$options['core'] : $options['c']; if (empty($core)) { die('no core specified or invalid options set.'); } $all = isset($options['a']) || isset($options['all']); $template = empty($options['t']) ? @$options['template'] : $options['t']; //init $cron_id = 'dummy'; include $path . 'init.php'; \CB\Config::setFlag('disableActivityLog', true); //create query filter $where = empty($all) ? ' AND t.updated = 1' : ''; if (!empty($template)) { $template = is_numeric($template) ? array($template) : DM\Templates::getIdsByType($template); if (!empty($template)) { $where .= ' AND t.template_id in (' . implode(',', $template) . ') '; } } // join with tree table if filter not empty if (!empty($where)) { $where = ' JOIN tree t ON o.id = t.id ' . $where; } //start the process //select all objects that have data in "objects" table $res = DB\dbQuery('SELECT count(*) `nr` FROM objects o' . $where) or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { echo "Total objects: " . $r['nr'] . "\n"; }
/** * get param for this node * * @param varchar $param for now using to get 'facets' or 'DC' * @return array */ public function getNodeParam($param = 'facets') { $rez = false; $from = $this->getId(); //check if cached $cacheParam = 'nodeParam_' . $param . '_' . $from; if (Cache::exist($cacheParam)) { return Cache::get($cacheParam); } $cfg = array(); $templateId = null; $tplCfg = array(); if (!empty($this->id) && is_numeric($this->id)) { $r = DM\Tree::read($this->id); } if (!empty($r)) { $cfg = $r['cfg']; $templateId = $r['template_id']; } if (!empty($this->config['template_id'])) { $templateId = $this->config['template_id']; } if (!empty($templateId)) { $r = DM\Templates::read($templateId); if (!empty($r)) { $tplCfg = $r['cfg']; } } if (isset($cfg[$param])) { $rez = $cfg[$param]; } elseif (isset($tplCfg[$param])) { $cfg = $tplCfg; $rez = $cfg[$param]; $from = 'template_' . $templateId; } //add grouping param for DC if ($param == 'DC' && $rez !== false) { if (!empty($cfg['view']['group'])) { $rez['group'] = $cfg['view']['group']; } elseif (!empty($cfg['group'])) { $rez['group'] = $cfg['group']; } } if ($rez === false) { $rez = parent::getNodeParam($param); } else { $rez = array('from' => $from, 'data' => $rez); } Cache::set($cacheParam, $rez); return $rez; }
/** * transfer config options to tree * @return void */ protected function syncConfigToTree() { $o = new \CB\Objects\Object(); $co = new \CB\Objects\Config(); $recs = DM\Config::readAll(); foreach ($recs as $r) { //detect option type $type = ''; switch ($r['param']) { case 'default_event_template': case 'default_file_template': case 'default_folder_template': case 'default_task_template': $type = 'int'; break; case 'default_language': case 'languages': case 'project_name_en': case 'project_name_ru': $type = 'varchar'; break; case 'folder_templates': case 'max_files_version_count': case 'templateIcons': $type = 'text'; break; case 'facet_configs': case 'js': case 'maintenance_cfg': case 'node_facets': case 'rootNode': case 'object_type_plugins': case 'treeNodes': $type = 'json'; break; case 'responsible_party': case 'responsible_party_default': case 'task_categories': case 'maintenance_mode': continue; default: if (is_numeric($r['value'])) { $type = 'int'; } else { $type = 'text'; } } if (empty($type)) { continue; } $childs = array(); if ($r['param'] == 'folder_templates') { $r['value'] .= ',' . $this->templateIds["Config json option"]; DM\Config::update($r); } if ($r['param'] == 'treeNodes') { $childs = Util\toJSONArray($r['value']); $r['value'] = ''; DM\Config::update($r); } $pid = $o->create(array('id' => null, 'pid' => $this->cfg['configFolderId'], 'template_id' => $this->templateIds["Config {$type} option"], 'name' => $r['param'], 'data' => array('_title' => $r['param'], 'value' => $r['value']))); $i = 1; foreach ($childs as $k => $v) { $co->create(array('id' => null, 'pid' => $pid, 'template_id' => $this->templateIds["Config {$type} option"], 'name' => $k, 'data' => array('_title' => $k, 'value' => json_encode($v, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT), 'order' => $i++))); } } //add menu rule for Menus folder $pid = Objects::getChildId($this->systemFolderId, 'Menus'); $tempalteIds = DM\Templates::getIdsByType('menu'); $o->create(array('id' => null, 'pid' => $pid, 'template_id' => $tempalteIds[0], 'name' => 'Create config options rule', 'data' => array('_title' => 'Create config options rule', 'node_ids' => $this->cfg['configFolderId'], 'menu' => $this->templateIds['Config int option'] . ',' . $this->templateIds['Config varchar option'] . ',' . $this->templateIds['Config text option'] . ',' . $this->templateIds['Config json option']))); }
/** * get template type by its id * @param int $id * @return varchar */ public function getType($id) { if (!is_numeric($id)) { return null; } // check if template has been loaded if (!empty($this->templates[$id])) { return $this->templates[$id]->getData()['type']; } $var_name = 'template_type' . $id; if (!\CB\Cache::exist($var_name)) { $r = DM\Templates::read($id); if (!empty($r)) { \CB\Cache::set($var_name, $r['type']); } } return \CB\Cache::get($var_name); }