diff --git a/module/action/model.php b/module/action/model.php index 09f5a53631..62b0d723d3 100755 --- a/module/action/model.php +++ b/module/action/model.php @@ -539,10 +539,8 @@ class actionModel extends model } $this->loadModel('doc'); - $docCondition = $this->doc->buildConditionSQL('doc'); - $libCondition = $this->doc->buildConditionSQL('lib'); - if($docCondition) $docCondition = $this->dao->select('id')->from(TABLE_DOC)->where($docCondition)->andWhere('deleted')->eq(0)->get(); - if($libCondition) $libCondition = $this->dao->select('id')->from(TABLE_DOCLIB)->where($libCondition)->andWhere('deleted')->eq(0)->get(); + $libs = $this->doc->getLibs('all'); + $docs = $this->doc->getPrivDocs(array_keys($libs)); /* Get actions. */ $actions = $this->dao->select('*')->from(TABLE_ACTION) @@ -554,9 +552,9 @@ class actionModel extends model ->beginIF(is_numeric($projectID))->andWhere('project')->eq($projectID)->fi() ->beginIF($productID == 'notzero')->andWhere('product')->gt(0)->fi() ->beginIF($projectID == 'notzero')->andWhere('project')->gt(0)->fi() - ->beginIF($projectID == 'all' or $productID == 'all')->andWhere("($condition)")->fi() - ->beginIF($docCondition)->andWhere("IF(objectType != 'doc', '1=1', objectID in ($docCondition))")->fi() - ->beginIF($libCondition)->andWhere("IF(objectType != 'doclib', '1=1', objectID in ($libCondition))")->fi() + ->beginIF($projectID == 'all' or $productID == 'all')->andWhere("IF((objectType!= 'doc' && objectType!= 'doclib'), ($condition), '1=1')")->fi() + ->beginIF($docs)->andWhere("IF(objectType != 'doc', '1=1', objectID " . helper::dbIN($docs) . ")")->fi() + ->beginIF($libs)->andWhere("IF(objectType != 'doclib', '1=1', objectID " . helper::dbIN(array_keys($libs)) . ') ')->fi() ->orderBy($orderBy)->page($pager)->fetchAll(); if(!$actions) return array(); diff --git a/module/doc/model.php b/module/doc/model.php index 4035cfd148..0cb305d04a 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -89,20 +89,6 @@ class docModel extends model return $this->dao->findByID($libID)->from(TABLE_DOCLIB)->fetch(); } - /** - * Get lib by object. - * - * @param string $type - * @param int $objectID - * @access public - * @return array - */ - public function getLibByObject($type, $objectID) - { - if($type != 'project' and $type != 'product') return true; - return $this->dao->select('*')->from(TABLE_DOCLIB)->where($type)->eq($objectID)->andWhere('deleted')->eq('0')->fetchAll('id'); - } - /** * Get libraries. * @@ -121,6 +107,10 @@ class docModel extends model ->orderBy("t2.order desc, t1.order, t1.id") ->query(); } + elseif($type == 'all') + { + $stmt = $this->dao->select('*')->from(TABLE_DOCLIB)->where('deleted')->eq(0)->orderBy('`order`, id desc')->query(); + } else { $stmt = $this->dao->select('*')->from(TABLE_DOCLIB)->where('deleted')->eq(0)->andWhere('product')->eq('0')->andWhere('project')->eq(0)->orderBy('`order`, id desc')->query(); @@ -200,11 +190,10 @@ class docModel extends model } elseif($browseType == "openedbyme") { - $condition = $this->buildConditionSQL('doc'); $docs = $this->dao->select('*')->from(TABLE_DOC) ->where('deleted')->eq(0) ->andWhere('lib')->in($libID) - ->beginIF($condition)->andWhere("($condition)")->fi() + ->andWhere('addedBy')->eq($this->app->user->account) ->orderBy($sort) ->page($pager) ->fetchAll(); @@ -217,13 +206,7 @@ class docModel extends model } elseif($browseType == "bymenu") { - $condition = $this->buildConditionSQL('doc'); - $docs = $this->dao->select('*')->from(TABLE_DOC)->where('deleted')->eq(0)->andWhere('lib')->in($libID) - ->andWhere('module')->eq($moduleID) - ->beginIF($condition)->andWhere("($condition)")->fi() - ->orderBy($sort) - ->page($pager) - ->fetchAll(); + $docs = $this->getDocs($libID, $moduleID, $sort, $pager); } elseif($browseType == 'bytree') { @@ -256,16 +239,15 @@ class docModel extends model $docQuery = str_replace("`project` = 'all'", '1', $docQuery); // Search all project. $docQuery = str_replace("`lib` = 'all'", '1', $docQuery); // Search all lib. - $condition = $this->buildConditionSQL('lib'); - $libIdList = $this->dao->select('id')->from(TABLE_DOCLIB)->beginIF($condition)->where("($condition)")->fi()->get(); - $docs = $this->dao->select('*')->from(TABLE_DOC)->where($docQuery) - ->beginIF($condition)->andWhere("($condition)")->fi() ->beginIF(!$libCond)->andWhere("lib")->eq($libID)->fi() - ->beginIF($allLibCond and $condition)->andWhere("lib in ($libIdList)")->fi() ->andWhere('deleted')->eq(0) - ->orderBy($sort)->page($pager) - ->fetchAll(); + ->fetchAll('id'); + foreach($docs as $docID => $doc) + { + if(!$this->checkPriv($doc)) unset($docs[$docID]); + } + $docs = $this->dao->select('*')->from(TABLE_DOC)->where('id')->in(array_keys($docs))->orderBy($sort)->page($pager)->fetchAll(); } $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'doc'); @@ -286,17 +268,39 @@ class docModel extends model * @access public * @return void */ - public function getDocs($libID, $module, $orderBy, $pager) + public function getDocs($libID, $module, $orderBy, $pager = null) { - $condition = $this->buildConditionSQL('doc'); + $docIdList = $this->getPrivDocs($libID, $module); return $this->dao->select('*')->from(TABLE_DOC) ->where('deleted')->eq(0) - ->andWhere('lib')->in($libID) - ->beginIF($condition)->andWhere("($condition)")->fi() - ->beginIF($module)->andWhere('module')->in($module)->fi() + ->andWhere('id')->in($docIdList) ->orderBy($orderBy) ->page($pager) - ->fetchAll(); + ->fetchAll('id'); + } + + /** + * Get priv docs. + * + * @param int $libID + * @param int $module + * @access public + * @return void + */ + public function getPrivDocs($libID = 0, $module = 0) + { + $stmt = $this->dao->select('*')->from(TABLE_DOC) + ->where('deleted')->eq(0) + ->beginIF($libID)->andWhere('lib')->in($libID)->fi() + ->beginIF($module)->andWhere('module')->in($module)->fi() + ->query(); + + $docIdList = array(); + while($doc = $stmt->fetch()) + { + if($this->checkPriv($doc)) $docIdList[$doc->id] = $doc->id; + } + return $docIdList; } /** @@ -595,7 +599,7 @@ class docModel extends model * @access public * @return bool */ - public function checkPriv($object) + public function checkPriv($object, $type = 'lib') { if($object->acl == 'open') return true; @@ -613,17 +617,27 @@ class docModel extends model if(strpos(",$object->groups,", ",$groupID,") !== false) return true; } } - - if($object->product) + + if(isset($object->lib)) { - $product = $this->dao->findById($object->product)->from(TABLE_PRODUCT)->fetch(); - return $this->loadModel('product')->checkPriv($product); + static $libs; + if(empty($libs)) $libs = $this->getLibs('all'); + if(!isset($libs[$object->lib])) return false; + } if($object->project) { - $project = $this->dao->findById($object->project)->from(TABLE_PROJECT)->fetch(); - return $this->loadModel('project')->checkPriv($project); + static $projects; + if(empty($projects)) $projects = $this->loadModel('project')->getPairs(); + return isset($projects[$object->project]); + } + + if($object->product) + { + static $products; + if(empty($products)) $products = $this->loadModel('product')->getPairs(); + return isset($products[$object->product]); } return false; @@ -642,7 +656,8 @@ class docModel extends model { if($product and $type == 'project') $projects = $this->dao->select('*')->from(TABLE_PROJECTPRODUCT)->where('product')->eq($product)->fetchPairs('project', 'project'); - $key = ($type == 'product' or $type == 'project') ? $type : 'id'; + $libs = $this->getLibs($type); + $key = ($type == 'product' or $type == 'project') ? $type : 'id'; $stmt = $this->dao->select("DISTINCT $key")->from(TABLE_DOCLIB)->where('deleted')->eq(0); if($type == 'product' or $type == 'project') { @@ -654,8 +669,7 @@ class docModel extends model } if(isset($projects)) $stmt = $stmt->andWhere('project')->in($projects); - $condition = $this->buildConditionSQL('lib'); - $idList = $stmt->beginIF($condition)->andWhere("($condition)")->fi()->orderBy("{$key}_desc")->page($pager, $key)->fetchPairs($key, $key); + $idList = $stmt->andWhere('id')->in(array_keys($libs))->orderBy("{$key}_desc")->page($pager, $key)->fetchPairs($key, $key); if($type == 'product' or $type == 'project') { @@ -678,10 +692,10 @@ class docModel extends model */ public function getAllLibGroups() { - $condition = $this->buildConditionSQL('lib'); + $libs = $this->getLibs('all'); $stmt = $this->dao->select("id,product,project,name")->from(TABLE_DOCLIB) ->where('deleted')->eq(0) - ->beginIF($condition)->andWhere("($condition)")->fi() + ->andWhere("id")->in(array_keys($libs)) ->orderBy("product desc,project desc, `order` asc, id asc") ->query(); @@ -942,31 +956,6 @@ class docModel extends model return $files; } - /** - * Build condition SQL for priv. - * - * @param string $table - * @access public - * @return string - */ - public function buildConditionSQL($type = 'lib', $table = '') - { - if($table) $table .= '.'; - $condition = ''; - $account = ',' . $this->app->user->account . ','; - if(!$this->app->user->admin) - { - $condition .= "{$table}acl='open'"; - if($type == 'doc') $condition .= " OR {$table}addedBy = '{$this->app->user->account}'"; - $condition .= " OR ({$table}acl='private' and CONCAT(',', {$table}users, ',') like '%$account%')"; - $condition .= " OR ({$table}acl='custom' and ("; - foreach($this->app->user->groups as $groupID) $condition .= "(CONCAT(',', {$table}groups, ',') like '%,$groupID,%') OR "; - $condition .= "(CONCAT(',', {$table}users, ',') like '%$account%')"; - $condition .= "))"; - } - return $condition; - } - /** * Get doc tree. * @@ -1001,14 +990,15 @@ class docModel extends model static $docGroups; if(empty($docGroups)) { - $condition = $this->buildConditionSQL('doc'); $docs = $this->dao->select('*')->from(TABLE_DOC) ->where('lib')->eq((int)$libID) - ->beginIF($condition)->andWhere("($condition)")->fi() ->andWhere('deleted')->eq(0) ->fetchAll(); $docGroups = array(); - foreach($docs as $doc) $docGroups[$doc->module][$doc->id] = $doc; + foreach($docs as $doc) + { + if($this->checkPriv($doc)) $docGroups[$doc->module][$doc->id] = $doc; + } } if(!empty($node->children)) foreach($node->children as $i => $child) $node->children[$i] = $this->fillDocsInTree($child, $libID); @@ -1295,9 +1285,7 @@ class docModel extends model */ public function setLibUsers($type, $objectID) { - if($type != 'project' and $type != 'product') return true; - $libs = $this->dao->select('*')->from(TABLE_DOCLIB)->where($type)->eq($objectID)->fetchAll(); - + if($type != 'project' and $type != 'product') return array(); if($type == 'product') { $teams = $this->dao->select('t1.account')->from(TABLE_TEAM)->alias('t1') @@ -1312,11 +1300,6 @@ class docModel extends model $teams = $this->dao->select('account')->from(TABLE_TEAM)->where('project')->eq($objectID)->fetchPairs('account', 'account'); } - foreach($libs as $lib) - { - foreach(explode(',', $lib->users) as $account) $teams[$account] = $account; - $this->dao->update(TABLE_DOCLIB)->set('users')->eq(join(',', $teams))->where('id')->eq($lib->id)->exec(); - } - return true; + return $teams; } } diff --git a/module/product/model.php b/module/product/model.php index a415deb3a3..00d4935da3 100644 --- a/module/product/model.php +++ b/module/product/model.php @@ -289,7 +289,7 @@ class productModel extends model $lib->product = $productID; $lib->name = $this->lang->doclib->main['product']; $lib->main = '1'; - $lib->acl = 'private'; + $lib->acl = $product->acl == 'open' ? 'open' : 'private'; $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); return $productID; @@ -321,6 +321,8 @@ class productModel extends model ->exec(); if(!dao::isError()) { + if($product->acl != $oldProduct->acl) $this->dao->update(TABLE_DOCLIB)->set('acl')->eq($product->acl == 'open' ? 'open' : 'private')->where('product')->eq($productID)->exec(); + $this->file->updateObjectID($this->post->uid, $productID, 'product'); return common::createChanges($oldProduct, $product); } diff --git a/module/project/model.php b/module/project/model.php index 37028d47d8..db3b1b83f9 100644 --- a/module/project/model.php +++ b/module/project/model.php @@ -289,7 +289,7 @@ class projectModel extends model $lib->project = $projectID; $lib->name = $this->lang->doclib->main['project']; $lib->main = '1'; - $lib->acl = 'private'; + $lib->acl = $project->acl == 'open' ? 'open' : 'private'; $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); return $projectID; @@ -348,6 +348,8 @@ class projectModel extends model } if(!dao::isError()) { + if($project->acl != $oldProject->acl) $this->dao->update(TABLE_DOCLIB)->set('acl')->eq($project->acl == 'open' ? 'open' : 'private')->where('project')->eq($projectID)->exec(); + $this->file->updateObjectID($this->post->uid, $projectID, 'project'); return common::createChanges($oldProject, $project); } diff --git a/www/js/jquery/syntaxhighlighter/styles/shCore.css b/www/js/jquery/syntaxhighlighter/styles/shCore.css index c6388a8aba..c92ff92baf 100755 --- a/www/js/jquery/syntaxhighlighter/styles/shCore.css +++ b/www/js/jquery/syntaxhighlighter/styles/shCore.css @@ -224,3 +224,4 @@ .syntaxhighlighter.printing .break, .syntaxhighlighter.printing .break a { color: black !important; } +.syntaxhighlighter .container::before{content:none;}