Esempio n. 1
0
 public function getName($id = false)
 {
     if ($id === false) {
         $id = $this->id;
     }
     switch ($id) {
         case 'tasks':
             return L\get('Tasks');
         case 2:
             return L\get('AssignedToMe');
         case 3:
             return L\get('Created');
         case 4:
             return lcfirst(L\get('Overdue'));
         case 5:
             return lcfirst(L\get('Ongoing'));
         case 6:
             return lcfirst(L\get('Closed'));
         case 'assignee':
             return lcfirst(L\get('Assignee'));
         default:
             if (substr($id, 0, 3) == 'au_') {
                 return \CB\User::getDisplayName(substr($id, 3));
             }
     }
     return 'none';
 }
Esempio n. 2
0
 public function getName($id = false)
 {
     $rez = 'no name';
     if ($id === false) {
         $id = $this->id;
     }
     if (!empty($id) && is_numeric($id)) {
         $facetConfig = $this->getFacetFieldConfig($this->getClassDepth() - 1);
         switch (@$facetConfig['type']) {
             case 'users':
                 $rez = User::getDisplayName($id);
                 break;
             case 'varchar':
                 $rez = $id;
                 break;
             default:
                 $rez = Objects::getName($id);
         }
     } else {
         switch ($id) {
             case 'root':
                 $rez = parent::getName('root');
                 break;
         }
     }
     return $rez;
 }
Esempio n. 3
0
 public function getClientData()
 {
     $rez = array('f' => $this->field, 'title' => $this->getTitle(), 'items' => array());
     foreach ($this->solrData as $k => $v) {
         $rez['items'][$k] = array('name' => User::getDisplayName($k), 'count' => $v);
     }
     return $rez;
 }
Esempio n. 4
0
 public function beforeLock($path, \Sabre\DAV\Locks\LockInfo $lock)
 {
     $path = $path;
     //dummy codacy assignment
     $lock->owner = \CB\User::getDisplayName($_SESSION['user']['id']);
     // error_log('beforeLock: ' . $lock->owner);
     return true;
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 /**
  * @depends testCreate
  */
 public function testsetAsLoged()
 {
     $id = DM\Users::create(array('name' => $this->testName, 'password' => 'qq'));
     $this->assertTrue(is_numeric($id), 'Cant create User');
     \CB\User::setAsLoged($id, 'tests_key');
     $this->assertTrue(\CB\User::isLoged(), ' Error: user is not logged');
     $this->assertEquals($id, $_SESSION['user']['id'], 'Sessions user is not equal with setted users');
     $this->assertEquals('tests_key', $_SESSION['key'], 'Sessions key is not equal with setted keys');
 }
Esempio n. 7
0
 /**
  *
  * @param type $corename
  */
 public static function init($corename = DEFAULT_TEST_CORENAME)
 {
     $CB_PATH = \CB_DOC_ROOT;
     $_SERVER['REMOTE_ADDR'] = '127.0.0.1';
     $_SERVER['SERVER_NAME'] = static::getHost();
     $_GET['core'] = $corename;
     $_SESSION['user'] = array('id' => 1, 'groups' => [1]);
     require_once $CB_PATH . '/config.php';
     require_once $CB_PATH . '/lib/language.php';
     L\initTranslations();
     Config::setEnvVar('user_language_index', 1);
     \CB\User::setAsLoged(1, 'AbrACadaBraK333y');
 }
Esempio n. 8
0
 public function getClientData($options = array())
 {
     $rez = array('f' => $this->field, 'title' => $this->getTitle(), 'items' => array());
     // $colors = empty($options['colors'])
     //     ? array()
     //     : Users::getColors();
     foreach ($this->solrData as $k => $v) {
         $rez['items'][$k] = array('name' => User::getDisplayName($k), 'count' => $v);
         if (!empty($options['colors'])) {
             $rez['items'][$k]['cls'] = 'user-color-' . $k;
         }
     }
     return $rez;
 }
Esempio n. 9
0
 /**
  * set state
  * @param array $p
  */
 public function set($p)
 {
     $rez = array('success' => true);
     $state = User::getUserState();
     if (!empty($p['value']) || isset($state[$p['name']])) {
         if (empty($p['value'])) {
             unset($state[$p['name']]);
         } else {
             $state[$p['name']] = $p['value'];
         }
         User::setUserState($state);
     }
     return $rez;
 }
Esempio n. 10
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'));
    }
}
Esempio n. 11
0
 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($data['cdate']);
         $data['user'] = User::getDisplayName($data['oid'], true);
         $data['cls'] = 'sel';
         $rez['data'] = array($data);
     }
     return $rez;
 }
Esempio n. 12
0
 public function getName($id = false)
 {
     if ($id == false) {
         $id = $this->id;
     }
     $rez = 'no name';
     switch ($id) {
         case 'users':
             $rez = L\get('Users');
             break;
         default:
             $rez = \CB\User::getDisplayName($id);
     }
     return $rez;
 }
Esempio n. 13
0
 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($version['cdate']);
             $version['user'] = User::getDisplayName($version['cid'], true);
         }
     }
     return $rez;
 }
Esempio n. 14
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:task) OR (target_type:task)'), 'fl' => 'id,pid,name,template_id,date,date_end,cid,cdate,status', 'sort' => 'cdate', 'dir' => 'desc');
     $s = new \CB\Search();
     $sr = $s->query($params);
     foreach ($sr['data'] as $d) {
         $d['ago_text'] = @Util\formatDateTimePeriod($d['date'], null, @$_SESSION['user']['cfg']['timezone']);
         $d['user'] = User::getDisplayName($d['cid'], true);
         \CB\Tasks::setTaskActionFlags($d);
         $rez['data'][] = $d;
     }
     return $rez;
 }
Esempio n. 15
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;
 }
Esempio n. 16
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;
 }
Esempio n. 17
0
 /**
  * @depends test_getLoginUrl
  */
 public function test_checkLogined()
 {
     unset($_SESSION['key']);
     $this->assertFalse(\CB\User::isLoged(), 'ERROR checkLogined \\CB\\Users::isLoged = true');
     $url = $this->getUrl();
     $this->assertTrue(isset($url), 'ERROR checkLogined getGoogleLoginUrl ' . $url);
     $uri = parse_url($url);
     $Oauth2Query = [];
     parse_str($uri['query'], $Oauth2Query);
     $_GET = $Oauth2Query;
     $state = \CB\Oauth2Utils::decodeState($Oauth2Query['state']);
     $state['email'] = $this->email;
     $_GET['state'] = \CB\Oauth2Utils::encodeState($state);
     $check = \CB\Oauth2Utils::checkLogined();
     $this->assertTrue($check['success'], '\\CB\\Oauth2Utils::checkLogined() return success false');
     $this->assertTrue($check['user_id'] == 1, '\\CB\\Oauth2Utils::checkLogined() WRONG USER ID');
     $this->assertTrue($check['session_id'] == $state['state'], '\\CB\\Oauth2Utils::checkLogined() WRON SESSION ID');
     $r = \CB\User::setAsLoged($check['user_id'], $check['session_id']);
     $this->assertTrue($r['success'], ' User can\'t be set as logined');
 }
Esempio n. 18
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;
 }
Esempio n. 19
0
 /**
  * load a single comment by id
  * used for add/update operations on comments
  * @param  int  $id
  * @return json response
  */
 public static function loadComment($id)
 {
     $rez = array('success' => true, 'data' => array());
     if (empty($id)) {
         return $rez;
     }
     $params = array('system' => '[0 TO 2]', 'fq' => array('id:' . intval($id)), 'fl' => 'id,pid,template_id,cid,cdate,content', 'rows' => 1);
     $s = new \CB\Search();
     $sr = $s->query($params);
     foreach ($sr['data'] as $d) {
         $d['cdate_text'] = Util\formatAgoTime($d['cdate']);
         $d['user'] = User::getDisplayName($d['cid'], true);
         //data in solr has already encoded html special chars
         // so we need to decode it and to format the message (where the chars will be encoded again)
         $d['content'] = htmlspecialchars_decode($d['content'], ENT_COMPAT);
         $d['content'] = \CB\Objects\Comment::processAndFormatMessage($d['content']);
         array_unshift($rez['data'], $d);
     }
     static::addAttachmentLinks($rez);
     return @array_shift($rez['data']);
 }
Esempio n. 20
0
 /**
  * catch server side errors and return json encoded exception
  * @return void
  */
 function extDirectShutdownFunction()
 {
     $data = \CB\Cache::get('ExtDirectData');
     $error = error_get_last();
     if (in_array($error['type'], array(1, 4))) {
         $data['type'] = 'exception';
         $data['result'] = array('success' => false);
         $data['msg'] = 'Internal server error.';
         if (\CB\IS_DEBUG_HOST) {
             $data['msg'] = $error['message'];
             $data['where'] = print_r(debug_backtrace(false), true);
         }
         //notify admin
         if (!(php_sapi_name() == "cli")) {
             @mail(Config::get('ADMIN_EMAIL'), 'Remote router error on ' . Config::get('core_url'), var_export($data, true), 'From: ' . Config::get('SENDER_EMAIL') . "\r\n");
         }
         echo Util\jsonEncode($data);
     }
     if (\CB\User::isLoged()) {
         \CB\User::updateLastActionTime();
     }
 }
Esempio n. 21
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;
 }
Esempio n. 22
0
function doRpc($cdata)
{
    $API = \CB\Cache::get('ExtDirectAPI');
    if (!\CB\User::isLoged() && ($cdata['action'] != 'User' || $cdata['method'] != 'login') && !(php_sapi_name() == "cli")) {
        return array(array('type' => 'exception', 'name' => 'login', 'tid' => $cdata['tid'], 'action' => $cdata['action'], 'method' => $cdata['method'], 'result' => array('success' => false)));
    }
    try {
        if (!isset($API[$cdata['action']])) {
            throw new \Exception('Call to undefined action: ' . $cdata['action']);
        }
        $action = $cdata['action'];
        $a = $API[$action];
        doAroundCalls($a['before'], $cdata);
        $method = $cdata['method'];
        $mdef = $a['methods'][$method];
        if (!$mdef) {
            throw new \Exception("Call to undefined method: {$method} on action {$action}");
        }
        doAroundCalls($mdef['before'], $cdata);
        $r = array('type' => 'rpc', 'tid' => $cdata['tid'], 'action' => $action, 'method' => $method);
        $action = str_replace('_', '\\', $action);
        $o = new $action();
        $params = isset($cdata['data']) && is_array($cdata['data']) ? $cdata['data'] : array();
        $r['result'] = call_user_func_array(array($o, $method), $params);
        doAroundCalls($mdef['after'], $cdata, $r);
        doAroundCalls($a['after'], $cdata, $r);
    } catch (\Exception $e) {
        $r['type'] = 'exception';
        $r['result'] = array('success' => false, 'msg' => $e->getMessage());
        if (\CB\IS_DEBUG_HOST) {
            $r['where'] = $e->getTraceAsString();
        }
        //notify admin
        if (!(php_sapi_name() == "cli")) {
            @mail(Config::get('ADMIN_EMAIL'), 'Remote router exception on ' . Config::get('core_url'), var_export($r, true), 'From: ' . Config::get('SENDER_EMAIL') . "\r\n");
        }
    }
    return $r;
}
Esempio n. 23
0
 public function getName($id = false)
 {
     $rez = 'no name';
     if ($id === false) {
         $id = $this->id;
     }
     if (!empty($id) && is_numeric($id)) {
         $facetConfig = $this->getFacetFieldConfig($this->getClassDepth() - 1);
         switch (@$facetConfig['type']) {
             case 'users':
                 $rez = User::getDisplayName($id);
                 break;
             default:
                 $rez = Objects::getName($id);
         }
     } else {
         switch ($id) {
             case 'root':
                 $cfg =& $this->config;
                 $l = Config::get('user_language');
                 if (empty($cfg['title_' . $l])) {
                     $l = Config::get('language');
                     if (empty($cfg['title_' . $l])) {
                         if (!empty($cfg['title'])) {
                             $rez = $cfg['title'];
                         }
                     } else {
                         $rez = $cfg['title_' . $l];
                     }
                 } else {
                     $rez = $cfg['title_' . $l];
                 }
                 break;
         }
     }
     return $rez;
 }
Esempio n. 24
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);
 }
Esempio n. 25
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);
     }
 }
Esempio n. 26
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;
 }
Esempio n. 27
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);
     }
 }
 /**
  * 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.');
 }
Esempio n. 29
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;
 }
Esempio n. 30
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;
 }