public function getData($id = false) { $rez = array('success' => true, 'data' => array()); parent::getData($id); $o = $this->getObjectClass(); if (empty($o)) { return $rez; } $data = $o->getData(); //dont display thumb for images less then 1MB $maxDisplaySize = Util\coalesce(Config::get('images_display_size'), 1024 * 1024); if (substr($data['content_type'], 0, 5) == 'image' && $data['size'] < $maxDisplaySize) { $preview = Files::generatePreview($data['id']); if (!empty($preview['filename'])) { $fn = Config::get('files_preview_dir') . $preview['filename']; $rez['data']['html'] = $fn; if (file_exists($fn)) { $rez['data']['html'] = str_replace('fit-img', 'click fit-img', file_get_contents($fn)); } } } else { $rez['data']['cls'] = 'pr-th-' . \CB\Files::getExtension($data['name']); } return $rez; }
/** * 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; }
private function switchNodeShowTitles(&$node) { /* switching label with hint if $_GET['title'] == 1*/ if (empty($_GET['titles']) && empty($this->params['titles'])) { /* parameter titles is sent from the client when switching the nodes display mode */ $t = Util\coalesce($node[$this->hintField], $node[$this->labelField]); $node[$this->hintField] = $node[$this->labelField]; $node[$this->labelField] = $t; } }
public function getData($id = false) { $rez = array('success' => true); parent::getData($id); $o = Objects::getCachedObject($this->id); $data = $o->getData(); //show current version only if have more other versions if (!empty($data['versions'])) { $data['ago_text'] = Util\formatAgoTime(Util\coalesce($data['udate'], $data['cdate'])); $data['user'] = User::getDisplayName(Util\coalesce($data['uid'], $data['oid'], $data['cid']), true); $data['cls'] = 'sel'; $rez['data'] = array($data); } return $rez; }
public function getData($id = false) { $rez = array('success' => true); parent::getData($id); // echo $this->id.'!!'; $o = Objects::getCachedObject($this->id); $data = $o->getData(); if (!empty($data['versions'])) { $rez['data'] = $data['versions']; foreach ($rez['data'] as &$version) { $version['ago_text'] = @Util\formatAgoTime(Util\coalesce($version['udate'], $version['cdate'])); $version['user'] = @User::getDisplayName(Util\coalesce($version['uid'], $version['uid']), true); } } return $rez; }
/** * get diff html for given log record data * @param array $logData * @return array */ public function getDiff($logData) { $old = empty($logData['old']) ? array() : $logData['old']; $new = empty($logData['new']) ? array() : $logData['new']; $rez = array(); $template = $this->getTemplate(); $ld = $this->getLinearData(true); foreach ($ld as $f) { $ov = empty($old[$f['name']]) ? '' : $old[$f['name']][0]; $nv = empty($new[$f['name']]) ? '' : $new[$f['name']][0]; if ($ov != $nv) { $field = $template->getField($f['name']); // var_export($field); $title = Util\coalesce($field['title'], $field['name']); $value = empty($ov) ? '' : '<div class="old-value">' . $template->formatValueForDisplay($field, $ov) . '</div>'; // var_export($nv); $value .= empty($nv) ? '' : '<div class="new-value">' . $template->formatValueForDisplay($field, $nv) . '</div>'; $rez[$title] = $value; } } return $rez; }
/** * method to collect solr data from object data * according to template fields configuration * and store it in sys_data under "solr" property * @return void */ protected function collectSolrData() { parent::collectSolrData(); $d =& $this->data; $sd =& $d['sys_data']; $solrData =& $sd['solr']; $template = $this->getTemplate(); $solrData['task_status'] = @$sd['task_status']; $user_ids = Util\toNumericArray($this->getFieldValue('assigned', 0)['value']); if (!empty($user_ids)) { $solrData['task_u_assignee'] = $user_ids; } $user_ids[] = @Util\coalesce($d['oid'], $d['cid']); $solrData['task_u_all'] = array_unique($user_ids); // $solrData['content'] = @$this->getFieldValue('description', 0)['value']; unset($solrData['task_d_closed']); unset($solrData['task_ym_closed']); if (!empty($sd['task_d_closed'])) { $solrData['task_d_closed'] = $sd['task_d_closed']; $solrData['task_ym_closed'] = str_replace('-', '', substr($sd['task_d_closed'], 2, 5)); } //get users that didnt complete the task yet if (!empty($sd['task_u_done'])) { $solrData['task_u_done'] = $sd['task_u_done']; } if (!empty($sd['task_u_ongoing'])) { $solrData['task_u_ongoing'] = $sd['task_u_ongoing']; } //set class $solrData['cls'] = $template->formatValueForDisplay($template->getField('color'), $this->getFieldValue('color', 0)['value'], false); }
protected function getRootNode() { return array('data' => array(array('name' => $this->getName('root'), 'id' => $this->getId('root'), 'iconCls' => Util\coalesce(@$this->config['iconCls'], 'icon-folder'), 'cls' => 'tree-header', 'has_childs' => false))); }
/** * download files * * outputs file content and set corresponding header params * * @param int $id file id * @return void */ public static function download($id, $versionId = null, $asAttachment = true, $forUseId = false) { $sql = empty($versionId) ? 'SELECT f.id ,f.content_id ,c.path ,f.name ,c.`type` ,c.size FROM files f LEFT JOIN files_content c ON f.content_id = c.id WHERE f.id = $1' : 'SELECT f.file_id `id` ,f.id `version_id` ,f.content_id ,c.path ,f.name ,c.`type` ,c.size FROM files_versions f LEFT JOIN files_content c ON f.content_id = c.id WHERE f.id = $1'; $res = DB\dbQuery($sql, Util\coalesce($versionId, $id)) or die(DB\dbQueryError()); if ($r = $res->fetch_assoc()) { //check if can download file if (!Security::canDownload($r['id'], $forUseId)) { throw new \Exception(L\get('Access_denied')); } header('Content-Description: File Transfer'); header('Content-Type: ' . $r['type'] . '; charset=UTF-8'); if ($asAttachment || $r['type'] !== 'application/pdf') { //purify filename for cases when we have a wrong filename in the system already header('Content-Disposition: attachment; filename="' . Purify::filename($r['name']) . '"'); } header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . $r['size']); readfile(Config::get('files_dir') . $r['path'] . DIRECTORY_SEPARATOR . $r['content_id']); } else { throw new \Exception(L\get('Object_not_found')); } $res->close(); }
/** * get solr columns for a node based on display columns * @return array */ public function getSolrFields($nodeId = false, $templateId = false) { $nodeId = $nodeId; // dummy codacy assignment $rez = array('fields' => array(), 'sort' => array()); $ip =& $this->inputParams; $defaultColumns = array_keys(Config::getDefaultGridViewColumns()); $displayColumns = $this->getDC(); $DC = empty($displayColumns['data']) ? array() : $displayColumns['data']; if (!empty($DC)) { foreach ($DC as $columnName => $column) { if (is_array($column) && !empty($column['solr_column_name'])) { $rez['fields'][$column['solr_column_name']] = 1; if (empty($column['localSort'])) { if (@$ip['sort'][0]['property'] == $columnName && !empty($ip['sort'][0]['direction'])) { $rez['sort'][] = $column['solr_column_name'] . ' ' . strtolower($ip['sort'][0]['direction']); } elseif (!empty($column['sort'])) { $rez['sort'][] = $column['solr_column_name'] . ' ' . $column['sort']; } } } elseif (is_scalar($column)) { $a = explode(':', $column); if ($a[0] == 'solr') { $rez['fields'][$a[1]] = 1; } } } } /* user clicked a column to sort by */ $property = null; $dir = 'asc'; if (!empty($ip['userSort'])) { $dir = strtolower($ip['sort'][0]['direction']); if (in_array($dir, array('asc', 'desc')) && preg_match('/^[a-z_0-9]+$/i', $ip['sort'][0]['property'])) { $prop = $ip['sort'][0]['property']; if (!empty($DC[$prop]['solr_column_name'])) { $col = $DC[$prop]; //also check if not marked as localSort if (empty($col['localSort'])) { $property = $col['solr_column_name']; } } elseif (in_array($prop, $defaultColumns)) { $property = $prop; } } } else { /* get user state and check if user has a custom sorting */ $stateFrom = empty($displayColumns['from']) ? 'default' : $displayColumns['from']; $state = $this->getState($stateFrom); if (!empty($state['sort']['property'])) { $property = $state['sort']['property']; $dir = strtolower(Util\coalesce(@$state['sort']['direction'], 'asc')); if (!empty($DC[$property]['solr_column_name']) && empty($DC[$property]['localSort'])) { $property = $DC[$property]['solr_column_name']; } elseif (!in_array($property, $defaultColumns)) { $property = null; } } } if (!empty($property)) { $rez['sort'] = 'ntsc asc,' . $property . ' ' . $dir; } /* end of get user state and check if user has a custom sorting */ if (!empty($rez['fields'])) { $rez['fields'] = array_keys($rez['fields']); } return $rez; }
public function getLogRecords() { $s = Log::getSolrLogConnection(); $this->requestParams['sort'] = array('action_date desc'); $p = array('rows' => 50, 'fl' => 'id,action_id,user_id,object_id,object_pid,object_data', 'fq' => $this->fq, 'strictSort' => 'action_date desc'); $id = substr($this->lastNode->id, 1); switch (substr($this->lastNode->id, 0, 1)) { case 'd': $p['fq'][] = 'action_date:["' . $id . 'T00:00:00Z" TO "' . $id . 'T23:59:99Z"]'; break; case 'm': $p['fq'][] = 'action_date:["' . date('Y-m') . '-01T00:00:00Z" TO *]'; break; case 't': $p['fq'][] = 'action_type:' . $id; break; case 'u': $p['fq'][] = 'user_id:' . $id; break; case 't': $p['fq'][] = 'action_type:' . $id; break; } $rez = $s->query($p); foreach ($rez['data'] as &$doc) { $k = @$doc['action_id']; $data = Util\toJSONArray($doc['object_data']); $doc['id'] = $this->getId($k); $doc['pid'] = @$doc['object_pid']; unset($doc['object_pid']); $doc['name'] = Util\coalesce($data['name'], $doc['object_data']); $doc['iconCls'] = $data['iconCls']; $doc['path'] = $data['path']; // $doc['template_id'] = $data['template_id']; $doc['case_id'] = $data['case_id']; if ($data['date']) { $doc['date'] = $data['date']; } $doc['size'] = $data['size']; $doc['cid'] = @$data['cid']; $doc['oid'] = @$data['oid']; $doc['uid'] = @$data['uid']; $doc['cdate'] = $data['cdate']; $doc['udate'] = $data['udate']; $doc['user'] = User::getDisplayName($doc['user_id'], true); $doc['has_childs'] = false; } 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; }
/** * get diff html for given log record data * @param array $logData * @return array */ public function getDiff($logData) { $old = empty($logData['old']) ? array() : $logData['old']; $new = empty($logData['new']) ? array() : $logData['new']; $rez = array(); $template = $this->getTemplate(); $ld = $this->getLinearData(true); foreach ($ld as $f) { $ov = empty($old[$f['name']]) ? '' : $old[$f['name']][0]; $nv = empty($new[$f['name']]) ? '' : $new[$f['name']][0]; if ($ov != $nv) { $field = $template->getField($f['name']); if ($field['type'] == '_objects') { $a = empty($ov['value']) ? array() : Util\toNumericArray($ov['value']); $b = empty($nv['value']) ? array() : Util\toNumericArray($nv['value']); $c = array_intersect($a, $b); if (!empty($c)) { $a = array_diff($a, $c); $b = array_diff($b, $c); $ov['value'] = implode(',', $a); $nv['value'] = implode(',', $b); } } $title = Util\coalesce($field['title'], $field['name']); $value = empty($ov) ? '' : '<div class="old-value">' . $template->formatValueForDisplay($field, $ov, false) . '</div>'; $value .= empty($nv) ? '' : '<div class="new-value">' . $template->formatValueForDisplay($field, $nv, false) . '</div>'; $rez[$title] = $value; } } return $rez; }
/** * return the owner of the object * @param int $userId */ public function getOwner() { $d =& $this->data; return @Util\coalesce($d['oid'], $d['cid']); }
protected function getRootNode() { return array('data' => array(array('name' => $this->getName('root'), 'id' => $this->getId('root'), 'iconCls' => Util\coalesce(@$this->config['iconCls'], 'icon-folder'), 'has_childs' => !empty($this->config['level_fields']) || !empty($this->config['show_in_tree'])))); }
protected function getData($p) { $rez = array(); if (empty($p)) { return $rez; } // form columns L\initTranslations(); $defaultColumns = Config::getDefaultGridColumnConfigs(); $columns = $defaultColumns; // retreive data $p['start'] = 0; $p['rows'] = 500; $sr = new \CB\BrowserView(); $results = $sr->getChildren($p); if (!empty($results['DC'])) { $columns = array(); foreach ($results['DC'] as $colName => $col) { if (@$col['hidden'] !== true) { $columns[$colName] = $col; } } } $colTitles = array(); foreach ($columns as $name => &$col) { $colTitles[] = empty($defaultColumns[$name]) ? @Util\coalesce($col['title'], $name) : $defaultColumns[$name]['title']; } //insert header $rez[] = $colTitles; while (!empty($results['data'])) { foreach ($results['data'] as $r) { $record = array(); foreach ($columns as $colName => $col) { if (@$col['xtype'] == 'datecolumn') { $value = Util\dateISOToMysql(@$r[$colName]); if (!empty($col['format'])) { $value = Util\formatMysqlTime($value, $col['format']); } else { $value = Util\formatMysqlTime($value); $tmp = explode(' ', $value); if (!empty($tmp[1]) && $tmp[1] == '00:00') { $value = $tmp[0]; } } $record[] = $value; } elseif (strpos($colName, 'date') === false) { if (in_array($colName, array('oid', 'cid', 'uid')) && !empty($r[$colName])) { $record[] = User::getDisplayName($r[$colName]); } else { $record[] = @$r[$colName]; } } } $rez[] = $record; } if ($p['start'] + $p['rows'] < $results['total']) { $p['start'] += $p['rows']; $results = $sr->getChildren($p); } else { $results['data'] = array(); } } return $rez; }