Пример #1
0
 /**
  * read objects data in bulk manner
  * @param  array $ids
  * @return array
  */
 public static function read($ids)
 {
     $rez = array();
     $ids = Util\toNumericArray($ids);
     if (!empty($ids)) {
         $sql = 'SELECT t.*
                 ,ti.pids
                 ,ti.path
                 ,ti.case_id
                 ,ti.acl_count
                 ,ti.security_set_id
                 ,o.data
                 ,o.sys_data
             FROM tree t
             JOIN tree_info ti
                 ON t.id = ti.id
             LEFT JOIN objects o
                 ON t.id = o.id
             WHERE t.id in (' . implode(',', $ids) . ')';
         $res = DB\dbQuery($sql) or die(DB\dbQueryError());
         while ($r = $res->fetch_assoc()) {
             $r['data'] = Util\jsonDecode($r['data']);
             $r['sys_data'] = Util\jsonDecode($r['sys_data']);
             $rez[] = $r;
         }
         $res->close();
     }
     return $rez;
 }
Пример #2
0
 /**
  * create system folders specified in created objects template config as system_folders property
  * @param  object $o
  * @return void
  */
 public function onNodeDbCreate($o)
 {
     if (!is_object($o)) {
         return;
     }
     $template = $o->getTemplate();
     if (empty($template)) {
         return;
     }
     $templateData = $template->getData();
     if (empty($templateData['cfg']['system_folders'])) {
         return;
     }
     $folderIds = Util\toNumericArray($templateData['cfg']['system_folders']);
     if (empty($folderIds)) {
         return;
     }
     $p = array('sourceIds' => array(), 'targetId' => $o->getData()['id']);
     $browserActionsClass = new Browser\Actions();
     $res = DB\dbQuery('SELECT id
         FROM tree
         WHERE pid in (' . implode(',', $folderIds) . ')
             AND dstatus = 0');
     while ($r = $res->fetch_assoc()) {
         $p['sourceIds'][] = $r['id'];
     }
     $res->close();
     // $browserActionsClass->copy($p);
     $browserActionsClass->objectsClass = new \CB\Objects();
     $browserActionsClass->doRecursiveAction('copy', $p['sourceIds'], $p['targetId']);
 }
Пример #3
0
 /**
  * update a record
  * @param  array $p array with properties
  * @return array
  */
 public static function getRecords($ids)
 {
     $rez = array();
     $ids = Util\toNumericArray($ids);
     $res = DB\dbQuery('SELECT *
         FROM `' . static::getTableName() . '`
         WHERE id in (0' . implode(',', $ids) . ')');
     while ($r = $res->fetch_assoc()) {
         $rez[] = $r;
     }
     $res->close();
     return $rez;
 }
Пример #4
0
 public function onSolrQuery(&$p)
 {
     $result =& $p['result'];
     $data =& $result['data'];
     $ip =& $p['inputParams'];
     $view =& $ip['view'];
     $facets =& $ip['facets'];
     $coloring = empty($view['coloring']) ? array() : Util\toTrimmedArray($view['coloring']);
     $view['coloring'] = $coloring;
     // detect active coloring facet
     $coloringField = $this->getActiveColoringField($p);
     $activeFacetClass = null;
     $types = array();
     foreach ($coloring as $facetAlias) {
         if (!empty($facets[$facetAlias]->field)) {
             $types[] = $facets[$facetAlias]->field;
             if ($coloringField == $facets[$facetAlias]->field) {
                 $activeFacetClass =& $facets[$facetAlias];
             }
         }
     }
     $result['view']['coloring'] = $types;
     $coloringItems = array();
     if (!empty($activeFacetClass)) {
         $cf = $activeFacetClass->getClientData(array('colors' => true));
         $result['facets'][$activeFacetClass->field] = $cf;
         $coloringItems = $cf['items'];
     }
     $rez = array();
     foreach ($data as $r) {
         $fv = empty($r[$coloringField]) ? array() : Util\toNumericArray($r[$coloringField]);
         if (empty($fv)) {
             $r['cls'] = 'user-color-' . $r['cid'];
             $rez[] = $r;
         } else {
             foreach ($fv as $v) {
                 if (!empty($coloringItems[$v])) {
                     $c = $coloringItems[$v];
                     if (!empty($c['cls'])) {
                         $r['cls'] = $c['cls'];
                     }
                     if (!empty($c['color'])) {
                         $r['style'] = 'background-color: ' . $c['color'];
                     }
                 }
                 $rez[] = $r;
             }
         }
     }
     $result['data'] = $rez;
 }
Пример #5
0
 protected function createDefaultFilter()
 {
     $this->fq = array();
     if (!empty($this->config['includeTemplates'])) {
         $ids = Util\toNumericArray($this->config['includeTemplates']);
         if (!empty($ids)) {
             $this->fq[] = 'template_id:(' . implode(' OR ', $ids) . ')';
         }
     } elseif (!empty($this->config['excludeTemplates'])) {
         $ids = Util\toNumericArray($this->config['excludeTemplates']);
         if (!empty($ids)) {
             $this->fq[] = '!template_id:(' . implode(' OR ', $ids) . ')';
         }
     }
 }
Пример #6
0
 /**
  * delete a record by its id
  * @param  []int   $ids
  * @return boolean
  */
 public static function delete($ids)
 {
     $sql = 'DELETE from ' . static::getTableName() . ' WHERE `type` = $1 and id';
     if (is_scalar($ids)) {
         static::validateParamTypes(array('id' => $ids));
         DB\dbQuery($sql . ' = $2', array(static::$type, $ids));
     } else {
         $ids = Util\toNumericArray($ids);
         if (!empty($ids)) {
             DB\dbQuery($sql . ' IN (' . implode(',', $ids) . ')', static::$type);
         }
     }
     $rez = DB\dbAffectedRows() > 0;
     return $rez;
 }
Пример #7
0
 /**
  * get relative content paths for given file ids
  * path is relative to casebox files directory
  * @param  array $ids
  * @return array associative array (id => relative_content_path)
  */
 public static function getContentPaths($ids)
 {
     $rez = array();
     $ids = Util\toNumericArray($ids);
     if (!empty($ids)) {
         $sql = 'SELECT f.id, c.`path`, f.content_id
             FROM files f
             JOIN files_content c
                 ON f.content_id = c.id
             WHERE f.id in (' . implode(',', $ids) . ')';
         $res = DB\dbQuery($sql);
         while ($r = $res->fetch_assoc()) {
             $rez[$r['id']] = $r['path'] . DIRECTORY_SEPARATOR . $r['content_id'];
         }
         $res->close();
     }
     return $rez;
 }
Пример #8
0
 public function getData($id = false)
 {
     $rez = array('success' => true);
     if (empty(parent::getData($id))) {
         return $rez;
     }
     $params = array('pid' => $this->id, 'fq' => array('(template_type:object) OR (target_type:object)'), 'fl' => 'id,pid,name,template_id,cdate,cid', 'sort' => 'cdate', 'dir' => 'desc');
     $folderTemplates = \CB\Config::get('folder_templates');
     if (!empty($folderTemplates)) {
         $params['fq'][] = '!template_id:(' . implode(' OR ', Util\toNumericArray($folderTemplates)) . ')';
     }
     $s = new \CB\Search();
     $sr = $s->query($params);
     foreach ($sr['data'] as $d) {
         $d['ago_text'] = Util\formatAgoTime($d['cdate']);
         $d['user'] = @User::getDisplayName($d['cid']);
         $rez['data'][] = $d;
     }
     return $rez;
 }
Пример #9
0
 /**
  * This function is designed to prepeare all necessary nodes properties for graph rendering.
  *
  * used properties for graph:
  * id
  * ,$this->labelField - will be used as node label
  * ,hint = $this->hintField
  * ,date = $this->dateField
  * ,shape - node shape
  * ,style - custom node style
  * ,fillcolor
  * ,margin
  * ,penwith
  * ,leftSideNodes - for decisions with associated violations
  * ,rightSideNodes
  */
 private function prepareGraphNodes(&$nodesArray)
 {
     for ($i = 0; $i < sizeof($nodesArray); $i++) {
         /* define a reference for easy use */
         $node =& $nodesArray[$i];
         /* adjust title field if needed */
         $t = trim($node[$this->labelField]);
         $node[$this->hintField] = nl2br($t);
         $node[$this->labelField] = strlen($t) > 30 ? substr($t, 0, 30) . ' ...' : $t;
         /* adjusting date field format */
         if (!empty($node[$this->dateField])) {
             $node[$this->dateField] = substr($node[$this->dateField], 0, 10);
             $node[$this->dateField] = implode('.', array_reverse(explode('-', $node[$this->dateField])));
         }
         /* end of adjusting date field format */
         /* SETTING NODE STYLE (SHAPE AND COLOR) */
         /* getting node object */
         $o = Objects::getCachedObject($node['id']);
         $node['style'] = 'filled';
         $color = $o->getFieldValue('color', 0)['value'];
         if (!empty($color)) {
             $t = $o->getTemplate();
             $color = $t->formatValueForDisplay($t->getField('color'), $color, false);
             $node['fillcolor'] = @$this->colors[$color];
         } else {
             $node['fillcolor'] = $this->colors['gray'];
         }
         $inLinks = Util\toNumericArray($o->getFieldValue('in_links', 0)['value']);
         $outLinks = Util\toNumericArray($o->getFieldValue('out_links', 0)['value']);
         foreach ($inLinks as $inNode) {
             $this->links[$inNode][$node['id']] = 1;
         }
         foreach ($outLinks as $outNode) {
             $this->links[$node['id']][$outNode] = 1;
         }
         /* setting node shape */
         $node['shape'] = "box";
         //set default shape
         // $this->switchNodeShowTitles($node);
     }
 }
Пример #10
0
 public function getData($id = false)
 {
     $rez = array('success' => true, 'data' => array());
     parent::getData($id);
     $obj = $this->getObjectClass();
     if (!is_object($obj)) {
         return $rez;
     }
     $data = $obj->getData();
     $rez['data'] = array_intersect_key($data, array('id' => 1, 'name' => 1, 'template_id' => 1, 'cid' => 1, 'cdate' => 1, 'uid' => 1, 'udate' => 1, 'dstatus' => 1, 'did' => 1, 'ddate' => 1, 'size' => 1));
     $d =& $rez['data'];
     $pids = Util\toNumericArray($data['pids']);
     array_pop($pids);
     $d['pids'] = $d['path'] = implode('/', $pids);
     $arr = array(&$d);
     Search::setPaths($arr);
     $d['template_name'] = Objects::getName($d['template_id']);
     $sd = $obj->getSysData();
     $userId = User::getId();
     $d['subscription'] = 'ignore';
     if (!empty($sd['fu']) && in_array($userId, $sd['fu'])) {
         $d['subscription'] = 'watch';
         //follow
     }
     if (!empty($sd['wu']) && in_array($userId, $sd['wu'])) {
         $d['subscription'] = 'watch';
     }
     $d['cid_text'] = User::getDisplayName($d['cid']);
     $d['cdate_ago_text'] = Util\formatAgoTime($d['cdate']);
     $d['cdate'] = Util\dateMysqlToISO($d['cdate']);
     $d['udate'] = Util\dateMysqlToISO($d['udate']);
     $d['uid_text'] = User::getDisplayName($d['uid']);
     $d['udate_ago_text'] = Util\formatAgoTime($d['udate']);
     if (!empty($d['dstatus'])) {
         $d['did_text'] = User::getDisplayName($d['did']);
         $d['ddate_text'] = Util\formatAgoTime($d['ddate']);
     }
     return $rez;
 }
Пример #11
0
 /**
  * function to update parent followers when uploading a file
  * with this user
  * @return void
  */
 protected function updateParentFollowers()
 {
     $posd = $this->parentObj->getSysData();
     $newUserIds = array();
     $wu = empty($posd['wu']) ? array() : $posd['wu'];
     $uid = User::getId();
     if (!in_array($uid, $wu)) {
         $newUserIds[] = intval($uid);
     }
     //update only if new users added
     if (!empty($newUserIds)) {
         $wu = array_merge($wu, $newUserIds);
         $wu = Util\toNumericArray($wu);
         $posd['wu'] = array_unique($wu);
         $this->parentObj->updateSysData($posd);
     }
 }
Пример #12
0
 /**
  * generate html preview for a task
  * @param  int   $id task id
  * @return array
  */
 public function getPreviewBlocks()
 {
     $pb = parent::getPreviewBlocks();
     $data = $this->getData();
     $sd =& $data['sys_data'];
     $template = $this->getTemplate();
     $actionsLine = 'Actions<hr />';
     $dateLines = '';
     $ownerRow = '';
     $assigneeRow = '';
     $contentRow = '';
     //create actions line
     $flags = $this->getActionFlags();
     $actions = array();
     if (!empty($flags['complete'])) {
         $actions[] = '<a action="complete" class="task-action ib-done">' . L\get('Complete') . '</a>';
     }
     if (!empty($flags['close'])) {
         $actions[] = '<a action="close" class="task-action ib-done-all">' . L\get('Close') . '</a>';
     }
     if (!empty($flags['reopen'])) {
         $actions[] = '<a action="reopen" class="task-action ib-repeat">' . L\get('Reopen') . '</a>';
     }
     $actionsLine = '<div class="task-actions">' . implode(' ', $actions) . '</div>';
     //create date and status row
     $ed = $this->getEndDate();
     $status = $this->getStatus();
     if (!empty($ed)) {
         $endDate = Util\formatTaskTime($ed, !$sd['task_allday']);
         // $endDate = empty($sd['task_allday'])
         //     ? Util\formatDateTimePeriod($ed, null, @$_SESSION['user']['cfg']['timezone'])
         //     : Util\formatDatePeriod($ed, null, @$_SESSION['user']['cfg']['timezone']);
         $dateLines = '<tr><td class="prop-key">' . L\get('Due') . ':</td><td>' . $endDate . '</td></tr>';
         // $dateLine .= '<div class="date">' . $endDate . '</div>';
     }
     if (!empty($sd['task_d_closed'])) {
         $dateLines .= '<tr><td class="prop-key">' . L\get('Completed') . ':</td><td>' . Util\formatAgoTime($sd['task_d_closed']) . '</td></tr>';
     }
     //create owner row
     $v = $this->getOwner();
     if (!empty($v)) {
         $cn = User::getDisplayName($v);
         $cdt = Util\formatAgoTime($data['cdate']);
         $cd = Util\formatDateTimePeriod($data['cdate'], null, @$_SESSION['user']['cfg']['timezone']);
         $ownerRow = '<tr><td class="prop-key">' . L\get('Owner') . ':</td><td>' . '<table class="prop-val people"><tbody>' . '<tr><td class="user"><img class="photo32" src="photo/' . $v . '.jpg?32=' . User::getPhotoParam($v) . '" style="width:32px; height: 32px" alt="' . $cn . '" title="' . $cn . '"></td>' . '<td><b>' . $cn . '</b><p class="gr">' . L\get('Created') . ': ' . '<span class="dttm" title="' . $cd . '">' . $cdt . '</span></p></td></tr></tbody></table>' . '</td></tr>';
     }
     //create assignee row
     $v = $this->getFieldValue('assigned', 0);
     if (!empty($v['value'])) {
         $isOwner = $this->isOwner();
         $assigneeRow .= '<tr><td class="prop-key">' . L\get('TaskAssigned') . ':</td><td><table class="prop-val people"><tbody>';
         $v = Util\toNumericArray($v['value']);
         $dateFormat = \CB\getOption('long_date_format') . ' H:i:s';
         foreach ($v as $id) {
             $un = User::getDisplayName($id);
             $completed = $this->getUserStatus($id) == static::$USERSTATUS_DONE;
             $flags = $this->getActionFlags($id);
             $cdt = '';
             //completed date title
             $dateText = '';
             if ($completed && !empty($sd['task_u_d_closed'][$id])) {
                 $cdt = Util\formatMysqlDate($sd['task_u_d_closed'][$id], $dateFormat);
                 $dateText = ': ' . Util\formatAgoTime($sd['task_u_d_closed'][$id]);
             }
             $assigneeRow .= '<tr><td class="user"><div style="position: relative">' . '<img class="photo32" src="photo/' . $id . '.jpg?32=' . User::getPhotoParam($id) . '" style="width:32px; height: 32px" alt="' . $un . '" title="' . $un . '">' . ($completed ? '<img class="done icon icon-tick-circle" src="/css/i/s.gif" />' : "") . '</div></td><td><b>' . $un . '</b>' . '<p class="gr" title="' . $cdt . '">' . ($completed ? L\get('Completed') . $dateText . ($isOwner ? ' <a class="bt task-action click" action="markincomplete" uid="' . $id . '">' . L\get('revoke') . '</a>' : '') : L\get('waitingForAction') . ($isOwner ? ' <a class="bt task-action click" action="markcomplete" uid="' . $id . '">' . L\get('complete') . '</a>' : '')) . '</p></td></tr>';
         }
         $assigneeRow .= '</tbody></table></td></tr>';
     }
     //create description row
     $v = $this->getFieldValue('description', 0);
     if (!empty($v['value'])) {
         $tf = $template->getField('description');
         $v = $template->formatValueForDisplay($tf, $v);
         $contentRow = '<tr><td class="prop-val" colspan="2">' . $v . '</td></tr>';
     }
     //insert rows
     $p = $pb[0];
     $pos = strrpos($p, '<tbody>');
     $p = substr($p, $pos + 7);
     $pos = strrpos($p, '</tbody>');
     if ($pos !== false) {
         $p = substr($p, 0, $pos);
     }
     $pb[0] = $actionsLine . '<table class="obj-preview"><tbody>' . $dateLines . $p . $ownerRow . $assigneeRow . $contentRow . '<tbody></table>';
     return $pb;
 }
Пример #13
0
 /**
  * mark user notifications as read
  * @param  int   $userId
  * @param  int[] $ids
  * @return void
  */
 public static function markAsRead($userId, $ids)
 {
     //validate params
     if (!is_numeric($userId)) {
         trigger_error(L\get('ErroneousInputData'), E_USER_ERROR);
     }
     $ids = Util\toNumericArray($ids);
     if (!empty($ids)) {
         DB\dbQuery('UPDATE `' . static::$tableName . '`
             SET `read` = 1
             WHERE user_id = $1 AND id IN (' . implode(',', $ids) . ')', $userId) or die(DB\dbQueryError());
     }
 }
Пример #14
0
 protected static function getMenuRules()
 {
     $rez = Cache::get('CreateMenuRules', array());
     if (!empty($rez)) {
         return $rez;
     }
     $s = new Search();
     $ids = array();
     $sr = $s->query(array('fl' => 'id', 'template_types' => 'menu', 'skipSecurity' => true));
     foreach ($sr['data'] as $r) {
         $ids[] = $r['id'];
     }
     $arr = Objects::getCachedObjects($ids);
     foreach ($arr as $o) {
         $d = $o->getData()['data'];
         $rez[] = array('nids' => empty($d['node_ids']) ? array() : Util\toNumericArray($d['node_ids']), 'ntids' => empty($d['template_ids']) ? array() : Util\toNumericArray($d['template_ids']), 'ugids' => empty($d['user_group_ids']) ? array() : Util\toNumericArray($d['user_group_ids']), 'menu' => $d['menu']);
     }
     Cache::set('CreateMenuRules', $rez);
     return $rez;
 }
Пример #15
0
 /**
  * get children count for given item ids
  * @param  array $ids
  * @param  array $templateIds filter children by template ids
  * @return array associative array of children per id
  */
 public static function getChildCount($ids, $templateIds = false)
 {
     $rez = array();
     $ids = Util\toNumericArray($ids);
     if (empty($ids)) {
         return $rez;
     }
     if (empty($templateIds)) {
         $templateIds = '';
     } else {
         $templateIds = Util\toNumericArray($templateIds);
         if (!empty($templateIds)) {
             $templateIds = ' AND template_id in (' . implode(',', $templateIds) . ')';
         }
     }
     $sql = 'SELECT pid, count(*) `children`
         FROM tree
         WHERE pid in (' . implode(',', $ids) . ')
             AND dstatus = 0' . $templateIds . '
         GROUP BY pid';
     $res = DB\dbQuery($sql);
     while ($r = $res->fetch_assoc()) {
         $rez[$r['pid']] = $r['children'];
     }
     $res->close();
     return $rez;
 }
Пример #16
0
 /**
  * mark user notifications as read
  * @param  int   $userId
  * @param  int[] $ids
  * @return void
  */
 public static function markAsRead($userId, $ids)
 {
     //validate params
     \CB\raiseErrorIf(!is_numeric($userId), 'ErroneousInputData');
     $ids = Util\toNumericArray($ids);
     if (!empty($ids)) {
         DB\dbQuery('UPDATE `' . static::getTableName() . '`
             SET `read` = 1
             WHERE user_id = $1 AND id IN (' . implode(',', $ids) . ')', $userId) or die(DB\dbQueryError());
     }
 }
Пример #17
0
 /**
  * prepare a given value for solr according to its type
  * @param  varchar $type  (checkbox,combo,date,datetime,float,html,int,memo,_objects,text,time,timeunits,varchar)
  * @param  variant $value
  * @return variant
  */
 protected function prepareValueforSolr($type, $value)
 {
     if (empty($value) || empty($value['value'])) {
         return null;
     }
     $value = $value['value'];
     switch ($type) {
         case 'boolean':
             //not used
         //not used
         case 'checkbox':
             $value = empty($value) ? false : true;
             break;
         case 'date':
         case 'datetime':
             if (!empty($value)) {
                 //check if there is only date, without time
                 if (strlen($value) == 10) {
                     $value .= 'T00:00:00';
                 }
                 if (substr($value, -1) != 'Z') {
                     $value .= 'Z';
                 }
                 if (@$value[10] == ' ') {
                     $value[10] = 'T';
                 }
             }
             break;
             /** time values are stored as seconds representation in solr */
         /** time values are stored as seconds representation in solr */
         case 'time':
             if (!empty($value)) {
                 $a = explode(':', $value);
                 @($value = $a[0] * 3600 + $a[1] * 60 + $a[2]);
             }
             break;
         case 'combo':
         case 'int':
         case '_objects':
             $arr = Util\toNumericArray($value);
             $value = array();
             //remove zero values
             foreach ($arr as $v) {
                 if (!empty($v)) {
                     $value[] = $v;
                 }
             }
             $value = array_unique($value);
             if (empty($value)) {
                 $value = null;
             } elseif (sizeof($value) == 1) {
                 //set just value if 1 element array
                 $value = array_shift($value);
             }
             break;
         case 'html':
             $value = strip_tags($value);
             break;
     }
     return $value;
 }
Пример #18
0
 /**
  * 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;
 }
Пример #19
0
 /**
  * get the menu config for a given path or id
  * @param  varchar | int $path path string or node id
  * @return [type]        [description]
  */
 public static function getMenuForPath($path)
 {
     $rez = '';
     //get item path if id specified
     if (is_numeric($path)) {
         $tmp = \CB\Path::getPath($path);
         $path = '/' . $tmp['path'];
     }
     if (is_string($path)) {
         $path = explode('/', $path);
     }
     $path = array_reverse(array_filter($path, 'is_numeric'));
     $path = Util\toNumericArray($path);
     // get templates for each path elements
     $nodeTemplate = array();
     $res = DB\dbQuery('SELECT id, template_id
         FROM tree
         WHERE id in (0' . implode(',', $path) . ')') or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         $nodeTemplate[$r['id']] = $r['template_id'];
     }
     $res->close();
     //get db menu into variable
     $menu = array();
     $res = DB\dbQuery('SELECT
             node_ids `nids`
             ,node_template_ids `ntids`
             ,user_group_ids `ugids`
             ,menu
         FROM menu') or die(DB\dbQueryError());
     while ($r = $res->fetch_assoc()) {
         $r['nids'] = Util\toNumericArray($r['nids']);
         $r['ntids'] = Util\toNumericArray($r['ntids']);
         $r['ugids'] = Util\toNumericArray($r['ugids']);
         $menu[] = $r;
     }
     $res->close();
     $ugids = $_SESSION['user']['groups'];
     $ugids[] = $_SESSION['user']['id'];
     // we have 3 main criterias for detecting needed menu:
     //  - user_group_ids - records for specific users or groups
     //  - node_ids
     //  - template_ids
     //
     // we'll iterate the path from the end and detect the menu
     $lastWeight = 0;
     for ($i = 0; $i < sizeof($path); $i++) {
         //firstly we'll check if we find a menu row with id or template of the node
         foreach ($menu as $m) {
             $weight = 0;
             if (in_array($path[$i], $m['nids'])) {
                 $weight += 50;
             } elseif (empty($m['nids'])) {
                 $weight += 1;
             } else {
                 //skip this record because it contain nids and not contain this node id
                 continue;
             }
             if (in_array($nodeTemplate[$path[$i]], $m['ntids'])) {
                 $weight += 50;
             } elseif (empty($m['ntids'])) {
                 $weight += 1;
             } else {
                 //skip this record because it has ntids specified and not contain this node template id
                 continue;
             }
             if (empty($m['ugids'])) {
                 $weight += 1;
             } else {
                 $int = array_intersect($ugids, $m['ugids']);
                 if (empty($int)) {
                     continue;
                 } else {
                     $weight += 10;
                 }
             }
             if ($weight > $lastWeight) {
                 $lastWeight = $weight;
                 $rez = $m['menu'];
             }
         }
         //if nid matched or template matched then dont iterate further
         if ($lastWeight > 50) {
             return $rez;
         }
     }
     return $rez;
 }
Пример #20
0
 /**
  * function to update parent followers when adding a comment
  * with this user and referenced users from comment
  * @return void
  */
 protected function updateParentFollowers()
 {
     $p =& $this->data;
     $posd = $this->parentObj->getSysData();
     $newUserIds = array();
     $posd['lastComment'] = array('user_id' => User::getId(), 'date' => Util\dateMysqlToISO('now'));
     $fu = empty($posd['fu']) ? array() : $posd['fu'];
     $uid = User::getId();
     if (!in_array($uid, $fu)) {
         $newUserIds[] = intval($uid);
     }
     //analize comment text and get referenced users
     if (preg_match_all('/@([^@\\s,!\\?]+)/', $p['data']['_title'], $matches, PREG_SET_ORDER)) {
         foreach ($matches as $match) {
             $uid = DM\User::getIdByName($match[1]);
             if (is_numeric($uid) && !in_array($uid, $fu) && !in_array($uid, $newUserIds)) {
                 $newUserIds[] = $uid;
             }
         }
     }
     //update only if new users added
     if (!empty($newUserIds)) {
         $fu = array_merge($fu, $newUserIds);
         $fu = Util\toNumericArray($fu);
         $posd['fu'] = array_unique($fu);
     }
     //always update sys_data to change lastComment date
     $this->parentObj->updateSysData($posd);
 }
Пример #21
0
 /**
  * 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;
 }
Пример #22
0
 /**
  * getActivityData (followers, watchers)
  * @param  array &$d object data
  * @return array
  */
 protected static function getActivityData(&$d)
 {
     $rez = array();
     $userId = User::getId();
     $rez['fu'] = array();
     if (!empty($d['sys_data']['fu'])) {
         $rez['fu'] = array_merge($rez['fu'], $d['sys_data']['fu']);
     }
     $rez['fu'] = array_unique($rez['fu']);
     //remove current user, that caused the action
     $rez['fu'] = array_diff($rez['fu'], array($userId));
     $rez['fu'] = Util\toNumericArray($rez['fu']);
     if (!empty($d['sys_data']['wu'])) {
         $rez['wu'] = array_diff($d['sys_data']['wu'], array($userId));
         $rez['wu'] = Util\toNumericArray($rez['wu']);
     }
     return $rez;
 }
Пример #23
0
 /**
  * mark user notifications as seen
  * @param  varchar | array $id     notification ids
  * @param  int             $userId
  * @return void
  */
 public static function markAsSeen($ids, $userId)
 {
     \CB\raiseErrorIf(!is_numeric($userId), 'ErroneousInputData');
     $ids = Util\toNumericArray($ids);
     if (!empty($ids)) {
         DB\dbQuery('UPDATE `' . static::getTableName() . '`
             SET `seen` = 1
             WHERE user_id = $1
                 AND id IN (' . implode(',', $ids) . ')
                 AND seen = 0', $userId) or die(DB\dbQueryError());
     }
 }
Пример #24
0
 /**
  * method to get multiple object properties from solr
  * Multilanguage plugin works also
  *
  * @param  array | string $ids
  * @param  string         $fieldList
  * @return array          associative array of properties per id
  */
 public static function getObjects($ids, $fieldList = 'id,name')
 {
     $rez = array();
     $ids = Util\toNumericArray($ids);
     if (!empty($ids)) {
         $chunks = array_chunk($ids, 200);
         //connect or get solr service connection
         $conn = Cache::get('solr_service');
         if (empty($conn)) {
             $conn = new Solr\Service();
             Cache::set('solr_service', $conn);
         }
         //execute search
         try {
             foreach ($chunks as $chunk) {
                 $params = array('defType' => 'dismax', 'q.alt' => '*:*', 'fl' => $fieldList, 'fq' => array('id:(' . implode(' OR ', $chunk) . ')'));
                 $inputParams = array('ids' => $chunk);
                 $eventParams = array('params' => &$params, 'inputParams' => &$inputParams);
                 \CB\fireEvent('beforeSolrQuery', $eventParams);
                 $searchRez = $conn->search('', 0, 200, $params);
                 if (!empty($searchRez->response->docs)) {
                     foreach ($searchRez->response->docs as $d) {
                         $rd = array();
                         foreach ($d as $fn => $fv) {
                             $rd[$fn] = $fv;
                         }
                         $rez[$d->id] = $rd;
                     }
                 }
                 $eventParams['result'] = array('data' => &$rez);
                 \CB\fireEvent('solrQuery', $eventParams);
             }
         } catch (\Exception $e) {
             throw new \Exception("An error occured in getObjects: \n\n {$e->__toString()}");
         }
     }
     return $rez;
 }
Пример #25
0
 /**
  * method to get multiple object properties from solr
  * Multilanguage plugin works also
  *
  * @param  array | string $ids
  * @param  string         $fieldList
  * @return array          associative array of properties per id
  */
 public static function getObjects($ids, $fieldList = 'id,name')
 {
     $rez = array();
     $ids = Util\toNumericArray($ids);
     if (!empty($ids)) {
         $chunks = array_chunk($ids, 200);
         //execute search
         try {
             foreach ($chunks as $chunk) {
                 $params = array('fl' => $fieldList, 'facet' => false, 'skipSecurity' => true, 'fq' => array('id:(' . implode(' OR ', $chunk) . ')'));
                 $search = new Search();
                 $sr = $search->query($params);
                 if (!empty($sr['data'])) {
                     foreach ($sr['data'] as &$d) {
                         $rez[$d['id']] = $d;
                     }
                 }
             }
         } catch (\Exception $e) {
             throw new \Exception("An error occured in getObjects: \n\n {$e->__toString()}");
         }
     }
     return $rez;
 }
Пример #26
0
 /**
  * get objects from cache or loads them and store in cache
  * @param  array $ids
  * @return array
  */
 public static function getCachedObjects($ids)
 {
     $ids = Util\toNumericArray($ids);
     $rez = array();
     $toLoad = array();
     foreach ($ids as $id) {
         //verify if already have cached result
         $var_name = 'Objects[' . $id . ']';
         if (\CB\Cache::exist($var_name)) {
             $rez[$id] = \CB\Cache::get($var_name);
         } else {
             $toLoad[] = $id;
         }
     }
     if (!empty($toLoad)) {
         $tc = Templates\SingletonCollection::getInstance();
         $data = DataModel\Objects::read($toLoad);
         foreach ($data as $objData) {
             $var_name = 'Objects[' . $objData['id'] . ']';
             $o = static::getCustomClassByType($tc->getType($objData['template_id']));
             if (!empty($o)) {
                 $o->setData($objData);
                 \CB\Cache::set($var_name, $o);
                 $rez[$objData['id']] = $o;
             }
         }
     }
     return $rez;
 }
Пример #27
0
 /**
  * merge files
  * To be reviewed
  *
  * @param  int  $ids
  * @return json response
  */
 public function merge($ids)
 {
     if (!is_array($ids)) {
         return array('success' => false);
     }
     $ids = Util\toNumericArray($ids);
     if (sizeof($ids) < 2) {
         return array('success' => false);
     }
     $to_id = null;
     $res = DB\dbQuery('SELECT id
         FROM tree
         WHERE id IN (' . implode(', ', $ids) . ')
         ORDER BY udate DESC, id DESC');
     if ($r = $res->fetch_assoc()) {
         $to_id = $r['id'];
     }
     $res->close();
     DB\dbQuery('UPDATE files_versions
         SET file_id = $1
         WHERE file_id IN (' . implode(', ', $ids) . ')', $to_id);
     $res = DB\dbQuery('INSERT INTO files_versions (file_id, content_id, `date`, name, cid, uid, cdate, udate)
             SELECT $1
                 ,content_id
                 ,`date`
                 ,name
                 ,cid
                 ,uid
                 ,cdate
                 ,udate
             FROM files
             WHERE id <> $1
                 AND id in(' . implode(',', $ids) . ')', $to_id);
     DB\dbQuery('UPDATE tree
         SET did = $2
                 , dstatus = 1
                 , updated = (updated | 1)
         WHERE id <> $1
             AND id IN (' . implode(', ', $ids) . ')', array($to_id, User::getId()));
     DM\Tree::update(array('id' => $to_id, 'updated' => 1));
     $ids = array_diff($ids, array($to_id));
     // Objects::updateCaseUpdateInfo($id);
     Solr\Client::runCron();
     return array('success' => true, 'rez' => $ids);
 }
Пример #28
0
 protected function getObjectWarmIds(&$customColumns, &$objClass, &$solrData)
 {
     $rez = array();
     $template = $objClass->getTemplate();
     foreach ($customColumns as &$col) {
         //$fieldName
         //detect field name
         $customField = $col['fieldName'];
         $templateField = $template->getField($customField);
         // $templateField = null;
         $values = array();
         if (!empty($col['solr_column_name'])) {
             $values = array(@$solrData[$col['solr_column_name']]);
         } else {
             //default
             $values = isset($solrData[$customField]) ? array($solrData[$customField]) : $objClass->getFieldValue($customField);
         }
         if (!empty($templateField) && in_array($templateField['type'], array('_objects'))) {
             foreach ($values as $value) {
                 $value = is_array($value) ? @$value['value'] : $value;
                 $value = Util\toNumericArray($value);
                 foreach ($value as $v) {
                     $rez[] = $v;
                 }
             }
         }
     }
     return $rez;
 }
Пример #29
0
 /**
  * recursive objects moving or copying
  * @param  int|array $objectIds source object ids
  * @param  int       $targetId  target id
  * @return array     processed ids
  */
 public function doRecursiveAction($action, $objectIds, $targetId)
 {
     $rez = array();
     if (!is_array($objectIds)) {
         $objectIds = Util\toNumericArray($objectIds);
     }
     if (empty($objectIds)) {
         return false;
     }
     foreach ($objectIds as $objectId) {
         $newId = null;
         // check if object with same name exist in target
         $existentTargetId = $this->overwriteCheck($objectId, $targetId);
         if ($existentTargetId == false) {
             // copy by creating a new object in target or just move
             switch ($action) {
                 case 'copy':
                     $newId = $this->objectsClass->copy($objectId, $targetId);
                     break;
                 case 'move':
                     $newId = $this->objectsClass->move($objectId, $targetId);
                     break;
             }
         } else {
             switch ($action) {
                 case 'copy':
                     $newId = $this->objectsClass->copy($objectId, $targetId, $existentTargetId);
                     break;
                 case 'move':
                     $newId = $this->objectsClass->move($objectId, $targetId, $existentTargetId);
                     break;
             }
         }
         // skip childs copy if object not copied/moved
         if (empty($newId)) {
             continue;
         }
         $rez[] = $newId;
         // skip childs moving if moved object is itself
         if ($newId == $objectId) {
             continue;
         }
         // select direct childs of the objects and make a recursive call with them
         $res = DB\dbQuery('SELECT t.id
             FROM tree t
             JOIN tree_info ti ON
                 t.id = ti.id ' . $this->securitySetsFilter . '
             WHERE t.pid = $1 AND t.dstatus = 0', $objectId);
         $childIds = array();
         while ($r = $res->fetch_assoc()) {
             $childIds[] = $r['id'];
         }
         $res->close();
         $this->doRecursiveAction($action, $childIds, $newId);
     }
     return $rez;
 }
Пример #30
0
 /**
  * function to update parent followers when adding a comment
  * with this user and referenced users from comment
  * @return void
  */
 protected function updateParentFollowers()
 {
     $p =& $this->data;
     $po = $this->getParentObject();
     $posd = $po->getSysData();
     $newUserIds = array();
     $posd['lastComment'] = array('user_id' => User::getId(), 'date' => Util\dateMysqlToISO('now'));
     $wu = empty($posd['wu']) ? array() : $posd['wu'];
     $uid = User::getId();
     if (!in_array($uid, $wu)) {
         $newUserIds[] = intval($uid);
     }
     //analize comment text and get referenced users
     $this->lastMentionedUserIds = Util\getReferencedUsers($p['data']['_title']);
     foreach ($this->lastMentionedUserIds as $uid) {
         if (!in_array($uid, $wu)) {
             $newUserIds[] = $uid;
         }
     }
     //update only if new users added
     if (!empty($newUserIds)) {
         $wu = array_merge($wu, $newUserIds);
         $wu = Util\toNumericArray($wu);
         $posd['wu'] = array_unique($wu);
     }
     //always update sys_data to change lastComment date
     $po->updateSysData($posd);
 }