/** * Deletes all associated RoleTransactionTypeAuthorizations * @return void */ public function DeleteAllRoleTransactionTypeAuthorizations() { if (is_null($this->intRoleId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateRoleTransactionTypeAuthorization on this unsaved Role.'); } // Get the Database Object for this Class $objDatabase = Role::GetDatabase(); // Journaling if ($objDatabase->JournalingDatabase) { foreach (RoleTransactionTypeAuthorization::LoadArrayByRoleId($this->intRoleId) as $objRoleTransactionTypeAuthorization) { $objRoleTransactionTypeAuthorization->Journal('DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `role_transaction_type_authorization` WHERE `role_id` = ' . $objDatabase->SqlVariable($this->intRoleId) . ' '); }
/** * Load an array of Shortcut objects, * by QApplication::$objRoleModule->RoleModuleId and by the Role Edit Access to the Built-in Fields of the Module. * @param string $strOrderBy * @param string $strLimit * @param array $objExpansionMap map of referenced columns to be immediately expanded via early-binding * @return Shortcut[] */ public static function LoadArrayByRoleModule($strOrderBy = null, $strLimit = null, $objExpansionMap = null) { // Call to ArrayQueryHelper to Get Database Object and Get SQL Clauses Shortcut::ArrayQueryHelper($strOrderBy, $strLimit, $strLimitPrefix, $strLimitSuffix, $strExpandSelect, $strExpandFrom, $objExpansionMap, $objDatabase); // Properly Escape All Input Parameters using Database->SqlVariable() $intModuleId = $objDatabase->SqlVariable(QApplication::$objRoleModule->ModuleId, true); $intRoleId = $objDatabase->SqlVariable(QApplication::$objRoleModule->RoleId, true); // Load an array of TransactionTypeAuthorizations where transaction level authorization is 'None' to match with shortcuts later. $intTransactionTypeIdArray = array(); $objRoleTransactionTypeAuthorizationArray = RoleTransactionTypeAuthorization::LoadArrayByRoleId(QApplication::$objRoleModule->RoleId); if ($objRoleTransactionTypeAuthorizationArray) { foreach ($objRoleTransactionTypeAuthorizationArray as $objRoleTransactionTypeAuthorization) { if ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 3) { $intTransactionTypeIdArray[] = $objRoleTransactionTypeAuthorization->TransactionTypeId; } } } $objViewRoleModuleAuthorization = RoleModuleAuthorization::LoadByRoleModuleIdAuthorizationId(QApplication::$objRoleModule->RoleModuleId, 1); if (!$objViewRoleModuleAuthorization) { throw new Exception('No valid RoleModuleAuthorization for this User Role.'); } elseif ($objViewRoleModuleAuthorization->AuthorizationLevelId == 1 || $objViewRoleModuleAuthorization->AuthorizationLevelId == 2) { $blnView = true; } else { $blnView = false; } $objEditRoleModuleAuthorization = RoleModuleAuthorization::LoadByRoleModuleIdAuthorizationId(QApplication::$objRoleModule->RoleModuleId, 2); if (!$objEditRoleModuleAuthorization) { throw new Exception('No valid RoleModuleAuthorization for this User Role.'); } elseif ($objEditRoleModuleAuthorization->AuthorizationLevelId == 1 || $objEditRoleModuleAuthorization->AuthorizationLevelId == 2) { $blnEdit = true; } else { $blnEdit = false; } if ($blnView && $blnEdit) { $strAuthorizationSql = 'AND (`shortcut`.`authorization_id` = 1 OR `shortcut`.`authorization_id` = 2)'; } elseif ($blnView) { $strAuthorizationSql = 'AND `shortcut`.`authorization_id` = 1'; } elseif ($blnEdit) { $strAuthorizationSql = 'AND `shortcut`.`authorization_id` = 2'; } else { $strAuthorizationSql = 'AND `shortcut`.`authorization_id` != 1 AND `shortcut`.`authorization_id` != 2'; } // If the transaction level authorization is 'None' for a user role the shortcuts will be hidden in the module pages. if (count($intTransactionTypeIdArray)) { $strAuthorizationSql .= ' AND (`shortcut`.`transaction_type_id` NOT IN (' . implode(", ", $intTransactionTypeIdArray) . ') OR `shortcut`.`transaction_type_id` IS NULL)'; } //Set the entities sql according to the Module switch (QApplication::$objRoleModule->ModuleId) { case 2: $strEntitiesSql = 'AND (`FLA`.`entity_qtype_id`=1 OR `FLA`.`entity_qtype_id`=4)'; break; case 3: $strEntitiesSql = 'AND (`FLA`.`entity_qtype_id`=2)'; break; case 4: $strEntitiesSql = 'AND (`FLA`.`entity_qtype_id`=7 OR `FLA`.`entity_qtype_id`=8 OR `FLA`.`entity_qtype_id`=9)'; break; case 5: $strEntitiesSql = 'AND (`FLA`.`entity_qtype_id`=10)'; break; case 6: $strEntitiesSql = 'AND (`FLA`.`entity_qtype_id`=11)'; break; case 7: $strEntitiesSql = ''; break; } // Setup the SQL Query that checks "edit" authorization to the module $strQuery = sprintf(' SELECT %s `shortcut`.`shortcut_id` AS `shortcut_id`, `shortcut`.`module_id` AS `module_id`, `shortcut`.`authorization_id` AS `authorization_id`, `shortcut`.`short_description` AS `short_description`, `shortcut`.`link` AS `link`, `shortcut`.`image_path` AS `image_path`, `shortcut`.`entity_qtype_id` AS `entity_qtype_id`, `shortcut`.`create_flag` AS `create_flag` %s FROM `shortcut` AS `shortcut`, `role_entity_qtype_built_in_authorization` AS `FLA` %s WHERE (`FLA`.`role_id` %s %s AND `FLA`.`authorization_id`=2) AND `shortcut`.`module_id` %s %s AND (`shortcut`.`entity_qtype_id`=`FLA`.`entity_qtype_id`) AND (`shortcut`.`create_flag`=0 OR `FLA`.`authorized_flag`=1) %s %s', $strLimitPrefix, $strExpandSelect, $strExpandFrom, $intRoleId, $strEntitiesSql, $intModuleId, $strAuthorizationSql, $strOrderBy, $strLimitSuffix); // Perform the Query and Instantiate the Result $objDbResult = $objDatabase->Query($strQuery); return Shortcut::InstantiateDbResult($objDbResult); }
public function btnAdd_Click($strFormId, $strControlId, $strParameter) { // Clear warnings from previous attempt $this->txtNewInventoryModelCode->Warning = ''; $blnError = false; // Assign the values from the user submitted form input $intNewInventoryLocationId = $this->lstSourceLocation->SelectedValue; $intTransactionQuantity = $this->txtQuantity->Text; // Create array of TransactionType (key) and AuthorizationLevel (value) by RoleId $objRoleTransactionTypeAuthorizationArray = RoleTransactionTypeAuthorization::LoadArrayByRoleId(QApplication::$objUserAccount->RoleId); $intAuthorizationLevelIdArray = array(); if ($objRoleTransactionTypeAuthorizationArray) { foreach ($objRoleTransactionTypeAuthorizationArray as $objRoleTransactionTypeAuthorization) { $intAuthorizationLevelIdArray[$objRoleTransactionTypeAuthorization->TransactionTypeId] = $objRoleTransactionTypeAuthorization->AuthorizationLevelId; } } // If transaction is a move or take out if ($this->intTransactionTypeId == 1 || $this->intTransactionTypeId == 5) { if ($intNewInventoryLocationId) { // Begin error checking if ($this->objInventoryLocationArray) { foreach ($this->objInventoryLocationArray as $objInventoryLocation) { if ($objInventoryLocation && $objInventoryLocation->InventoryLocationId == $intNewInventoryLocationId) { $blnError = true; $this->txtNewInventoryModelCode->Warning = "That Inventory has already been added."; } } } if (!$blnError) { $objNewInventoryLocation = InventoryLocation::LoadLocations($intNewInventoryLocationId); // This should not be possible because the list is populated with existing InventoryLocations if (!$objNewInventoryLocation instanceof InventoryLocation) { $this->txtNewInventoryModelCode->Warning = "That Inventory location does not exist."; $blnError = true; } elseif (!ctype_digit($intTransactionQuantity) || $intTransactionQuantity <= 0) { $this->txtQuantity->Warning = "That is not a valid quantity."; $blnError = true; } // Move if ($this->intTransactionTypeId == 1) { if ($objNewInventoryLocation->Quantity < $intTransactionQuantity) { $this->txtQuantity->Warning = "Quantity moved cannot exceed quantity available."; $blnError = true; } } elseif ($this->intTransactionTypeId == 5) { if ($objNewInventoryLocation->Quantity < $intTransactionQuantity) { $this->txtQuantity->Warning = "Quantity taken out cannot exceed quantity available."; $blnError = true; } } } } elseif ($this->intTransactionTypeId != 4) { $this->txtNewInventoryModelCode->Warning = "Please select a source location."; $blnError = true; } } elseif ($this->intTransactionTypeId == 4) { // Check for duplicate inventory code $strNewInventoryModelCode = $this->txtNewInventoryModelCode->Text; if (!($objNewInventoryModel = InventoryModel::LoadByInventoryModelCode($strNewInventoryModelCode))) { $blnError = true; $this->txtNewInventoryModelCode->Warning = "That is an invalid Inventory Code."; } elseif ($this->objInventoryLocationArray) { foreach ($this->objInventoryLocationArray as $objInventoryLocation) { if ($objInventoryLocation && $objInventoryLocation->InventoryModel->InventoryModelCode == $strNewInventoryModelCode) { $blnError = true; $this->txtNewInventoryModelCode->Warning = "That Inventory has already been added."; } } } if (!$blnError) { $objRoleTransactionTypeAuthorization = RoleTransactionTypeAuthorization::LoadByRoleIdTransactionTypeId(QApplication::$objUserAccount->RoleId, 4); if ($objRoleTransactionTypeAuthorization) { // If the user has 'None' privileges for this transaction if ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 3) { $this->txtNewInventoryModelCode->Warning = "You do not have privileges for this transaction."; $blnError = true; } elseif ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 2 && $objNewInventoryModel->CreatedBy != QApplication::$objUserAccount->UserAccountId) { $this->txtNewInventoryModelCode->Warning = "You are not the owner of this inventory."; $blnError = true; } } } if (!$blnError) { // Create a new InventoryLocation for the time being // Before saving we will check to see if it already exists $objNewInventoryLocation = new InventoryLocation(); $objNewInventoryLocation->InventoryModelId = $objNewInventoryModel->InventoryModelId; $objNewInventoryLocation->Quantity = 0; // LocationID = 4 is 'New Inventory' Location $objNewInventoryLocation->LocationId = 4; } } if (!$blnError && isset($objNewInventoryModel) && !QApplication::AuthorizeEntityBoolean($objNewInventoryModel, 2)) { $blnError = true; $this->txtNewInventoryModelCode->Warning = "You do not have authorization to perform a transaction on this inventory model."; } if (!$blnError && $objNewInventoryLocation instanceof InventoryLocation) { $objNewInventoryLocation->intTransactionQuantity = $intTransactionQuantity; $this->objInventoryLocationArray[] = $objNewInventoryLocation; $this->txtNewInventoryModelCode->Text = null; $this->lstSourceLocation->SelectedIndex = 0; $this->txtQuantity->Text = null; if ($this->intTransactionTypeId == 1 || $this->intTransactionTypeId == 5) { $this->lstSourceLocation->Enabled = false; $this->txtQuantity->Enabled = false; } } }
protected function UpdateTransactionLevelAuthorizations() { if (!$this->blnEditMode) { // Create a new RoleTransactionTypeAuthorization // Move $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 1; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['move']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Check In $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 2; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['check_in_out']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Check Out $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 3; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['check_in_out']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Reserve $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 8; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['reserve_unreserve']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Unreserve $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 9; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['reserve_unreserve']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Take Out $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 5; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['take_out']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Restock $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 4; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['restock']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Archive $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 10; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['archive_unarchive']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Unarchive $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 11; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['archive_unarchive']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); } else { $objRoleTransactionTypeAuthorizationArray = RoleTransactionTypeAuthorization::LoadArrayByRoleId($this->objRole->RoleId); if ($objRoleTransactionTypeAuthorizationArray) { foreach ($objRoleTransactionTypeAuthorizationArray as $objRoleTransactionTypeAuthorization) { if ($objRoleTransactionTypeAuthorization->TransactionTypeId == 1) { $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['move']->SelectedValue; } elseif ($objRoleTransactionTypeAuthorization->TransactionTypeId == 2 || $objRoleTransactionTypeAuthorization->TransactionTypeId == 3) { $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['check_in_out']->SelectedValue; } elseif ($objRoleTransactionTypeAuthorization->TransactionTypeId == 8 || $objRoleTransactionTypeAuthorization->TransactionTypeId == 9) { $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['reserve_unreserve']->SelectedValue; } elseif ($objRoleTransactionTypeAuthorization->TransactionTypeId == 5) { $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['take_out']->SelectedValue; } elseif ($objRoleTransactionTypeAuthorization->TransactionTypeId == 4) { $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['restock']->SelectedValue; } elseif ($objRoleTransactionTypeAuthorization->TransactionTypeId == 10 || $objRoleTransactionTypeAuthorization->TransactionTypeId == 11) { $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['archive_unarchive']->SelectedValue; } $objRoleTransactionTypeAuthorization->Save(); } } else { // Create a new RoleTransactionTypeAuthorization // Move $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 1; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['move']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Check In $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 2; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['check_in_out']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Check Out $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 3; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['check_in_out']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Reserve $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 8; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['reserve_unreserve']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Unreserve $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 9; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['reserve_unreserve']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Take Out $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 5; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['take_out']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Restock $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 4; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['restock']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Archive $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 10; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['archive_unarchive']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); // Unarchive $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization(); $objRoleTransactionTypeAuthorization->RoleId = $this->objRole->RoleId; $objRoleTransactionTypeAuthorization->TransactionTypeId = 11; $objRoleTransactionTypeAuthorization->AuthorizationLevelId = $this->arrControls['archive_unarchive']->SelectedValue; $objRoleTransactionTypeAuthorization->Save(); } } }