예제 #1
0
 public function getContentItems()
 {
     $p =& $this->requestParams;
     $folderTemplates = \CB\Config::get('folder_templates');
     $p['fl'] = 'id,system,path,name,case,date,date_end,size,cid,oid,cdate,uid,udate,template_id,acl_count,cls,status,task_status,dstatus';
     if (@$p['from'] == 'tree') {
         $p['templates'] = $folderTemplates;
     }
     if (is_numeric($this->lastNode->id)) {
         $p['pid'] = $pid;
     }
     $p['dstatus'] = 1;
     $p['fq'] = $this->fq;
     $s = new \CB\Search();
     $rez = $s->query($p);
     if (!empty($rez['data'])) {
         for ($i = 0; $i < sizeof($rez['data']); $i++) {
             $d =& $rez['data'][$i];
             $r = DM\Tree::read($d['id']);
             if (!empty($r)) {
                 $d['cfg'] = $r['cfg'];
                 $r = DM\Tree::getChildCount($d['id'], @$p['from'] == 'tree' ? $folderTemplates : false);
                 $d['has_childs'] = !empty($r[$d['id']]);
             }
         }
     }
     return $rez;
 }
예제 #2
0
 /**
  * copy a record
  * @param  int     $id
  * @return boolean
  */
 public static function copy($sourceId, $targetId)
 {
     $r = Tree::read($targetId);
     $pid = empty($r) ? null : $r['pid'];
     DB\dbQuery('INSERT INTO ' . static::getTableName() . '
             (id,
             pid,
             `is_folder`,
             `type`,
             `name`,
             `l1`,
             `l2`,
             `l3`,
             `l4`,
             `order`,
             `visible`,
             `iconCls`,
             `default_field`,
             `cfg`,
             `title_template`,
             `info_template`)
         SELECT
             $2,
             $3,
             `is_folder`,
             `type`,
             `name`,
             `l1`,
             `l2`,
             `l3`,
             `l4`,
             `order`,
             `visible`,
             `iconCls`,
             `default_field`,
             `cfg`,
             `title_template`,
             `info_template`
         FROM ' . static::getTableName() . '
         WHERE id = $1', array($sourceId, $targetId, $pid));
     return DB\dbAffectedRows() > 0;
 }
예제 #3
0
 /**
  * create an object with specified params
  * @param  array $p object properties
  * @return int   created id
  */
 public function create($p = false)
 {
     if ($p === false) {
         $p = $this->data;
     }
     // check input params
     if (!isset($p['target_id'])) {
         throw new \Exception("No target id specified for shortcut creation", 1);
     }
     //check if target is also shortuc and replace with its target
     if (Objects::getType($p['target_id']) == 'shortcut') {
         $r = DM\Tree::read($p['target_id']);
         if (!empty($r)) {
             $p['target_id'] = $r['target_id'];
         }
     }
     $p['name'] = 'link to #' . $p['target_id'];
     if (empty($p['template_id'])) {
         $p['template_id'] = \CB\Config::get('default_shortcut_template');
     }
     $this->data = $p;
     return parent::create($p);
 }
예제 #4
0
파일: Files.php 프로젝트: sebbie42/casebox
 public function restoreVersion($id)
 {
     $rez = array('success' => true, 'data' => array('id' => 0, 'pid' => 0));
     $fileId = 0;
     //detect file id
     $version = DM\FilesVersions::read($id);
     if (!empty($version)) {
         $fileId = $version['file_id'];
         $rez['data']['id'] = $fileId;
     }
     //get its pid
     $r = DM\Tree::read($fileId);
     if (!empty($r['pid'])) {
         $rez['data']['pid'] = $r['pid'];
     }
     $this->saveCurrentVersion($fileId);
     DM\Files::delete($fileId);
     DM\Files::create(array('id' => $fileId, 'content_id' => $version['content_id'], 'date' => $version['date'], 'name' => $version['name'], 'cid' => $version['cid'], 'uid' => User::getId(), 'cdate' => $version['cdate'], 'udate' => $version['udate']));
     Objects::updateCaseUpdateInfo($id);
     Solr\Client::runCron();
     return $rez;
 }
예제 #5
0
 /**
  * setting security inheritance flag for an item
  *
  * @param array $p {
  *     @type int      $id    id of tree node
  *     @type boolean  $inherit    set inherit to true or false
  *     @type string   $copyRules   when removing inheritance ($inherit = false)
  *                                 then this value could be set to 'yes' or 'no'
  *                                 for copying inherited rules to current node
  * }
  *
  */
 public function setInheritance($p)
 {
     /* check input params */
     if (empty($p['id']) || !isset($p['inherit']) || !is_numeric($p['id']) || !is_bool($p['inherit'])) {
         throw new \Exception(L\get('Wrong_input_data'));
     }
     /* end of check input params */
     if (!Security::isAdmin() && !Security::canChangePermissions($p['id'])) {
         throw new \Exception(L\get('Access_denied'));
     }
     /* checking if current inherit value is not already set to requested state */
     $inherit_acl = false;
     $r = DM\Tree::read($p['id']);
     if (!empty($r)) {
         $inherit_acl = $r['inherit_acl'];
     } else {
         throw new \Exception(L\get('Object_not_found'));
     }
     if ($inherit_acl == $p['inherit']) {
         return array('success' => false);
     }
     /* end of checking if current inherit value is not already set to requested state */
     // make pre update changes
     if ($p['inherit']) {
         DB\dbQuery('DELETE from tree_acl WHERE node_id = $1', $p['id']);
     } else {
         switch (@$p['copyRules']) {
             case 'yes':
                 //copy all inherited rules to current object
                 $acl = $this->getObjectAcl($p);
                 foreach ($acl['data'] as $rule) {
                     $allow = explode(',', str_replace('2', '1', $rule['allow']));
                     $deny = explode(',', str_replace('2', '1', $rule['deny']));
                     for ($i = 0; $i < 12; $i++) {
                         $allow[$i] = $allow[$i] == 1 ? '1' : '0';
                         $deny[$i] = $deny[$i] == -1 ? '1' : '0';
                     }
                     $allow = array_reverse($allow);
                     $deny = array_reverse($deny);
                     $allow = bindec(implode('', $allow));
                     $deny = bindec(implode('', $deny));
                     DB\dbQuery('INSERT INTO tree_acl (
                             node_id
                             ,user_group_id
                             ,allow
                             ,deny
                             ,cid)
                         VALUES($1
                              ,$2
                              ,$3
                              ,$4
                              ,$5) ON duplicate KEY
                         UPDATE allow = $3
                                 ,deny = $4
                                 ,uid = $5
                                 ,udate = CURRENT_TIMESTAMP', array($p['id'], $rule['id'], $allow, $deny, User::getId()));
                 }
                 break;
             default:
                 DB\dbQuery('DELETE from tree_acl WHERE node_id = $1', $p['id']);
                 break;
         }
     }
     // updating inherit flag for the object
     DM\Tree::update(array('id' => $p['id'], 'inherit_acl' => intval($p['inherit'])));
     Security::calculateUpdatedSecuritySets();
     Solr\Client::runBackgroundCron();
     return array('success' => true, 'data' => array());
 }
예제 #6
0
 /**
  * checks if given id exists in our tree
  * @param  int     $id
  * @return boolean
  */
 public static function idExists($id)
 {
     $rez = false;
     if (empty($id)) {
         return $rez;
     }
     $r = DM\Tree::read($id);
     $rez = !empty($r);
     return $rez;
 }
예제 #7
0
 /**
  * move an object to $pid or over $targetId
  *
  * we'll use the same principle as for copy
  *
  * @param  int $pid      if not specified then will be set to pid of targetId
  * @param  int $targetId
  * @return int the id of moved object or false
  */
 public function moveTo($pid = false, $targetId = false)
 {
     // check input params
     if (!is_numeric($this->id) || !is_numeric($pid) && !is_numeric($targetId)) {
         return false;
     }
     /* security check */
     if (!\CB\Security::canRead($this->id)) {
         return false;
     }
     /* end of security check */
     //load current object from db into a variable to be passed to log and events
     $this->oldObject = clone $this;
     $this->oldObject->load($this->id);
     if (is_numeric($targetId)) {
         /* target security check */
         if (!\CB\Security::canWrite($targetId)) {
             return false;
         }
         /* end of target security check */
         // marking overwriten object with dstatus = 3
         DM\Tree::update(array('id' => $targetId, 'updated' => 1, 'dstatus' => 3, 'did' => User::getId()));
         $r = DM\Tree::read($targetId);
         if (!empty($r)) {
             $pid = $r['pid'];
         }
     } else {
         /* pid security check */
         if (!\CB\Security::canWrite($pid)) {
             return false;
         }
         /* end of pid security check */
     }
     /* check again if we have pid set
            It can be unset when not existent $targetId is specified
        */
     if (!is_numeric($pid)) {
         return false;
     }
     // moving the object to $pid
     DM\Tree::update(array('id' => $this->id, 'pid' => $pid, 'updated' => 1));
     $this->moveCustomDataTo($pid);
     // move childs from overwriten targetId (which has been marked with dstatus = 3)
     // to newly copied object
     if (is_numeric($targetId)) {
         DM\Tree::moveActiveChildren($targetId, $this->id);
     }
     $this->load();
     $this->logAction('move', array('old' => $this->oldObject));
     return $this->id;
 }
예제 #8
0
 public function rename($p)
 {
     $id = explode('/', $p['path']);
     $id = array_pop($id);
     $p['name'] = trim($p['name']);
     if (!is_numeric($id) || empty($p['name'])) {
         return array('success' => false);
     }
     /* check security access */
     if (!Security::canWrite($id)) {
         throw new \Exception(L\get('Access_denied'));
     }
     $p['name'] = Purify::filename($p['name']);
     $rez = array('success' => true, 'data' => array('id' => $id, 'pid' => null, 'newName' => $p['name']));
     $objectType = Objects::getType($id);
     if ($objectType == 'shortcut') {
         $r = DM\Tree::read($id);
         if (!empty($r['target_id'])) {
             $id = $r['target_id'];
             $objectType = Objects::getType($id);
         }
     }
     DM\Tree::update(array('id' => $id, 'name' => $p['name']));
     if ($objectType == 'file') {
         DM\Files::update(array('id' => $id, 'name' => $p['name']));
     }
     /*updating renamed document into solr directly (before runing background cron)
       so that it'll be displayed with new name without delay*/
     $solrClient = new Solr\Client();
     $solrClient->updateTree(array('id' => $id));
     //running background cron to index other nodes
     $solrClient->runBackgroundCron();
     $p['name'] = htmlspecialchars($p['name'], ENT_COMPAT);
     //get pid
     $r = DM\Tree::read($rez['data']['id']);
     if (!empty($r['pid'])) {
         $rez['data']['pid'] = $r['pid'];
     }
     return $rez;
 }
예제 #9
0
파일: Dbnode.php 프로젝트: sebbie42/casebox
 /**
  * get param for this node
  *
  * @param  varchar $param for now using to get 'facets' or 'DC'
  * @return array
  */
 public function getNodeParam($param = 'facets')
 {
     $rez = false;
     $from = $this->getId();
     //check if cached
     $cacheParam = 'nodeParam_' . $param . '_' . $from;
     if (Cache::exist($cacheParam)) {
         return Cache::get($cacheParam);
     }
     $cfg = array();
     $templateId = null;
     $tplCfg = array();
     if (!empty($this->id) && is_numeric($this->id)) {
         $r = DM\Tree::read($this->id);
     }
     if (!empty($r)) {
         $cfg = $r['cfg'];
         $templateId = $r['template_id'];
     }
     if (!empty($this->config['template_id'])) {
         $templateId = $this->config['template_id'];
     }
     if (!empty($templateId)) {
         $r = DM\Templates::read($templateId);
         if (!empty($r)) {
             $tplCfg = $r['cfg'];
         }
     }
     if (isset($cfg[$param])) {
         $rez = $cfg[$param];
     } elseif (isset($tplCfg[$param])) {
         $cfg = $tplCfg;
         $rez = $cfg[$param];
         $from = 'template_' . $templateId;
     }
     //add grouping param for DC
     if ($param == 'DC' && $rez !== false) {
         if (!empty($cfg['view']['group'])) {
             $rez['group'] = $cfg['view']['group'];
         } elseif (!empty($cfg['group'])) {
             $rez['group'] = $cfg['group'];
         }
     }
     if ($rez === false) {
         $rez = parent::getNodeParam($param);
     } else {
         $rez = array('from' => $from, 'data' => $rez);
     }
     Cache::set($cacheParam, $rez);
     return $rez;
 }