Exemple #1
0
 /**
  * Adds a group for a right at a given systemid
  * <b>NOTE: By setting rights using this method, inheritance is set to false!!!</b>
  *
  * @param string $strGroupId
  * @param string $strSystemid
  * @param string $strRight one of view, edit, delete, right, right1, right2, right3, right4, right5
  *
  * @return bool
  */
 public function addGroupToRight($strGroupId, $strSystemid, $strRight)
 {
     $this->objDb->flushQueryCache();
     $this->flushRightsCache();
     //Load the current rights
     $arrRights = $this->getArrayRights($strSystemid, false);
     //rights not given, add now, disabling inheritance
     $arrRights[self::$STR_RIGHT_INHERIT] = 0;
     //add the group to the row
     if (!in_array($strGroupId, $arrRights[$strRight])) {
         $arrRights[$strRight][] = $strGroupId;
     }
     //build a one-dim array
     $arrRights[self::$STR_RIGHT_VIEW] = implode(",", $arrRights[self::$STR_RIGHT_VIEW]);
     $arrRights[self::$STR_RIGHT_EDIT] = implode(",", $arrRights[self::$STR_RIGHT_EDIT]);
     $arrRights[self::$STR_RIGHT_DELETE] = implode(",", $arrRights[self::$STR_RIGHT_DELETE]);
     $arrRights[self::$STR_RIGHT_RIGHT] = implode(",", $arrRights[self::$STR_RIGHT_RIGHT]);
     $arrRights[self::$STR_RIGHT_RIGHT1] = implode(",", $arrRights[self::$STR_RIGHT_RIGHT1]);
     $arrRights[self::$STR_RIGHT_RIGHT2] = implode(",", $arrRights[self::$STR_RIGHT_RIGHT2]);
     $arrRights[self::$STR_RIGHT_RIGHT3] = implode(",", $arrRights[self::$STR_RIGHT_RIGHT3]);
     $arrRights[self::$STR_RIGHT_RIGHT4] = implode(",", $arrRights[self::$STR_RIGHT_RIGHT4]);
     $arrRights[self::$STR_RIGHT_RIGHT5] = implode(",", $arrRights[self::$STR_RIGHT_RIGHT5]);
     $arrRights[self::$STR_RIGHT_CHANGELOG] = implode(",", $arrRights[self::$STR_RIGHT_CHANGELOG]);
     //and save the row
     $bitReturn = $this->setRights($arrRights, $strSystemid);
     return $bitReturn;
 }
Exemple #2
0
 /**
  * Generates a new SystemRecord and, if needed, the corresponding record in the rights-table (here inheritance is default)
  * Returns the systemID used for this record
  *
  * @param string $strPrevId  Previous ID in the tree-structure
  * @param string $strComment Comment to identify the record
  * @return string The ID used/generated
  *
  * * @todo find ussages and make private
  */
 private function createSystemRecord($strPrevId, $strComment)
 {
     $strSystemId = generateSystemid();
     $this->setStrSystemid($strSystemId);
     //Correct prevID
     if ($strPrevId == "") {
         $strPrevId = 0;
     }
     $this->setStrPrevId($strPrevId);
     //determine the correct new sort-id - append by default
     if (class_module_system_module::getModuleByName("system") != null && version_compare(class_module_system_module::getModuleByName("system")->getStrVersion(), "4.7.5", "lt")) {
         $strQuery = "SELECT COUNT(*) FROM " . _dbprefix_ . "system WHERE system_prev_id = ? AND system_id != '0'";
     } else {
         $strQuery = "SELECT COUNT(*) FROM " . _dbprefix_ . "system WHERE system_prev_id = ? AND system_id != '0' AND system_deleted = 0";
     }
     $arrRow = $this->objDB->getPRow($strQuery, array($strPrevId), 0, false);
     $intSiblings = $arrRow["COUNT(*)"];
     $strComment = uniStrTrim(strip_tags($strComment), 240);
     if (class_module_system_module::getModuleByName("system") != null && version_compare(class_module_system_module::getModuleByName("system")->getStrVersion(), "4.7.5", "lt")) {
         //So, lets generate the record
         $strQuery = "INSERT INTO " . _dbprefix_ . "system\n                     ( system_id, system_prev_id, system_module_nr, system_owner, system_create_date, system_lm_user,\n                       system_lm_time, system_status, system_comment, system_sort, system_class) VALUES\n                     (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
         //Send the query to the db
         $this->objDB->_pQuery($strQuery, array($strSystemId, $strPrevId, $this->getIntModuleNr(), $this->objSession->getUserID(), class_date::getCurrentTimestamp(), $this->objSession->getUserID(), time(), (int) $this->getIntRecordStatus(), $strComment, $this->getNextSortValue($strPrevId), $this->getStrRecordClass()));
     } else {
         //So, lets generate the record
         $strQuery = "INSERT INTO " . _dbprefix_ . "system\n                     ( system_id, system_prev_id, system_module_nr, system_owner, system_create_date, system_lm_user,\n                       system_lm_time, system_status, system_comment, system_sort, system_class, system_deleted) VALUES\n                     (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
         //Send the query to the db
         $this->objDB->_pQuery($strQuery, array($strSystemId, $strPrevId, $this->getIntModuleNr(), $this->objSession->getUserID(), class_date::getCurrentTimestamp(), $this->objSession->getUserID(), time(), (int) $this->getIntRecordStatus(), $strComment, (int) ($intSiblings + 1), $this->getStrRecordClass(), $this->getIntRecordDeleted()));
     }
     //we need a Rights-Record
     $this->objDB->_pQuery("INSERT INTO " . _dbprefix_ . "system_right (right_id, right_inherit) VALUES (?, 1)", array($strSystemId));
     //update rights to inherit
     class_carrier::getInstance()->getObjRights()->setInherited(true, $strSystemId);
     class_logger::getInstance()->addLogRow("new system-record created: " . $strSystemId . " (" . $strComment . ")", class_logger::$levelInfo);
     $this->objDB->flushQueryCache();
     $this->internalInit();
     //reset the old values since we're having a new record
     $this->strOldPrevId = -1;
     $this->intOldRecordStatus = -1;
     return $strSystemId;
 }
 /**
  * Sets the position of systemid using a given value.
  *
  * @param int $intNewPosition
  * @param array|bool $arrRestrictionModules If an array of module-ids is passed, the determination of siblings will be limited to the module-records matching one of the module-ids
  *
  * @throws class_exception
  * @return void
  */
 public function setAbsolutePosition($intNewPosition, $arrRestrictionModules = false)
 {
     class_logger::getInstance()->addLogRow("move " . $this->objSource->getSystemid() . " to new pos " . $intNewPosition, class_logger::$levelInfo);
     $this->objDB->flushQueryCache();
     //validate if object is sortable
     if (!$this->objSource->getLockManager()->isAccessibleForCurrentUser()) {
         throw new class_exception("Object is locked", class_exception::$level_ERROR);
     }
     $arrParams = array();
     $arrParams[] = $this->objSource->getPrevId();
     $strWhere = "";
     if ($arrRestrictionModules && is_array($arrRestrictionModules)) {
         $arrMarks = array();
         foreach ($arrRestrictionModules as $strOneId) {
             $arrMarks[] = "?";
             $arrParams[] = $strOneId;
         }
         $strWhere = "AND system_module_nr IN ( " . implode(", ", $arrMarks) . " )";
     }
     //Load all elements on the same level, so at first get the prev id
     $strQuery = "SELECT *\n                         FROM " . _dbprefix_ . "system\n                         WHERE system_prev_id=? AND system_id != '0'\n                           AND system_deleted = 0\n                         " . $strWhere . "\n                         ORDER BY system_sort ASC, system_comment ASC";
     //No caching here to allow multiple shiftings per request
     $arrElements = $this->objDB->getPArray($strQuery, $arrParams, null, null, false);
     //more than one record to set?
     if (count($arrElements) <= 1) {
         return;
     }
     //senseless new pos?
     if ($intNewPosition <= 0 || $intNewPosition > count($arrElements)) {
         return;
     }
     $intCurPos = $this->objSource->getIntSort();
     if ($intNewPosition == $intCurPos) {
         return;
     }
     //searching the current element to get to know if element should be sorted up- or downwards
     $bitSortDown = false;
     $bitSortUp = false;
     if ($intNewPosition < $intCurPos) {
         $bitSortUp = true;
     } else {
         $bitSortDown = true;
     }
     //sort up?
     if ($bitSortUp) {
         //move the record to be shifted to the wanted pos
         $strQuery = "UPDATE " . _dbprefix_ . "system\n                                SET system_sort=?\n                                WHERE system_id=?";
         $this->objDB->_pQuery($strQuery, array((int) $intNewPosition, $this->objSource->getSystemid()));
         //start at the pos to be reached and move all one down
         for ($intI = $intNewPosition; $intI < $intCurPos; $intI++) {
             $strQuery = "UPDATE " . _dbprefix_ . "system\n                            SET system_sort=?\n                            WHERE system_id=?";
             $this->objDB->_pQuery($strQuery, array($intI + 1, $arrElements[$intI - 1]["system_id"]));
         }
     }
     if ($bitSortDown) {
         //move the record to be shifted to the wanted pos
         $strQuery = "UPDATE " . _dbprefix_ . "system\n                                SET system_sort=?\n                                WHERE system_id=?";
         $this->objDB->_pQuery($strQuery, array((int) $intNewPosition, $this->objSource->getSystemid()));
         //start at the pos to be reached and move all one up
         for ($intI = $intCurPos + 1; $intI <= $intNewPosition; $intI++) {
             $strQuery = "UPDATE " . _dbprefix_ . "system\n                            SET system_sort= ?\n                            WHERE system_id=?";
             $this->objDB->_pQuery($strQuery, array($intI - 1, $arrElements[$intI - 1]["system_id"]));
         }
     }
     //flush the cache
     $this->objSource->flushCompletePagesCache();
     class_carrier::getInstance()->flushCache(class_carrier::INT_CACHE_TYPE_DBQUERIES | class_carrier::INT_CACHE_TYPE_ORMCACHE);
     $this->objSource->setIntSort($intNewPosition);
 }