Ejemplo n.º 1
0
 protected function createDefaultFilter()
 {
     $this->fq = array();
     //select only case templates
     $templates = Templates::getIdsByType('case');
     if (!empty($templates)) {
         $this->fq[] = 'template_id:(' . implode(' OR ', $templates) . ')';
     }
     $this->user_id = $_SESSION['user']['id'];
     // add office filter
     $parentNode = null;
     switch (get_class($this->lastNode)) {
         case 'Demosrc\\TreeNode\\OfficeCases':
             if (is_numeric($this->lastNode->id)) {
                 $parentNode = $this->lastNode->parent->parent;
                 // $this->fq[] = 'category_id:'.$this->lastNode->parent->parent->id;
                 $this->fq[] = 'status:' . $this->lastNode->id;
             } else {
                 $parentNode = $this->lastNode->parent;
                 // $this->fq[] = 'category_id:'.$this->lastNode->parent->id;
             }
             break;
         default:
             $parentNode = $this->lastNode;
     }
     switch (get_class($parentNode)) {
         case 'Demosrc\\TreeNode\\OfficeUsers':
             $this->fq[] = '(role_ids2:' . $parentNode->id . ' OR role_ids3:' . $parentNode->id . ')';
             // $this->fq[] = 'category_id:'.$parentNode->parent->parent->id;
             break;
         case 'Demosrc\\TreeNode\\Offices':
             // $this->fq[] = 'category_id:'.$parentNode->id;
             break;
     }
 }
Ejemplo n.º 2
0
 protected function createDefaultFilter()
 {
     $this->fq = array();
     //select only task templates
     $taskTemplates = Templates::getIdsByType('task');
     if (!empty($taskTemplates)) {
         $this->fq[] = 'template_id:(' . implode(' OR ', $taskTemplates) . ')';
     }
     // add office filter
     switch (get_class($this->lastNode)) {
         case 'Demosrc\\TreeNode\\TaskTypes':
             $this->fq[] = 'template_id:' . $this->lastNode->id;
             break;
         case 'Demosrc\\TreeNode\\TaskStatuses':
             $this->fq[] = 'template_id:' . $this->lastNode->parent->id;
             $this->fq[] = 'status:' . $this->lastNode->id;
             break;
     }
     //get program filter
     $pnode = $this->lastNode->parent;
     while (!empty($pnode) && get_class($pnode) !== 'Demosrc\\TreeNode\\Offices') {
         // echo get_class($pnode)."\n";
         $pnode = @$pnode->parent;
     }
     if (!empty($pnode) && get_class($pnode) == 'Demosrc\\TreeNode\\Offices') {
         // $this->fq[] = 'category_id:'.$pnode->id;
     }
     // if (get_class($this->lastNode) == 'Demosrc\\TreeNode\\OfficeUsers') {
     //     $this->fq[] = 'category_id:'.$this->lastNode->parent->parent->id;
     //     $this->fq[] = 'user_ids:'.$this->lastNode->id;
     // } else {
     //     $this->fq[] = 'category_id:'.$this->lastNode->id;
     // }
     $this->user_id = $_SESSION['user']['id'];
 }
Ejemplo n.º 3
0
 /**
  * load next set of comments (not all are loaded by default)
  * @param  array $p
  * @return json  response
  */
 public function loadMore($p)
 {
     $rez = array('success' => true, 'data' => array());
     if (empty(parent::getData($p['id']))) {
         return $rez;
     }
     $commentTemplateIds = \CB\Templates::getIdsByType('comment');
     if (empty($commentTemplateIds)) {
         return $rez;
     }
     $limit = Config::get('max_load_comments', 4);
     $params = array('pid' => $this->id, 'system' => '[0 TO 2]', 'fq' => array('template_id:(' . implode(' OR ', $commentTemplateIds) . ')'), 'fl' => 'id,pid,template_id,cid,cdate,content', 'strictSort' => 'cdate desc', 'rows' => $limit);
     if (!empty($p['beforeId']) && is_numeric($p['beforeId'])) {
         $params['fq'][] = 'id:[* TO ' . ($p['beforeId'] - 1) . ']';
     }
     $s = new \CB\Search();
     $sr = $s->query($params);
     if (empty($p['beforeId'])) {
         $rez['total'] = $sr['total'];
     }
     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 $rez;
 }
Ejemplo n.º 4
0
 protected function createDefaultFilter()
 {
     $this->fq = array();
     //select only task templates
     $taskTemplates = Templates::getIdsByType('task');
     if (!empty($taskTemplates)) {
         $this->fq[] = 'template_id:(' . implode(' OR ', $taskTemplates) . ')';
     }
 }
Ejemplo n.º 5
0
 protected function createDefaultFilter()
 {
     $this->fq = array();
     //select only case templates
     $caseTemplates = Templates::getIdsByType('case');
     if (!empty($caseTemplates)) {
         $this->fq[] = 'template_id:(' . implode(' OR ', $caseTemplates) . ')';
     }
     $this->user_id = $_SESSION['user']['id'];
     $this->fq[] = sprintf('(role_ids1:%1$d OR role_ids2:%1$d OR role_ids3:%1$d)', $this->user_id);
 }
Ejemplo n.º 6
0
 protected function createDefaultFilter()
 {
     $this->fq = array();
     //select only task templates
     $taskTemplates = Templates::getIdsByType('task');
     if (!empty($taskTemplates)) {
         $this->fq[] = 'template_id:(' . implode(' OR ', $taskTemplates) . ')';
     }
     // add office filter
     if (get_class($this->lastNode) == 'Demosrc\\TreeNode\\OfficeUsers') {
         $this->office_id = $this->lastNode->parent->id;
     } else {
         $this->office_id = $this->lastNode->id;
     }
     // $this->fq[] = 'category_id:'.$this->office_id;
     $this->user_id = $_SESSION['user']['id'];
 }
Ejemplo n.º 7
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 = 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 = 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')));
 }
        // System::notifyAdmin('Casebox: check mail Exception for core' . $coreName, $e->getMessage());
        echo " Error connecting to email\n" . $e->getMessage();
    }
}
// iterate each core and add comment items if there is smth
foreach ($mailServers as $mailConf) {
    $deleteMailIds = array();
    foreach ($mailConf['cores'] as $coreName => $core) {
        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']);
            // <*****@*****.**>
Ejemplo n.º 9
0
 /**
  * add comments for an objects
  * @param array $p input params (id, msg)
  */
 public function addComment($p)
 {
     $rez = array('success' => false);
     if (empty($p['id']) || !is_numeric($p['id']) || empty($p['msg'])) {
         $rez['msg'] = L\get('Wrong_input_data');
         return $rez;
     }
     if (!Security::canRead($p['id'])) {
         throw new \Exception(L\get('Access_denied'));
     }
     $commentTemplates = Templates::getIdsByType('comment');
     if (empty($commentTemplates)) {
         $rez['msg'] = 'No comment templates found';
         return $rez;
     }
     $co = new Objects\Comment();
     $data = array('pid' => $p['id'], 'draftId' => @$p['draftId'], 'template_id' => array_shift($commentTemplates), 'system' => 2, 'data' => array('_title' => $p['msg']));
     $id = $co->create($data);
     Solr\Client::runCron();
     return array('success' => true, 'data' => \CB\Objects\Plugins\Comments::loadComment($id));
 }
Ejemplo n.º 10
0
 /**
  *  set the flags for actions that could be made to the tasks by a specific or current user
  * @param  reference $object_records
  * @return void
  */
 public static function setTasksActionFlags(&$tasksDataArray, $userId = false)
 {
     $taskTemplates = Templates::getIdsByType('task');
     foreach ($tasksDataArray as &$d) {
         if (!in_array(@$d['template_id'], $taskTemplates) || empty($d['status'])) {
             continue;
         }
         $task = Objects::getCachedObject($d['id']);
         $d['can'] = $task->getActionFlags();
     }
 }
//check script options
$options = getopt('c:at:', array('core', 'all', 'template'));
$core = empty($options['c']) ? @$options['core'] : $options['c'];
if (empty($core)) {
    die('no core specified or invalid options set.');
}
$all = isset($options['a']) || isset($options['all']);
$template = empty($options['t']) ? @$options['template'] : $options['t'];
//init
$cron_id = 'dummy';
include $path . 'init.php';
\CB\Config::setFlag('disableActivityLog', true);
//create query filter
$where = empty($all) ? ' AND t.updated = 1' : '';
if (!empty($template)) {
    $template = is_numeric($template) ? array($template) : Templates::getIdsByType($template);
    if (!empty($template)) {
        $where .= ' AND t.template_id in (' . implode(',', $template) . ') ';
    }
}
// join with tree table if filter not empty
if (!empty($where)) {
    $where = ' JOIN tree t ON o.id = t.id ' . $where;
}
//start the process
//select all objects that have data in "objects" table
$res = DB\dbQuery('SELECT count(*) `nr`
    FROM objects o' . $where) or die(DB\dbQueryError());
if ($r = $res->fetch_assoc()) {
    echo "Total objects: " . $r['nr'] . "\n";
}