コード例 #1
0
ファイル: RecycleBin.php プロジェクト: youprofit/casebox
 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
ファイル: Path.php プロジェクト: sebbie42/casebox
 public static function getPath($id, $excludeItself = false)
 {
     $rez = array('success' => false);
     if (!is_numeric($id)) {
         return $rez;
     }
     $r = DM\Tree::getBasicInfo($id);
     if (!empty($r)) {
         $p = explode(',', $r['pids']);
         if ($excludeItself) {
             array_pop($r['pids']);
         }
         $p = implode('/', $p);
         $rez = array('success' => true, 'id' => $id, 'name' => $r['name'], 'path' => $p);
     }
     return $rez;
 }
コード例 #3
0
ファイル: Templates.php プロジェクト: sebbie42/casebox
 /**
  * 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;
 }
コード例 #4
0
ファイル: BrowserTree.php プロジェクト: sebbie42/casebox
 public function getChildren($p)
 {
     $p['from'] = 'tree';
     $rez = parent::getChildren($p);
     //collect resulting record ids and get their children
     $ids = array();
     foreach ($rez['data'] as &$d) {
         $ids[] = $d['nid'];
     }
     $children = DM\Tree::getChildCount($ids);
     foreach ($rez['data'] as &$d) {
         if (!isset($d['loaded'])) {
             if (!isset($d['has_childs'])) {
                 $d['has_childs'] = !empty($children[$d['nid']]);
             }
             $d['loaded'] = empty($d['has_childs']);
         }
     }
     return $rez['data'];
 }
コード例 #5
0
ファイル: Shortcut.php プロジェクト: sebbie42/casebox
 /**
  * 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);
 }
コード例 #6
0
ファイル: Files.php プロジェクト: sebbie42/casebox
 /**
  * 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);
 }
コード例 #7
0
ファイル: Security.php プロジェクト: sebbie42/casebox
 /**
  * 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());
 }
コード例 #8
0
ファイル: CreateMenu.php プロジェクト: sebbie42/casebox
 /**
  * get the menu config for a given path or id
  * @param  varchar | int $path path string or node id
  * @return [type]        [description]
  */
 public static function getMenuForPath($path)
 {
     $rez = '';
     //get item path if id specified
     if (is_numeric($path)) {
         $tmp = \CB\Path::getPath($path);
         $path = '/' . $tmp['path'];
     }
     if (is_string($path)) {
         $path = explode('/', $path);
     }
     $path = array_reverse(array_filter($path, 'is_numeric'));
     $path = Util\toNumericArray($path);
     // get templates for each path elements
     $nodeTemplate = array();
     $recs = DM\Tree::readByIds($path);
     foreach ($recs as $r) {
         $nodeTemplate[$r['id']] = $r['template_id'];
     }
     //get db menu into variable
     $menu = static::getMenuRules();
     $ugids = isset($_SESSION['user']['groups']) ? $_SESSION['user']['groups'] : array();
     $ugids[] = $_SESSION['user']['id'];
     // we have 3 main criterias for detecting needed menu:
     //  - user_group_ids - records for specific users or groups
     //  - node_ids
     //  - template_ids
     //
     // we'll iterate the path from the end and detect the menu
     $lastWeight = 0;
     for ($i = 0; $i < sizeof($path); $i++) {
         //firstly we'll check if we find a menu row with id or template of the node
         foreach ($menu as $m) {
             $weight = 0;
             if (in_array($path[$i], $m['nids'])) {
                 $weight += 50;
             } elseif (empty($m['nids'])) {
                 $weight += 1;
             } else {
                 //skip this record because it contain nids and not contain this node id
                 continue;
             }
             if (in_array($nodeTemplate[$path[$i]], $m['ntids'])) {
                 $weight += 50;
             } elseif (empty($m['ntids'])) {
                 $weight += 1;
             } else {
                 //skip this record because it has ntids specified and not contain this node template id
                 continue;
             }
             if (empty($m['ugids'])) {
                 $weight += 1;
             } else {
                 $int = array_intersect($ugids, $m['ugids']);
                 if (empty($int)) {
                     continue;
                 } else {
                     $weight += 10;
                 }
             }
             if ($weight > $lastWeight) {
                 $lastWeight = $weight;
                 $rez = $m['menu'];
             }
         }
         //if nid matched or template matched then dont iterate further
         if ($lastWeight > 50) {
             return $rez;
         }
     }
     return $rez;
 }
コード例 #9
0
ファイル: Objects.php プロジェクト: sebbie42/casebox
 /**
  * get a child node id by its name under specified $pid
  * @param  int           $id
  * @param  varchar|array $name direct child name or the list of child, subchild, ...
  * @return int|null
  */
 public static function getChildId($pid, $name)
 {
     if (!is_array($name)) {
         $name = array($name);
     }
     do {
         $n = array_shift($name);
         $r = DM\Tree::getChildByName($pid, $n);
         if (!empty($r)) {
             $pid = $r['id'];
         } else {
             $pid = null;
         }
     } while (!empty($pid) && !empty($name));
     return $pid;
 }
コード例 #10
0
 /**
  * sync config table ids with those from tree
  * @return void
  */
 protected function syncConfigIds()
 {
     echo "Sync config ids .. ";
     $rootId = Browser::getRootFolderId();
     $pid = Objects::getChildId($rootId, 'System');
     $pid = Objects::getChildId($pid, 'Config');
     $ref = array();
     $left = array();
     $lastLength = 0;
     $rows = DM\Config::readAll();
     //add root nodes
     foreach ($rows as &$r) {
         if (empty($r['pid'])) {
             $tr = DM\Tree::getChildByName($pid, $r['param']);
             if (empty($tr)) {
                 DM\Config::delete($r['id']);
             } else {
                 $ref[$r['id']] =& $r;
                 $r['treeRecord'] = $tr;
             }
         } else {
             $left[] =& $r;
         }
     }
     while (!empty($left) && sizeof($left) != $lastLength) {
         $rows = $left;
         $lastLength = sizeOf($left);
         $left = array();
         foreach ($rows as &$r) {
             if (isset($ref[$r['pid']]) && !empty($ref[$r['pid']]['treeRecord'])) {
                 $ref[$r['id']] =& $r;
                 $r['treeRecord'] = DM\Tree::getChildByName($ref[$r['pid']]['treeRecord']['id'], $r['param']);
             } else {
                 $left[] =& $r;
             }
         }
     }
     //iterate and update config table
     foreach ($ref as &$r) {
         $tr = $r['treeRecord'];
         $pid = empty($ref[$r['pid']]['treeRecord']) ? null : $ref[$r['pid']]['treeRecord']['id'];
         DB\dbQuery('UPDATE config
             SET
                 id = $2
                 ,pid = $3
             WHERE id = $1', array($r['id'], $tr['id'], $pid));
     }
     echo "Ok \n";
 }
コード例 #11
0
ファイル: Object.php プロジェクト: youprofit/casebox
 /**
  * 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;
 }
コード例 #12
0
ファイル: Browser.php プロジェクト: sebbie42/casebox
 public static function getRootProperties($id)
 {
     $rez = array('success' => true, 'data' => array());
     $r = DM\Tree::getProperties($id);
     if (!empty($r)) {
         $rez['data'] = array($r);
         Browser::updateLabels($rez['data']);
         $rez['data'] = $rez['data'][0];
     }
     return $rez;
 }
コード例 #13
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;
 }