示例#1
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);
 }
示例#2
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);
 }
示例#3
0
 public static function deleteByNodeId($nodeId, $userId = false)
 {
     if ($userId == false) {
         $userId = \CB\User::getId();
     }
     DB\dbQuery('DELETE FROM ' . static::getTableName() . ' WHERE user_id = $1 AND node_id = $2', array($userId, $nodeId)) or die(DB\dbQueryError());
     $rez = DB\dbAffectedRows() > 0;
     return $rez;
 }
示例#4
0
/**
 * save attachments array for a given object id
 * @param  int $objectId
 * @param  array &$attachments attachments array as from getMailContentAndAtachment
 * @return void
 */
function saveObjectAttachments($objectId, &$attachments)
{
    $filesApiObject = new \CB\Api\Files();
    foreach ($attachments as $d) {
        if (empty($d['attachment'])) {
            continue;
        }
        //safe content to a temporary file
        $tmpName = tempnam(sys_get_temp_dir(), 'cbMailAtt');
        file_put_contents($tmpName, $d['content']);
        //call the api method
        $filesApiObject->upload(array('pid' => $objectId, 'localFile' => $tmpName, 'oid' => \CB\User::getId(), 'filename' => $d['filename'], 'content-type' => $d['content-type'], 'fileExistAction' => 'autorename'));
    }
}
示例#5
0
 /**
  * set complete or incomplete status for a task responsible user
  * @param array $p params
  */
 public function setUserStatus($p)
 {
     $rez = array('success' => true, 'id' => $p['id']);
     $obj = Objects::getCachedObject($p['id']);
     $data = $obj->getData();
     if (User::getId() != $data['cid'] && !Security::isAdmin()) {
         throw new \Exception(L\get('Access_denied'));
     }
     if ($obj->getUserStatus($p['user_id']) == Objects\Task::$USERSTATUS_NONE) {
         throw new \Exception(L\get('Wrong_id'));
     }
     $status = $p['status'] == 1 ? Objects\Task::$USERSTATUS_DONE : Objects\Task::$USERSTATUS_ONGOING;
     $obj->setUserStatus($status, $p['user_id']);
     // $obj->updateSysData();
     $this->afterUpdate($p['id']);
     return $rez;
 }
示例#6
0
 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;
 }
示例#7
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;
 }
示例#8
0
 /**
  * change user status for loaded task
  * @param  array   $p params
  * @return boolean
  */
 public function setUserStatus($status, $userId = false)
 {
     $rez = false;
     $action = '';
     $currentUserId = User::getId();
     if ($userId == false) {
         $userId = $currentUserId;
     }
     $d =& $this->data;
     $sd =& $d['sys_data'];
     switch ($status) {
         case static::$USERSTATUS_ONGOING:
             if (in_array($userId, $sd['task_u_done'])) {
                 $sd['task_u_done'] = array_diff($sd['task_u_done'], array($userId));
                 $sd['task_u_ongoing'][] = $userId;
                 unset($sd['task_u_d_closed'][$userId]);
                 $rez = true;
                 $action = $currentUserId == $userId ? 'reopen' : 'completion_decline';
             }
             break;
         case static::$USERSTATUS_DONE:
             if (in_array($userId, $sd['task_u_ongoing'])) {
                 $sd['task_u_ongoing'] = array_diff($sd['task_u_ongoing'], array($userId));
                 $sd['task_u_done'][] = $userId;
                 $sd['task_u_d_closed'][$userId] = date(DATE_ISO8601);
                 $rez = true;
                 $action = $currentUserId == $userId ? 'complete' : 'completion_on_behalf';
             }
             break;
     }
     if ($rez) {
         $this->checkAutoclose();
         $this->logAction($action, array('old' => &$this, 'forUserId' => $userId));
         // $this->updateSysData();
     }
     return $rez;
 }
示例#9
0
 /**
  * mark all unread user notifications  as read
  * @return json response
  */
 public function markAllAsRead()
 {
     DM\Notifications::markAllAsRead(User::getId());
     return array('success' => true);
 }
示例#10
0
 /**
  * set subscription to an object for current user
  * @param array $p
  *        [
  *            int objectId
  *            varchar type      (follow, watch, ignore)
  *        ]
  * return array     json responce
  */
 public function setSubscription($p)
 {
     //validate input params
     if (empty($p['objectId']) || !is_numeric($p['objectId']) || empty($p['type']) || !in_array($p['type'], array('follow', 'watch', 'ignore'))) {
         throw new \Exception(L\get('Wrong_input_data'));
     }
     //set subscription
     $userId = User::getId();
     $obj = $this->getCachedObject($p['objectId']);
     $sd = $obj->getSysData();
     $fu = empty($sd['fu']) ? array() : $sd['fu'];
     $wu = empty($sd['wu']) ? array() : $sd['wu'];
     switch ($p['type']) {
         case 'follow':
             $sd['wu'] = array_diff($wu, array($userId));
             $sd['fu'] = array_merge(array_diff($fu, array($userId)), array($userId));
             break;
         case 'watch':
             $sd['fu'] = array_diff($fu, array($userId));
             $sd['wu'] = array_merge(array_diff($wu, array($userId)), array($userId));
             break;
         case 'ignore':
             $sd['fu'] = array_diff($fu, array($userId));
             $sd['wu'] = array_diff($wu, array($userId));
             break;
     }
     $obj->updateSysData($sd);
     return array('success' => true);
 }
示例#11
0
文件: User.php 项目: sebbie42/casebox
 private static function setUserConfig($cfg, $userId = false)
 {
     if ($userId === false) {
         $userId = User::getId();
     }
     DM\Users::update(array('id' => $userId, 'cfg' => Util\jsonEncode($cfg)));
 }
示例#12
0
 /**
  * Check if current loged user is owner for given user id
  *
  * @param  int     $userId
  * @return boolean
  */
 public static function isUsersOwner($userId)
 {
     return User::getId() == DM\User::getOwnerId($userId);
 }
示例#13
0
 public static function getGridViewState($guid)
 {
     $rez = array();
     $res = DB\dbQuery('SELECT cfg
         FROM tree_user_config
         WHERE  user_id = $1 and guid = $2', array(User::getId(), $guid));
     if ($r = $res->fetch_assoc()) {
         $rez = Util\toJSONArray($r['cfg']);
     }
     $res->close();
     //backward compatibility to extjs3
     if (!empty($rez['sort']['field']) && empty($rez['sort']['property'])) {
         $rez['sort']['property'] = $rez['sort']['field'];
     }
     return $rez;
 }
示例#14
0
文件: Task.php 项目: sebbie42/casebox
 /**
  *  get action flags that a user can do to task
  * @param  int   $userId
  * @return array
  */
 public function getActionFlags($userId = false)
 {
     if ($userId === false) {
         $userId = User::getId();
     }
     $isAdmin = \CB\Security::isAdmin($userId);
     $isOwner = $this->isOwner($userId);
     $isClosed = $this->isClosed();
     $canEdit = !$isClosed && ($isAdmin || $isOwner);
     $rez = array('close' => $canEdit, 'reopen' => $isClosed && $isOwner, 'complete' => !$isClosed && $this->getUserStatus($userId) == static::$USERSTATUS_ONGOING);
     return $rez;
 }
示例#15
0
 /**
  * add action to log
  * @param  varchar $type
  * @param  array   $params
  * @return void
  */
 protected function logAction($type, $params = array())
 {
     if (!Cache::get('disable_logs', false) && !Config::getFlag('disableActivityLog')) {
         $params['type'] = $type;
         $obj =& $this;
         if (empty($params['new'])) {
             $params['new'] =& $this;
         } else {
             $obj =& $params['new'];
         }
         $logActionId = Log::add($params);
         $uid = User::getId();
         //add action to object sys_data
         $data = $obj->getData();
         $lastAction = $obj->getLastActionData();
         if ($lastAction['type'] != $type) {
             $lastAction = array('type' => $type, 'time' => Util\dateMysqlToISO('now'), 'users' => array());
         }
         /*$sysData = empty($data['sys_data'])
                         ? $this->getSysData()
                         : $data['sys_data'];
         
                     $lastAction = array(
                         'type' => $type
                         ,'time' => Util\dateMysqlToISO('now')
                         ,'users' => array()
                     );
         
                     if (!empty($sysData['lastAction']) &&
                         ($sysData['lastAction']['type'] == $type)
                     ) {
                         $lastAction['users'] = $sysData['lastAction']['users'];
                     } /**/
         unset($lastAction['users'][$uid]);
         $lastAction['users'][$uid] = $logActionId;
         $obj->setSysDataProperty('lastAction', $lastAction);
     }
 }
示例#16
0
文件: File.php 项目: sebbie42/casebox
 /**
  * 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);
     }
 }
示例#17
0
 /**
  * replace possible variables in a filter array for solr query
  * @param  array reference &$filterArray
  * @return void
  */
 protected function replaceFilterVars(&$filterArray)
 {
     //
     foreach ($filterArray as $key => $value) {
         $filterArray[$key] = str_replace('$activeUserId', User::getId(), $value);
     }
 }
示例#18
0
文件: Tree.php 项目: sebbie42/casebox
 /**
  * copy a source record under given $pid
  * @param  array $sourceId
  * @param  array $pid
  * @return int   created record id
  */
 public static function copy($sourceId, $pid)
 {
     DB\dbQuery('INSERT INTO `tree`
             (`id`
             ,`pid`
             ,`user_id`
             ,`system`
             ,`type`
             ,`template_id`
             ,`tag_id`
             ,`target_id`
             ,`name`
             ,`date`
             ,`date_end`
             ,`size`
             ,`is_main`
             ,`cfg`
             ,`inherit_acl`
             ,`cid`
             ,`cdate`
             ,`uid`
             ,`udate`
             ,`updated`
             ,`oid`
             ,`did`
             ,`ddate`
             ,`dstatus`)
         SELECT
             NULL
             ,$2
             ,`user_id`
             ,`system`
             ,`type`
             ,`template_id`
             ,`tag_id`
             ,`target_id`
             ,`name`
             ,`date`
             ,`date_end`
             ,`size`
             ,`is_main`
             ,`cfg`
             ,`inherit_acl`
             ,`cid`
             ,`cdate`
             ,$3
             ,CURRENT_TIMESTAMP
             ,1
             ,`oid`
             ,`did`
             ,`ddate`
             ,`dstatus`
         FROM `tree` t
         WHERE id = $1', array($sourceId, $pid, User::getId()));
     return DB\dbLastInsertId();
 }
示例#19
0
 /**
  * Rename group
  */
 public function renameGroup($p)
 {
     if (!User::isVerified()) {
         return array('success' => false, 'verify' => true);
     }
     $title = Purify::humanName($p['title']);
     if (empty($title)) {
         throw new \Exception(L\get('Wrong_input_data'));
     }
     $id = $this->extractId($p['id']);
     if (!Security::canEditUser($id)) {
         throw new \Exception(L\get('Access_denied'));
     }
     DB\dbQuery('UPDATE users_groups
         SET name = $2, uid = $3
         WHERE id = $1 AND type = 1', array($id, $title, User::getId()));
     return array('success' => true, 'title' => $title);
 }
示例#20
0
 protected function getAssigneeTasks()
 {
     $p = $this->requestParams;
     $p['fq'] = $this->fq;
     $p['fq'][] = 'cid:' . User::getId();
     $p['fq'][] = 'task_status:[1 TO 2]';
     $user_id = substr($this->lastNode->id, 3);
     $p['fq'][] = 'task_u_ongoing:' . $user_id;
     $s = new \CB\Search();
     $sr = $s->query($p);
     return $sr;
 }
示例#21
0
 /**
  * function to check if a user cam manage task
  *
  * This function returns true if specified user can manage/update specified task.
  * User can manage a task if he is Administrator, Creator of the task
  * or is one of the responsible task users.
  *
  * @param  int     $taskId id of the task to be checked
  * @param  int     $userId id of the user to be checked
  * @return boolean returns true in case of the user can manage the task
  */
 public static function canManageTask($taskId, $userId = false)
 {
     $rez = false;
     if ($userId == false) {
         $userId = User::getId();
     }
     $task = Objects::getCachedObject($taskId);
     $data = $task->getData();
     $rez = $data['cid'] == $userId || in_array($userId, $data['sys_data']['task_u_ongoing']) || in_array($userId, $data['sys_data']['task_u_done']);
     if (!$rez) {
         $rez = Security::isAdmin($userId);
     }
     return $rez;
 }
 /**
  * get last notification for current user,
  * mark it as read and check the result.
  * Mark all as read
  *
  * @return void
  */
 protected function checkMarkingNotificationsAsRead()
 {
     $userId = \CB\User::getId();
     $n = $this->getLastNotification($userId);
     $this->assertTrue(!empty($n) && $n['read'] == '0', 'Last notification read or empty');
     $api = new \CB\Api\Notifications();
     //mark last notification as read
     $r = $api->markAsRead(array('ids' => $n['ids']));
     $this->assertTrue($r['success'] == true, 'Error marking notification as read.');
     //read the notification again and check the result
     $n = $this->getLastNotification($userId);
     $this->assertTrue(!empty($n) && $n['read'] == '1', 'Last notification not marked as read');
     //mark all as read
     $r = $api->markAllAsRead();
     $this->assertTrue($r['success'] == true, 'Error marking all notification as read.');
 }
示例#23
0
 protected function createDefaultFilter()
 {
     $this->fq = array('did:' . User::getId());
 }
示例#24
0
 /**
  * get assign security sets to filters
  * dont check if 'skipSecurity = true'
  * it's used in Objects fields where we show all nodes
  * without permission filtering
  * @param  array   &$p
  * @return varchar
  */
 protected function getSecuritySetsParam(&$p)
 {
     $rez = '';
     if (!Security::isAdmin() && empty($p['skipSecurity'])) {
         $pids = false;
         if (!empty($p['pid'])) {
             $pids = $p['pid'];
         } elseif (!empty($p['pids'])) {
             $pids = $p['pids'];
         }
         $sets = Security::getSecuritySets(false, 5, $pids);
         if (!empty($sets)) {
             $rez = 'security_set_id:(' . implode(' OR ', $sets) . ') OR oid:' . User::getId();
         } else {
             //for created users that doesnt belong to any group
             //and dont have any security sets associated
             $rez = '!security_set_id:[* TO *]';
         }
     }
     return $rez;
 }
示例#25
0
 /**
  * copy file data, but without versions. Should we copy versions also?
  * @param  int  $sourceId
  * @param  int  $targetId
  * @return void
  */
 public static function copy($sourceId, $targetId)
 {
     DB\dbQuery('INSERT INTO `files`
             (`id`
             ,`content_id`
             ,`date`
             ,`name`
             ,`title`
             ,`cid`
             ,`uid`
             ,`cdate`
             ,`udate`)
         SELECT
             $2
             ,`content_id`
             ,`date`
             ,`name`
             ,`title`
             ,`cid`
             ,$3
             ,`cdate`
             ,CURRENT_TIMESTAMP
         FROM `files`
         WHERE id = $1', array($sourceId, $targetId, User::getId()));
 }
示例#26
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);
 }
示例#27
0
文件: Log.php 项目: youprofit/casebox
 /**
  * add/update record into solr
  * @param array $p action params
  */
 private static function addSolrRecord(&$p)
 {
     $solr = static::getSolrLogConnection();
     if (empty($solr)) {
         return;
     }
     $data = empty($p['new']) ? empty($p['old']) ? $p['data'] : $p['old']->getData() : $p['new']->getData();
     $fu = @$p['activityData']['fu'];
     $wu = @$p['activityData']['wu'];
     $record = array('id' => Config::get('core_name') . '_' . $p['action_id'], 'core_id' => Config::get('core_id'), 'action_id' => $p['action_id'], 'action_type' => $p['type'], 'action_date' => date('Y-m-d\\TH:i:s\\Z'), 'user_id' => User::getId(), 'object_id' => $data['id'], 'object_pid' => empty($data['pid']) ? null : $data['pid'], 'object_pids' => $p['logData']['pids'], 'object_data' => Util\jsonEncode($p['logData']));
     //delete empty values because solr raises exception when sending empty values for ints
     foreach ($record as $k => $v) {
         if (empty($v)) {
             unset($record[$k]);
         }
     }
     $record['dstatus'] = 0;
     $record['system'] = 0;
     $rez = $solr->addDocument($record);
     $solr->commit();
 }