Beispiel #1
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;
 }
Beispiel #2
0
 public function onSolrQuery(&$p)
 {
     $result =& $p['result'];
     $data =& $result['data'];
     $actionLogIds = array();
     $comments = new Objects\Plugins\Comments();
     //format ago date and collect log action ids
     foreach ($data as &$doc) {
         $la = Objects::getCachedObject($doc['id'])->getLastActionData();
         $la['agoText'] = Util\formatAgoTime($la['time']);
         $la['uids'] = array_reverse(array_keys($la['users']));
         $doc['lastAction'] = $la;
         $actionLogId = $la['users'][$la['uids'][0]];
         $doc['comments'] = $comments->getData($doc['id']);
         $actionLogIds[$actionLogId] =& $doc;
     }
     $logRecs = DM\Log::getRecords(array_keys($actionLogIds));
     foreach ($logRecs as $r) {
         $d = Util\jsonDecode($r['data']);
         $obj = Objects::getCachedObject($actionLogIds[$r['id']]['id']);
         $diff = $obj->getDiff($d);
         if (!empty($diff)) {
             $html = '';
             foreach ($diff as $fn => $fv) {
                 $html .= "<tr><th>{$fn}</th><td>{$fv}</td></tr>";
             }
             $actionLogIds[$r['id']]['diff'] = "<table class=\"as-diff\">{$html}</table>";
         }
     }
 }
Beispiel #3
0
 public function getChildren(&$pathArray, $requestParams)
 {
     $this->path = $pathArray;
     $this->lastNode = @$pathArray[sizeof($pathArray) - 1];
     $this->requestParams = $requestParams;
     if (!$this->acceptedPath($pathArray, $requestParams)) {
         return;
     }
     $ourPid = @$this->config['pid'];
     if ($ourPid == '') {
         $ourPid = 0;
     }
     $this->createDefaultFilter();
     if (empty($this->lastNode) || $this->lastNode->id == $ourPid && get_class($this->lastNode) != get_class($this) || \CB\Objects::getType($this->lastNode->id) == 'case') {
         $rez = $this->getRootNodes();
     } else {
         switch ($this->lastNode->id) {
             case 'tasks':
                 $rez = $this->getDepthChildren2();
                 break;
             case 2:
             case 3:
                 $rez = $this->getDepthChildren3();
                 break;
             default:
                 $rez = $this->getChildrenTasks();
         }
     }
     return $rez;
 }
function sendUserMails($u)
{
    $uid = $u['id'];
    if (empty($u['email'])) {
        return;
    }
    $sendType = User::canSendNotifications($uid);
    if ($sendType == false) {
        return;
    }
    $coreName = Config::get('core_name');
    // $coreUrl = Config::get('core_url');
    $languages = Config::get('languages');
    $lang = $languages[$u['language_id'] - 1];
    if (filter_var($u['email'], FILTER_VALIDATE_EMAIL)) {
        //group mails into digest and separate ones (where user is mentioned)
        $mails = array('digest' => array(), 'separate' => array());
        foreach ($u['mails'] as $notificationId => $notification) {
            //[$core #$nodeId] $action_type $template_name: $object_title
            $templateId = Objects::getTemplateId($notification['object_id']);
            $templateName = Objects::getName($templateId);
            $subject = '[' . $coreName . ' #' . $notification['object_id'] . '] ' . Notifications::getActionDeclination($notification['action_type'], $lang) . ' ' . $templateName . ' "' . htmlspecialchars_decode($notification['data']['name']) . '"';
            $sender = Notifications::getSender($notification['from_user_id']);
            //divide notification into separate number of actions it consist of
            $actions = getNotificationActions($notification);
            for ($i = 0; $i < sizeof($actions); $i++) {
                $a = $actions[$i];
                $message = Notifications::getMailBodyForAction($a, $u);
                $isMentioned = !empty($a['data']['mentioned']) && in_array($uid, $a['data']['mentioned']);
                $mails[$isMentioned ? 'separate' : 'digest'][] = array('subject' => $subject, 'body' => $message, 'sender' => $sender, 'nId' => $notificationId);
            }
        }
        //merge digest emails group into one email and put it into separate group
        if (sizeof($mails['digest']) == 1) {
            $mails['separate'][] = $mails['digest'][0];
        } elseif (!empty($mails['digest'])) {
            $mail = array();
            $ids = array();
            $sender = '';
            foreach ($mails['digest'] as $m) {
                $mail[] = $m['body'];
                $sender = $m['sender'];
                $ids[] = $m['nId'];
            }
            $mails['separate'][] = array('subject' => '[' . $coreName . '] Notifications digest', 'body' => implode('<hr />', $mail), 'sender' => $sender, 'nId' => $ids);
        }
        foreach ($mails['separate'] as $mail) {
            echo $u['email'] . ': ' . $mail['subject'] . "\n";
            if (!mail($u['email'], $mail['subject'], $mail['body'], "Content-type: text/html; charset=utf-8\r\nFrom: " . $mail['sender'] . "\r\n")) {
                System::notifyAdmin('CaseBox cron notification: Cant send notification (' . $mail['nId'] . ') mail to "' . $u['email'] . '"', $mail['body']);
            } else {
                DM\Notifications::markAsSeen($mail['nId'], $uid);
            }
        }
        if (!empty($mails['digest'])) {
            User::setUserConfigParam('lastNotifyTime', Util\dateISOToMysql('now'), $uid);
        }
    }
}
Beispiel #5
0
 public function getName($id = false)
 {
     if ($id == false) {
         $id = $this->id;
     }
     $rez = Objects::getName($id);
     return $rez;
 }
Beispiel #6
0
 /**
  * method to get and format the log data as needed
  * @param  array &$p
  * @return array
  */
 protected static function getLogData(&$p)
 {
     $rez = array();
     $fields = array('id' => 1, 'name' => 1, 'iconCls' => 1, 'pids' => 1, 'path' => 1, 'template_id' => 1, 'case_id' => 1, 'date' => 1, 'size' => 1, 'cid' => 1, 'oid' => 1, 'uid' => 1, 'cdate' => 1, 'udate' => 1);
     $oldData = empty($p['old']) ? array() : $p['old']->getData();
     $newData = empty($p['new']) ? array() : $p['new']->getData();
     $oldData = array_intersect_key($oldData, $fields);
     $newData = array_intersect_key($newData, $fields);
     $rez = $newData + $oldData;
     //return empty result for other than object actions (login, logout, etc)
     if (empty($rez['id'])) {
         return;
     }
     Util\unsetNullValues($rez);
     $rez['name'] = htmlspecialchars($rez['name'], ENT_COMPAT);
     if (empty($rez['iconCls'])) {
         $rez['iconCls'] = Browser::getIcon($rez);
     }
     if (!empty($p['mentioned'])) {
         $rez['mentioned'] = $p['mentioned'];
     }
     $rez['pids'] = empty($rez['pids']) ? Objects::getPids($rez['id']) : Util\toNumericArray($rez['pids']);
     $rez['path'] = htmlspecialchars(@Util\coalesce($rez['pathtext'], $rez['path']), ENT_COMPAT);
     switch ($p['type']) {
         case 'comment':
         case 'comment_update':
             $rez['comment'] = $p['comment'];
             break;
         case 'file_upload':
         case 'file_update':
             $rez['file'] = $p['file'];
             break;
         case 'completion_decline':
         case 'completion_on_behalf':
             if (!empty($p['forUserId'])) {
                 $rez['forUserId'] = $p['forUserId'];
             }
             break;
         default:
             // setting old and new properties of linear custom data
             if (!empty($p['old'])) {
                 $rez['old'] = $p['old']->getAssocLinearData();
             }
             if (!empty($p['new'])) {
                 $rez['new'] = $p['new']->getAssocLinearData();
             }
             //unset identical values
             if (!empty($rez['old']) && !empty($rez['new'])) {
                 foreach ($rez['old'] as $k => $v) {
                     if (isset($rez['new'][$k]) && $rez['new'][$k] == $v) {
                         unset($rez['old'][$k]);
                         unset($rez['new'][$k]);
                     }
                 }
             }
     }
     return $rez;
 }
Beispiel #7
0
 protected function getObjectClass()
 {
     $rez = null;
     if (empty($this->objectClass) && !empty($this->id)) {
         $this->objectClass = \CB\Objects::getCachedObject($this->id);
         $rez =& $this->objectClass;
     }
     return $rez;
 }
Beispiel #8
0
 /**
  * get data model pid that is different from tree one
  * @param  int $pid
  * @return int
  */
 protected function getDMPid($pid)
 {
     $rez = null;
     $name = Objects::getName($pid);
     $id = DM\Config::toId($name, 'param');
     if (is_numeric($id)) {
         $rez = $id;
     }
     return $rez;
 }
Beispiel #9
0
 public function getData($id = false)
 {
     $rez = array('success' => true);
     parent::getData($id);
     $preview = Objects::getPreview($this->id);
     $obj = Objects::getCachedObject($this->id);
     if (empty($obj)) {
         return $rez;
     }
     $data = $obj->getData();
     if (!empty($preview)) {
         $rez['data'] = array('preview' => $preview);
     }
     if (!empty($data)) {
         if (!empty($data['pids'])) {
             $path = explode(',', $data['pids']);
             array_pop($path);
             $rez['data']['pids'] = $rez['data']['path'] = implode('/', $path);
             $arr = array(&$rez['data']);
             Search::setPaths($arr);
         }
         foreach ($data as $k => $v) {
             if (in_array($k, array('id', 'template_id', 'date_end', 'cid', 'uid', 'cdate', 'udate'))) {
                 if (in_array($k, array('date', 'date_end', 'cdate', 'udate'))) {
                     $v = Util\dateMysqlToISO($v);
                 }
                 $rez['data'][$k] = $v;
                 //add ago udate text
                 if (in_array($k, array('cdate', 'udate'))) {
                     $rez['data'][$k . '_ago_text'] = Util\formatAgoTime($v);
                 }
             }
         }
         $rez['data']['name'] = $obj->getName();
     }
     $rez['data']['can'] = $obj->getActionFlags();
     //set status info for tasks if not active
     if ($obj->getType() == 'task') {
         $d =& $rez['data'];
         $d['status'] = '';
         switch ($obj->getStatus()) {
             case Objects\Task::$STATUS_ACTIVE:
                 break;
             case Objects\Task::$STATUS_CLOSED:
                 //just add title css class and continue with default
                 $d['titleCls'] = 'task-completed';
                 // break;
             // break;
             default:
                 $d['status'] = $obj->getStatusText();
                 $d['statusCls'] = $obj->getStatusCSSClass();
         }
     }
     return $rez;
 }
Beispiel #10
0
 protected function getColors()
 {
     $rez = array();
     $ids = array_keys((array) $this->solrData);
     $objects = Objects::getCachedObjects($ids);
     foreach ($objects as $o) {
         $d = $o->getData();
         if (!empty($d['data']['color'])) {
             $rez[$d['id']] = $d['data']['color'];
         }
     }
     return $rez;
 }
Beispiel #11
0
 /**
  * update objects custom data
  * @return boolean
  */
 protected function updateCustomData()
 {
     parent::updateCustomData();
     /* saving template data to templates and templates_structure tables */
     $p =& $this->data;
     $data = $this->collectCustomModelData();
     $data['id'] = $this->id;
     $data['template_id'] = $this->detectParentTemplate();
     DM\TemplatesStructure::update($data);
     if ($this->isSolrConfigUpdated()) {
         $tpl = \CB\Objects::getCachedObject($data['template_id']);
         $tpl->setSysDataProperty('solrConfigUpdated', true);
     }
 }
Beispiel #12
0
 /**
  * create method
  * @return void
  */
 public function create($p = false)
 {
     //disable default log from parent Object class
     //we'll set comments add as comment action for parent
     $disableLogFlag = \CB\Config::getFlag('disableActivityLog');
     \CB\Config::setFlag('disableActivityLog', true);
     $rez = parent::create($p);
     \CB\Config::setFlag('disableActivityLog', $disableLogFlag);
     $p =& $this->data;
     $this->parentObj = Objects::getCachedObject($p['pid']);
     $this->updateParentFollowers();
     $this->logAction('file_upload', array('file' => array('id' => $p['id'], 'name' => $p['name'])));
     return $rez;
 }
 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;
 }
Beispiel #14
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;
 }
 public function getName($id = false)
 {
     if ($id == false) {
         $id = $this->id;
     }
     switch ($id) {
         case 1:
             return L\get('Manager');
         case 2:
             return L\get('Lead');
         case 3:
             return L\get('Support');
         case 4:
             return L\get('AllMyCases');
     }
     return Objects::getName($id);
 }
Beispiel #16
0
 public function getName($id = false)
 {
     if ($id === false) {
         $id = $this->id;
     }
     $rez = $id;
     switch ($id) {
         case 'recycleBin':
             return L\get('RecycleBin');
         default:
             if (!empty($id) && is_numeric($id)) {
                 $rez = \CB\Objects::getName($id);
             }
             break;
     }
     return $rez;
 }
Beispiel #17
0
 /**
  * check if current class is configured to return any result for
  * given path and request params
  * @param  array   &$pathArray
  * @param  array   &$requestParams
  * @return boolean
  */
 protected function acceptedPath(&$pathArray, &$requestParams)
 {
     $lastNode = null;
     if (empty($pathArray)) {
         return false;
     } else {
         $lastNode = $pathArray[sizeof($pathArray) - 1];
     }
     if ($lastNode instanceof Dbnode) {
         if (\CB\Objects::getType($lastNode->id) !== 'case') {
             return false;
         }
     } elseif (get_class($lastNode) != get_class($this)) {
         return false;
     }
     return true;
 }
Beispiel #18
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;
 }
Beispiel #19
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);
     }
 }
Beispiel #20
0
 /**
  * executing preimporting changes to target core
  * @return void
  */
 protected function prepare()
 {
     //update template types
     DB\dbQuery("ALTER TABLE `templates`\n            CHANGE `type` `type` enum('case','object','file','task','user','email','template','field','search','comment','shortcut','menu')\n            COLLATE utf8_general_ci NULL after `is_folder`") or die(DB\dbQueryError());
     // set templates template id in config
     $ids = DM\Templates::getIdsByType('template');
     $id = array_shift($ids);
     BBM::$cfg['templatesTemplateId'] = $id;
     $this->cfg['templates']['Menu rule']['fields']['template_ids']['cfg']['templates'] = $id;
     $this->cfg['templates']['Menu rule']['fields']['menu']['cfg']['templates'] = $id;
     // detect fields template id
     $ids = DM\Templates::getIdsByType('field');
     $id = array_shift($ids);
     BBM::$cfg['fieldTemplateId'] = $id;
     //detect folderTemplateId
     $ids = Config::get('folder_templates');
     if (!empty($ids)) {
         BBM::$cfg['folderTemplateId'] = array_shift($ids);
     }
     //create "Menu" folder under templates to store our menu templates there
     //and update BBM::$cfg['templatesFolderId'] to our folder id
     $o = new \CB\Objects\Object();
     $rootId = Browser::getRootFolderId();
     $pid = Objects::getChildId($rootId, 'Templates');
     if (empty($pid)) {
         $pid = Objects::getChildId($rootId, 'System');
         if (!empty($pid)) {
             $pid = Objects::getChildId($pid, 'Templates');
         }
     }
     $id = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'Menu', 'data' => array('_title' => 'Menu')));
     BBM::$cfg['templatesFolderId'] = $id;
     //create System/Menus folder for transferring menu rules to it
     $pid = Objects::getChildId($rootId, 'System');
     if (empty($pid)) {
         $pid = $o->create(array('id' => null, 'pid' => $rootId, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'System', 'data' => array('_title' => 'System')));
     }
     $this->cfg['menusFolderId'] = $o->create(array('id' => null, 'pid' => $pid, 'template_id' => BBM::$cfg['folderTemplateId'], 'name' => 'Menus', 'data' => array('_title' => 'Menus')));
 }
Beispiel #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;
 }
Beispiel #22
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;
 }
Beispiel #23
0
 /**
  * just a test method to upload a file and execute methods from
  * DataModel to check the result
  * @return void
  */
 public function testDataModelFilesMethods()
 {
     $api = new Api\Files();
     $fn = tempnam(sys_get_temp_dir(), 'cb_test');
     file_put_contents($fn, 'testing');
     $data = array('pid' => 1, 'localFile' => $fn, 'oid' => 1);
     $rez = $api->upload($data);
     $this->assertTrue($rez['success'], 'Upload test file failed: ' . $fn);
     $fileData = $rez['data']['file'];
     $id = $fileData['id'];
     $rez = DM\Files::getContentIds($id);
     $this->assertTrue(!empty($rez[$id]), 'Cant get content id');
     $rez = DM\Files::getContentPaths($id);
     $this->assertTrue(!empty($rez[$id]), 'Cant get content path');
     //delete the file from system and check if same actions return empty results
     $f = Objects::getCachedObject($id);
     $f->delete(true);
     // permanently delete
     unset($f);
     $rez = DM\Files::getContentIds($id);
     $this->assertTrue(empty($rez[$id]), 'Obtaining content id for a permanently deleted file');
     $rez = DM\Files::getContentPaths($id);
     $this->assertTrue(empty($rez[$id]), 'Obtaining content path for a permanently deleted file');
 }
Beispiel #24
0
 public function deleteVersion($id)
 {
     $rez = array('success' => true, 'id' => $id);
     $content_id = 0;
     $version = DM\FilesVersions::read($id);
     if (!empty($version)) {
         $content_id = $version['content_id'];
     }
     DM\FilesVersions::delete($id);
     $this->removeContentId($content_id);
     DM\Tree::update(array('id' => $version['file_id'], 'updated' => 1));
     Objects::updateCaseUpdateInfo($id);
     Solr\Client::runCron();
     return $rez;
 }
Beispiel #25
0
 /**
  * update create menus
  * @return void
  */
 protected function updateCreateMenus()
 {
     $rootId = \CB\Browser::getRootFolderId();
     $pid = Objects::getChildId($rootId, 'System');
     if (!empty($pid)) {
         $pid = Objects::getChildId($pid, 'Menus');
         if (!empty($pid)) {
             $res = DB\dbQuery('SELECT id
                 FROM tree
                 WHERE pid = $1
                     AND dstatus = 0', $pid) or die(DB\dbQueryError());
             if ($r = $res->fetch_assoc()) {
                 $o = Objects::getCachedObject($r['id']);
                 $d = $o->getData();
                 $d['data']['menu'] = $this->templateIds['Case'] . ',' . $this->templateIds['Contact'] . ',' . $this->templateIds['Organization'] . ',' . $d['data']['menu'];
                 $o->update($d);
             }
             $res->close();
         }
     }
 }
 if (empty($core['mails'])) {
     continue;
 }
 $_GET['core'] = $coreName;
 $_SERVER['SERVER_NAME'] = $coreName . '.casebox.org';
 include $site_path . DIRECTORY_SEPARATOR . 'config.php';
 include $site_path . DIRECTORY_SEPARATOR . 'lib/language.php';
 $templateIds = Templates::getIdsByType('comment');
 if (empty($templateIds)) {
     \CB\debug('receive comments cron: no comment template defined');
     continue;
 }
 $templateId = array_shift($templateIds);
 $commentsObj = Objects::getCustomClassByType('comment');
 foreach ($core['mails'] as $mail) {
     if (!Objects::idExists($mail['pid'])) {
         \CB\debug('receive comments cron: target id not found for mail "' . $mail['subject'] . '"');
         continue;
     }
     $emailFrom = extractEmailFromText($mail['from']);
     // user email
     $emailTo = extractEmailFromText($mail['to']);
     // <*****@*****.**>
     $userId = DM\User::getIdByEmail($emailFrom);
     $_SESSION['user'] = array('id' => $userId);
     $data = array('id' => null, 'pid' => $mail['pid'], 'oid' => $userId, 'cid' => $userId, 'template_id' => $templateId, 'data' => array('_title' => removeContentExtraBlock($mail['content'], $emailFrom, $emailTo)), 'sys_data' => array('mailId' => $mail['id']));
     try {
         $commentId = $commentsObj->create($data);
         //add attachments
         if (!empty($mail['attachments'])) {
             saveObjectAttachments($commentId, $mail['attachments']);
Beispiel #27
0
 /**
  * update path property for an items array
  * @param array $dataArray
  */
 public static function setPaths(&$dataArray)
 {
     //collect distinct paths and ids
     $paths = array();
     $distinctIds = array();
     foreach ($dataArray as &$item) {
         if (isset($item['path']) && !isset($paths[$item['path']])) {
             $path = Util\toNumericArray($item['path'], '/');
             if (!empty($path)) {
                 $paths[$item['path']] = $path;
                 $distinctIds = array_merge($distinctIds, $path);
             }
         }
     }
     if (!empty($distinctIds)) {
         $distinctIds = array_unique($distinctIds);
         $objects = Objects::getCachedObjects($distinctIds);
         $names = array();
         foreach ($distinctIds as $id) {
             if (!empty($objects[$id])) {
                 $names[$id] = $objects[$id]->getHtmlSafeName();
             }
         }
         //replace ids in paths with names
         foreach ($paths as $path => $elements) {
             for ($i = 0; $i < sizeof($elements); $i++) {
                 if (isset($names[$elements[$i]])) {
                     $elements[$i] = $names[$elements[$i]];
                 }
             }
             array_unshift($elements, '');
             array_push($elements, '');
             $paths[$path] = implode('/', $elements);
         }
         //replace paths in objects data
         foreach ($dataArray as &$item) {
             if (isset($item['path'])) {
                 $item['path'] = @$paths[$item['path']];
             }
         }
     }
 }
 /**
  * test notifications module
  *
  * @return [type] [description]
  */
 public function testNotifications()
 {
     //check if everything is prepeared
     $this->assertTrue(sizeof($this->userIds) > 3, 'Less than 4 users created');
     $this->assertTrue(sizeof($this->objectIds) > 2, 'Less than 3 tasks created');
     //add a comment to obj 1 with user 1 referencing user 2
     $firstUserId = $this->userIds[0];
     $secondUserId = $this->userIds[1];
     $thirdUserId = $this->userIds[2];
     $forthUserId = $this->userIds[3];
     $rootUserId = $this->oldValues['user_id'];
     $pid = $this->objectIds[0];
     $commentData = array('pid' => $pid, 'template_id' => 9, 'data' => array('_title' => 'Hello to user @bow!'));
     $_SESSION['user']['id'] = $firstUserId;
     /* make a check - user should be denied to add comments */
     try {
         $commentId = $this->createObject($commentData);
     } catch (\Exception $e) {
         $msg = $e->getMessage();
         $this->assertTrue($msg == 'Access is denied', $msg);
     }
     $_SESSION['user']['id'] = $rootUserId;
     $this->addAllowSecurityRule();
     // try again adding a comment,
     // now it should work without access exceptions
     $_SESSION['user']['id'] = $firstUserId;
     $commentId = $this->createObject($commentData);
     $this->assertTrue(is_numeric($commentId), 'Wrong comment ID.');
     //check notifications for user bow,
     //he should receive 2 new notifications from root and andrew
     $this->assertTrue($this->checkLastNotification($secondUserId, array('user_id' => $firstUserId, 'object_id' => $pid, 'read' => 0)), 'Wrong last notification');
     //check notifications for root user, he also should receive a new notification from andrew
     //as owner of the object
     $this->assertTrue($this->checkLastNotification($rootUserId, array('user_id' => $firstUserId, 'object_id' => $pid, 'read' => 0)), 'No notification for root (owner) user.');
     //add comments with all 4 users and check notifications to cover
     //code for 3 and more users notifications grouping
     //and check root notifications with each comment
     for ($i = 0; $i < 4; $i++) {
         $_SESSION['user']['id'] = $this->userIds[$i];
         $commentData['data']['_title'] = 'Comment from user #' . $i . '.';
         $this->createObject($commentData);
         $this->assertTrue($this->checkLastNotification($rootUserId, array('user_id' => $this->userIds[$i], 'object_id' => $pid, 'read' => 0)), 'Wrong last notification for root from user #' . $i . '.');
     }
     $_SESSION['user']['id'] = $rootUserId;
     /*-------- answer back to previous comment with root and see if notifications are created */
     $commentData['data']['_title'] = 'Reply to Hellow comment.';
     $commentId = $this->createObject($commentData);
     //check notifications for all 4 users
     for ($i = 0; $i < 3; $i++) {
         $this->assertTrue($this->checkLastNotification($this->userIds[$i], array('object_id' => $pid, 'read' => 0)), 'Wrong last notification from root for user #' . $i . '.');
     }
     $this->checkMarkingNotificationsAsRead();
     //end of big testing schema
     //cover for now some simple code from Notifications
     $this->assertTrue(\CB\Notifications::getActionDeclination('reopen', 'en') == 'reopened', 'Declination not correct for reopen.');
     $this->assertTrue(\CB\Notifications::getActionDeclination('SomeWrongValue!>', 'en') == 'SomeWrongValue!>', 'Declination not correct for a wrong value.');
     $this->assertTrue(\CB\Notifications::getActionDeclination('file_upload', 'en') == 'uploaded a file to', 'Declination not correct for file_upload.');
     $this->assertTrue(\CB\Notifications::getActionDeclination('file_update', 'en') == 'updated a file in', 'Declination not correct for file_update.');
     //update a task and delete them all
     $obj = \CB\Objects::getCachedObject($pid);
     $data = $obj->getData();
     $data['data']['due_date'] = '2012-12-17T00:00:00Z';
     unset($data['data']['importance']);
     $data['data']['description'] .= ' *update* ';
     $obj->update($data);
     foreach ($this->objectIds as $id) {
         $obj->delete(false);
     }
     //get unset notifications and and access functions for preparing email
     $recs = DM\Notifications::getUnsent();
     foreach ($recs as $action) {
         $userData = \CB\User::getPreferences($action['to_user_id']);
         $sender = \CB\Notifications::getSender($action['from_user_id']);
         $body = \CB\Notifications::getMailBodyForAction($action, $userData);
     }
 }
Beispiel #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;
 }
Beispiel #30
0
 /**
  * method to collect solr data from object data
  * according to template fields configuration
  * and store it in sys_data onder "solr" property
  * @return void
  */
 protected function collectSolrData()
 {
     parent::collectSolrData();
     $sd =& $this->data['sys_data']['solr'];
     $sd['target_type'] = Objects::getType($this->data['target_id']);
 }