Esempio n. 1
0
function CreateRoleTransactionTypeAuthorizations()
{
    $intRoleTransactionTypeAuthorizationArray = RoleTransactionTypeAuthorization::CountAll();
    if (count($intRoleTransactionTypeAuthorizationArray)) {
        foreach (Role::LoadAll() as $objRole) {
            // Archive
            $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization();
            $objRoleTransactionTypeAuthorization->RoleId = $objRole->RoleId;
            $objRoleTransactionTypeAuthorization->TransactionTypeId = 10;
            $objRoleTransactionTypeAuthorization->AuthorizationLevelId = 1;
            $objRoleTransactionTypeAuthorization->Save();
            // Unarchive
            $objRoleTransactionTypeAuthorization = new RoleTransactionTypeAuthorization();
            $objRoleTransactionTypeAuthorization->RoleId = $objRole->RoleId;
            $objRoleTransactionTypeAuthorization->TransactionTypeId = 11;
            $objRoleTransactionTypeAuthorization->AuthorizationLevelId = 1;
            $objRoleTransactionTypeAuthorization->Save();
        }
    }
}
 /**
  * Authorizes any control to determine if the user has access
  * If not, it sets the objControl->Visible to false
  *
  * @param object $objEntity - any entity with a created_by column (asset, location, etc.)
  * @param object $objControl - the control which is being evaluated - any QControl where visible is a property
  * @param integer $intTransactionTypeId - the transaction_type_id
  */
 public static function AuthorizeControlByRoleTransactionType($objEntity, $objControl, $intTransactionTypeId)
 {
     if ($objControl->Visible != false) {
         $objRoleTransactionTypeAuthorization = RoleTransactionTypeAuthorization::LoadByRoleIdTransactionTypeId(QApplication::$objUserAccount->RoleId, $intTransactionTypeId);
         if ($objRoleTransactionTypeAuthorization) {
             // None
             if ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 3) {
                 $objControl->Visible = false;
             } elseif ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 2 && !($objEntity->CreatedBy == QApplication::$objUserAccount->UserAccountId)) {
                 $objControl->Visible = false;
             }
         }
     }
 }
Esempio n. 3
0
    /**
     * 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) . '
			');
    }
 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;
         }
     }
 }
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, RoleTransactionTypeAuthorization::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
 protected function btnArchive_Create()
 {
     $this->btnArchive = new QButton($this);
     $this->btnArchive->AddAction(new QClickEvent(), new QServerControlAction($this, 'btnArchive_Click'));
     $this->btnArchive->AddAction(new QEnterKeyEvent(), new QServerControlAction($this, 'btnArchive_Click'));
     $this->btnArchive->AddAction(new QEnterKeyEvent(), new QTerminateAction());
     $this->btnArchive->CausesValidation = false;
     QApplication::AuthorizeControl($this->objAsset, $this->btnArchive, 2);
     if ($this->btnArchive->Visible) {
         // Check if they have the ability to create a new Archivement
         QApplication::AuthorizeControl(null, $this->btnArchive, 2, 5);
         if ($this->objAsset->ArchivedFlag) {
             $this->btnArchive->Text = 'Unarchive';
             RoleTransactionTypeAuthorization::AuthorizeControlByRoleTransactionType($this->objAsset, $this->btnArchive, 11);
         } else {
             $this->btnArchive->Text = 'Archive';
             RoleTransactionTypeAuthorization::AuthorizeControlByRoleTransactionType($this->objAsset, $this->btnArchive, 10);
         }
     }
 }
Esempio n. 7
0
    /**
     * 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);
    }
Esempio n. 8
0
 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();
         }
     }
 }
 public function btnAdd_Click($strFormId, $strControlId, $strParameter)
 {
     $strAssetCode = $this->txtNewAssetCode->Text;
     $blnDuplicate = false;
     $blnError = false;
     if ($strAssetCode) {
         // Begin error checking
         if ($this->objAssetArray) {
             foreach ($this->objAssetArray as $asset) {
                 if ($asset && $asset->AssetCode == $strAssetCode) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset has already been added.";
                 }
             }
         }
         if (!$blnError) {
             $this->txtNewAssetCode->Warning = '';
             $objNewAsset = Asset::LoadByAssetCodeWithCustomFields($this->txtNewAssetCode->Text);
             if (!$objNewAsset instanceof Asset) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "That asset code does not exist.";
             } elseif ($objNewAsset->LinkedFlag) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "That asset is locked to a parent asset.";
             } elseif ($objNewAsset->LocationId == 6 && $this->intTransactionTypeId != 11) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "That asset has already been archived.";
             } elseif ($objNewAsset->LocationId == 2) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "That asset has already been shipped.";
             } elseif ($objNewAsset->LocationId == 5) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "That asset is currently scheduled to be received.";
             } elseif ($objPendingShipment = AssetTransaction::PendingShipment($objNewAsset->AssetId)) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "That asset is already in a pending shipment.";
             } elseif (!QApplication::AuthorizeEntityBoolean($objNewAsset, 2)) {
                 $blnError = true;
                 $this->txtNewAssetCode->Warning = "You do not have authorization to perform a transaction on this asset.";
             } elseif ($this->intTransactionTypeId == 1) {
                 if ($objNewAsset->CheckedOutFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is checked out.";
                 } elseif ($objNewAsset->ReservedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is reserved.";
                 }
             } elseif ($this->intTransactionTypeId == 2) {
                 if (!$objNewAsset->CheckedOutFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is not checked out.";
                 } elseif ($objNewAsset->ReservedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is reserved.";
                 } elseif ($objNewAsset->CheckedOutFlag) {
                     $objUserAccount = $objNewAsset->GetLastTransactionUser();
                     if (QApplication::$TracmorSettings->StrictCheckinPolicy == '1' && $objUserAccount->UserAccountId != QApplication::$objUserAccount->UserAccountId) {
                         $blnError = true;
                         $this->txtNewAssetCode->Warning = "That asset was not checked out by the current user.";
                     }
                 }
             } elseif ($this->intTransactionTypeId == 3) {
                 if ($objNewAsset->CheckedOutFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is already checked out.";
                 } elseif ($objNewAsset->ReservedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is reserved.";
                 }
             } elseif ($this->intTransactionTypeId == 8) {
                 if ($objNewAsset->ReservedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is already reserved.";
                 } elseif ($objNewAsset->CheckedOutFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is checked out.";
                 }
             } elseif ($this->intTransactionTypeId == 9) {
                 if (!$objNewAsset->ReservedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is not reserved";
                 } elseif ($objNewAsset->CheckedOutFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is checked out.";
                 } elseif ($objNewAsset->ReservedFlag) {
                     $objUserAccount = $objNewAsset->GetLastTransactionUser();
                     if ($objUserAccount->UserAccountId != QApplication::$objUserAccount->UserAccountId) {
                         $blnError = true;
                         $this->txtNewAssetCode->Warning = "That asset was not reserved by the current user.";
                     }
                 }
             } elseif ($this->intTransactionTypeId == 10) {
                 if ($objNewAsset->ArchivedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is already archived.";
                 } elseif ($objNewAsset->CheckedOutFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is checked out.";
                 } elseif ($objNewAsset->ReservedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is reserved.";
                 }
             } elseif ($this->intTransactionTypeId == 11) {
                 if (!$objNewAsset->ArchivedFlag) {
                     $blnError = true;
                     $this->txtNewAssetCode->Warning = "That asset is not archived.";
                 }
             }
             if (!$blnError && ($this->intTransactionTypeId == 1 || $this->intTransactionTypeId == 2 || $this->intTransactionTypeId == 3 || $this->intTransactionTypeId == 8 || $this->intTransactionTypeId == 9 || $this->intTransactionTypeId == 10 || $this->intTransactionTypeId == 11)) {
                 $objRoleTransactionTypeAuthorization = RoleTransactionTypeAuthorization::LoadByRoleIdTransactionTypeId(QApplication::$objUserAccount->RoleId, $this->intTransactionTypeId);
                 if ($objRoleTransactionTypeAuthorization) {
                     // If the user has 'None' privileges for this transaction
                     if ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 3) {
                         $blnError = true;
                         $this->txtNewAssetCode->Warning = "You do not have privileges for this transaction.";
                     } elseif ($objRoleTransactionTypeAuthorization->AuthorizationLevelId == 2 && $objNewAsset->CreatedBy != QApplication::$objUserAccount->UserAccountId) {
                         $blnError = true;
                         $this->txtNewAssetCode->Warning = "You are not the owner of this asset.";
                     }
                 }
             }
             if (!$blnError && $objNewAsset instanceof Asset) {
                 $this->objAssetArray[] = $objNewAsset;
                 $this->txtNewAssetCode->Text = null;
                 // Load all linked assets
                 $objLinkedAssetArray = Asset::LoadChildLinkedArrayByParentAssetIdWithNoCustomFields($objNewAsset->AssetId);
                 if ($objLinkedAssetArray) {
                     $strAssetCodeArray = array();
                     foreach ($objLinkedAssetArray as $objLinkedAsset) {
                         $strAssetCodeArray[] = $objLinkedAsset->AssetCode;
                         $this->objAssetArray[] = $objLinkedAsset;
                     }
                     $this->txtNewAssetCode->Warning = sprintf("The following asset(s) have been added to the transaction because they are locked to asset (%s):<br />%s", $objNewAsset->AssetCode, implode('<br />', $strAssetCodeArray));
                 }
                 unset($objLinkedAssetArray);
                 $this->dtgAssetTransact->Refresh();
             }
         }
         if (!$blnError) {
             $this->txtNewAssetCode->Warning = '';
         }
     } else {
         $this->txtNewAssetCode->Warning = "Please enter an asset code.";
     }
     $this->txtNewAssetCode->Focus();
     $this->txtNewAssetCode->Select();
 }
 /**
  * Main utility method to aid with data binding.  It is used by the default BindAllRows() databinder but
  * could and should be used by any custom databind methods that would be used for instances of this
  * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. 
  *
  * If a paginator is set on this DataBinder, it will use it.  If not, then no pagination will be used.
  * It will also perform any sorting (if applicable).
  *
  * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself
  * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query		 
  * @return void
  */
 public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null)
 {
     // Setup input parameters to default values if none passed in
     if (!$objCondition) {
         $objCondition = QQ::All();
     }
     $objClauses = $objOptionalClauses ? $objOptionalClauses : array();
     // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     if ($this->Paginator) {
         $this->TotalItemCount = RoleTransactionTypeAuthorization::QueryCount($objCondition, $objClauses);
     }
     // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add
     // the OrderByClause to the $objClauses array
     if ($objClause = $this->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be a Query result from RoleTransactionTypeAuthorization, given the clauses above
     $this->DataSource = RoleTransactionTypeAuthorization::QueryArray($objCondition, $objClauses);
 }
 protected function btnRestock_Create()
 {
     $this->btnRestock = new QButton($this);
     $this->btnRestock->Text = 'Restock';
     $this->btnRestock->AddAction(new QClickEvent(), new QAjaxControlAction($this, 'btnRestock_Click'));
     $this->btnRestock->AddAction(new QEnterKeyEvent(), new QAjaxControlAction($this, 'btnRestock_Click'));
     $this->btnRestock->AddAction(new QEnterKeyEvent(), new QTerminateAction());
     $this->btnRestock->CausesValidation = false;
     QApplication::AuthorizeControl($this->objInventoryModel, $this->btnRestock, 2);
     RoleTransactionTypeAuthorization::AuthorizeControlByRoleTransactionType($this->objInventoryModel, $this->btnRestock, 4);
 }
 /**
  * Static Helper Method to Create using PK arguments
  * You must pass in the PK arguments on an object to load, or leave it blank to create a new one.
  * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo
  * static helper methods.  Finally, specify a CreateType to define whether or not we are only allowed to 
  * edit, or if we are also allowed to create a new one, etc.
  * 
  * @param mixed $objParentObject QForm or QPanel which will be using this RoleTransactionTypeAuthorizationMetaControl
  * @param integer $intRoleTransactionTypeAuthorizationId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing RoleTransactionTypeAuthorization object creation - defaults to CreateOrEdit
  * @return RoleTransactionTypeAuthorizationMetaControl
  */
 public static function Create($objParentObject, $intRoleTransactionTypeAuthorizationId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intRoleTransactionTypeAuthorizationId)) {
         $objRoleTransactionTypeAuthorization = RoleTransactionTypeAuthorization::Load($intRoleTransactionTypeAuthorizationId);
         // RoleTransactionTypeAuthorization was found -- return it!
         if ($objRoleTransactionTypeAuthorization) {
             return new RoleTransactionTypeAuthorizationMetaControl($objParentObject, $objRoleTransactionTypeAuthorization);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a RoleTransactionTypeAuthorization object with PK arguments: ' . $intRoleTransactionTypeAuthorizationId);
             }
         }
         // If EditOnly is specified, throw an exception
     } else {
         if ($intCreateType == QMetaControlCreateType::EditOnly) {
             throw new QCallerException('No PK arguments specified');
         }
     }
     // If we are here, then we need to create a new record
     return new RoleTransactionTypeAuthorizationMetaControl($objParentObject, new RoleTransactionTypeAuthorization());
 }