Exemplo n.º 1
0
 public function __construct($objParentObject, $intEntityQtypeId = null, $strControlId = null)
 {
     // First, call the parent to do most of the basic setup
     try {
         parent::__construct($objParentObject, $strControlId);
     } catch (QCallerException $objExc) {
         $objExc->IncrementOffset();
         throw $objExc;
     }
     $this->objParentObject = $objParentObject;
     $this->intEntityQtypeId = $intEntityQtypeId;
     $this->chkEntityView = new QCheckBox($this);
     $this->chkEntityEdit = new QCheckBox($this);
     $this->chkBuiltInView = new QCheckBox($this);
     $this->chkBuiltInView->Enabled = false;
     $this->chkBuiltInView->Checked = true;
     $intRoleId = QApplication::QueryString('intRoleId');
     if ($intRoleId) {
         $objBuiltInViewAuth = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($intRoleId, $intEntityQtypeId, 1);
     }
     if (isset($objBuiltInViewAuth)) {
         $this->chkBuiltInView->Checked = $objBuiltInViewAuth->AuthorizedFlag;
     }
     $this->chkBuiltInEdit = new QCheckBox($this);
     if ($intRoleId) {
         $objBuiltInEditAuth = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($intRoleId, $intEntityQtypeId, 2);
     }
     if (isset($objBuiltInEditAuth)) {
         $this->chkBuiltInEdit->Checked = $objBuiltInEditAuth->AuthorizedFlag;
     }
     // Load all custom fields and their values into an array arrCustomChecks
     $objCustomFieldArray = CustomField::LoadObjCustomFieldArray($intEntityQtypeId, false, null);
     foreach ($objCustomFieldArray as $objCustomField) {
         $chkCustomView = new QCheckBox($this);
         $chkCustomEdit = new QCheckBox($this);
         $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($intEntityQtypeId, $objCustomField->CustomFieldId);
         if ($objEntityQtypeCustomField) {
             $objCustomAuthView = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($intRoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
             if ($objCustomAuthView) {
                 $chkCustomView->Checked = $objCustomAuthView->AuthorizedFlag;
             }
             $objCustomAuthEdit = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($intRoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
             if ($objCustomAuthEdit) {
                 $chkCustomEdit->Checked = $objCustomAuthEdit->AuthorizedFlag;
             }
         }
         $this->arrCustomChecks[] = array('name' => $objCustomField->ShortDescription . ':', 'view' => $chkCustomView, 'edit' => $chkCustomEdit);
     }
 }
 protected function SetupEntityQtypeCustomField()
 {
     // Lookup Object PK information from Query String (if applicable)
     // Set mode to Edit or New depending on what's found
     $intEntityQtypeCustomFieldId = QApplication::QueryString('intEntityQtypeCustomFieldId');
     if ($intEntityQtypeCustomFieldId) {
         $this->objEntityQtypeCustomField = EntityQtypeCustomField::Load($intEntityQtypeCustomFieldId);
         if (!$this->objEntityQtypeCustomField) {
             throw new Exception('Could not find a EntityQtypeCustomField object with PK arguments: ' . $intEntityQtypeCustomFieldId);
         }
         $this->strTitleVerb = QApplication::Translate('Edit');
         $this->blnEditMode = true;
     } else {
         $this->objEntityQtypeCustomField = new EntityQtypeCustomField();
         $this->strTitleVerb = QApplication::Translate('Create');
         $this->blnEditMode = false;
     }
 }
Exemplo n.º 3
0
 public function Delete()
 {
     $arrEntityQtype = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->CustomFieldId);
     parent::Delete();
     foreach ($arrEntityQtype as $objEntityQtype) {
         $strHelperTableArray = $this->GetHelperTableByEntityQtypeId($objEntityQtype->EntityQtypeId);
         $strHelperTable = $strHelperTableArray[0];
         $strTableName = $strHelperTableArray[1];
         $strQuery = sprintf("UPDATE %s SET `cfv_%s` = NULL WHERE `cfv_%s` = '%s'", $strHelperTable, $this->CustomFieldId, $this->CustomFieldId, $this->ShortDescription);
         $objDatabase = CustomFieldValue::GetDatabase();
         $objDatabase->NonQuery($strQuery);
     }
     /*		  $objCondition = QQ::Equal(QQN::CustomFieldSelection()->CustomFieldValueId, $this->CustomFieldValueId);
     			$objClauses = QQ::Clause(QQ::Expand(QQN::CustomFieldSelection()->CustomFieldValue));
     			// Select all CustomFieldSelections (and expanded CustomFieldValues) by CustomFieldValueId
     			$objCustomFieldSelectionArray = CustomFieldSelection::QueryArray($objCondition, $objClauses);
     			//parent::Delete();
     			$intRowsToDeleteArray = array();
     			// Create an array switched by helper tables (to minimize number of queries)
     			foreach ($objCustomFieldSelectionArray as $objCustomFieldSelection) {
     			  if ($this->GetHelperTableByEntityQtypeId($objCustomFieldSelection->EntityQtypeId)) {
     			    $intRowsToDeleteArray[$objCustomFieldSelection->EntityQtypeId][] = $objCustomFieldSelection->EntityId;
     			  }
     			}
     			$objDatabase = CustomFieldValue::GetDatabase();
     			// For each helper table
     			foreach (array_keys($intRowsToDeleteArray) as $intEntityQtypeId) {
     				$strHelperTableArray = $this->GetHelperTableByEntityQtypeId($intEntityQtypeId);
     				$strHelperTable = $strHelperTableArray[0];
       			$strTableName = $strHelperTableArray[1];
     				
     				$strQuery = sprintf("UPDATE %s SET `cfv_%s`='' WHERE `%s_id` IN (%s);", $strHelperTable, $objCustomFieldSelection->CustomFieldValue->CustomFieldId, $strTableName, implode(', ', $intRowsToDeleteArray[$intEntityQtypeId]));
             $objDatabase->NonQuery($strQuery);
     			}*/
 }
 public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects)
 {
     if ($objObject->objRole) {
         $objObject->objRole = Role::GetSoapObjectFromObject($objObject->objRole, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intRoleId = null;
         }
     }
     if ($objObject->objEntityQtypeCustomField) {
         $objObject->objEntityQtypeCustomField = EntityQtypeCustomField::GetSoapObjectFromObject($objObject->objEntityQtypeCustomField, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intEntityQtypeCustomFieldId = null;
         }
     }
     if ($objObject->objAuthorization) {
         $objObject->objAuthorization = Authorization::GetSoapObjectFromObject($objObject->objAuthorization, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intAuthorizationId = null;
         }
     }
     if ($objObject->objCreatedByObject) {
         $objObject->objCreatedByObject = UserAccount::GetSoapObjectFromObject($objObject->objCreatedByObject, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intCreatedBy = null;
         }
     }
     if ($objObject->dttCreationDate) {
         $objObject->dttCreationDate = $objObject->dttCreationDate->__toString(QDateTime::FormatSoap);
     }
     if ($objObject->objModifiedByObject) {
         $objObject->objModifiedByObject = UserAccount::GetSoapObjectFromObject($objObject->objModifiedByObject, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intModifiedBy = null;
         }
     }
     return $objObject;
 }
Exemplo n.º 5
0
 protected function chkCustom_Create()
 {
     $intRoleId = QApplication::QueryString('intRoleId');
     $objCustomFieldArray = CustomField::LoadObjCustomFieldArray($this->intEntityQtypeId, false, null);
     foreach ($objCustomFieldArray as $objCustomField) {
         //For each Custom Field, we setup one checkbox for View Access and one for Edit Access
         $chkCustomView = new QCheckBox($this);
         $chkCustomView->AddAction(new QClickEvent(), new QAjaxAction('chkCustom_Click'));
         $chkCustomEdit = new QCheckBox($this);
         //When we click in a View Checkbox, we need to control the Edit Checkbox Control too in the chkCustom_Click method.
         $chkCustomView->ActionParameter = $chkCustomEdit->ControlId;
         //In order to manipulate the RoleEntityQtypeCustomFieldAuthorization table, we need to obtain the EntityQtypeCustomFieldId field.
         $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($this->intEntityQtypeId, $objCustomField->CustomFieldId);
         if ($objEntityQtypeCustomField) {
             $objCustomAuthView = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($intRoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
             //If Creation Mode, the View Privilege of the Custom Fields is checked by default
             if (!$this->blnEditMode) {
                 $chkCustomView->Checked = 1;
             } elseif (isset($objCustomAuthView)) {
                 $chkCustomView->Checked = $objCustomAuthView->AuthorizedFlag;
             }
             $objCustomAuthEdit = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($intRoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
             //If Creation Mode, the Edit Privilege of the Custom Fields is checked by default
             if (!$this->blnEditMode) {
                 $chkCustomEdit->Checked = 1;
             } elseif (isset($objCustomAuthEdit)) {
                 $chkCustomEdit->Checked = $objCustomAuthEdit->AuthorizedFlag;
             }
             //if view access is not authorized, edit access won't be authorized
             if (!$chkCustomView->Checked) {
                 $chkCustomEdit->Enabled = false;
                 $chkCustomEdit->Checked = false;
             }
         }
         //In order to manipulate all the custom checkbox of the entity, we save them in an associated array.
         $this->arrCustomChecks[] = array('name' => $objCustomField->ShortDescription . ':', 'view' => $chkCustomView, 'edit' => $chkCustomEdit, 'id' => $objCustomField->CustomFieldId);
     }
 }
 public function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     $this->UpdateAssetModelFields();
     $this->objAssetModel->Save();
     // Adding AssetCustomFieldsAssetModels with allAssetModel flag checked
     $arrAllAssetModelsFlaggedObjects = EntityQtypeCustomField::LoadArrayByEntityQtypeId(QApplication::Translate(EntityQtype::Asset));
     foreach ($arrAllAssetModelsFlaggedObjects as $arrAllAssetModelsFlaggedObject) {
         if ($arrAllAssetModelsFlaggedObject->CustomField->AllAssetModelsFlag) {
             $newAssetCustomField = new AssetCustomFieldAssetModel();
             $newAssetCustomField->CustomFieldId = $arrAllAssetModelsFlaggedObject->CustomField->CustomFieldId;
             $newAssetCustomField->AssetModelId = $this->objAssetModel->AssetModelId;
             $newAssetCustomField->Save();
         }
     }
     $this->CloseSelf(true);
 }
Exemplo n.º 7
0
 protected function UpdateFieldLevelAuthorizations()
 {
     if ($this->objModuleArray) {
         //First, we get all the panels that we need to manipulate
         foreach ($this->objModuleArray as $objModule) {
             switch ($objModule->ModuleId) {
                 case 2:
                     $arrEntity[] = array('objPanel' => $this->pnlAssets, 'intEntity' => EntityQtype::Asset);
                     $arrEntity[] = array('objPanel' => $this->pnlAssetModel, 'intEntity' => EntityQtype::AssetModel);
                     break;
                 case 3:
                     $arrEntity[] = array('objPanel' => $this->pnlInventory, 'intEntity' => EntityQtype::Inventory);
                     break;
                 case 4:
                     $arrEntity[] = array('objPanel' => $this->pnlCompany, 'intEntity' => EntityQtype::Company);
                     $arrEntity[] = array('objPanel' => $this->pnlContact, 'intEntity' => EntityQtype::Contact);
                     $arrEntity[] = array('objPanel' => $this->pnlAddress, 'intEntity' => EntityQtype::Address);
                     break;
                 case 5:
                     $arrEntity[] = array('objPanel' => $this->pnlShipping, 'intEntity' => EntityQtype::Shipment);
                     break;
                 case 6:
                     $arrEntity[] = array('objPanel' => $this->pnlReceiving, 'intEntity' => EntityQtype::Receipt);
                     break;
             }
         }
         //One Panel= One Entity. For each entity, we must save chkBuiltIn for View and Edit and several CustomChecks, for View and Edit
         foreach ($arrEntity as $entity) {
             //We look for the BuiltIn View entry, searching by RoleId, EntityId and authorizationId=1 (View)
             $objRoleEntityQTypeBuiltInAuthView = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($this->objRole->RoleId, $entity['intEntity'], 1);
             // If the entry doesn't exists, we create it.
             if (!$objRoleEntityQTypeBuiltInAuthView) {
                 $objRoleEntityQTypeBuiltInAuthView = new RoleEntityQtypeBuiltInAuthorization();
                 $objRoleEntityQTypeBuiltInAuthView->RoleId = $this->objRole->RoleId;
                 $objRoleEntityQTypeBuiltInAuthView->EntityQtypeId = $entity['intEntity'];
                 $objRoleEntityQTypeBuiltInAuthView->AuthorizationId = 1;
             }
             $objRoleEntityQTypeBuiltInAuthView->AuthorizedFlag = $entity['objPanel']->chkBuiltInView->Checked;
             $objRoleEntityQTypeBuiltInAuthView->Save();
             //We look for the BuiltIn Edit entry, searching by RoleId, EntityId and authorizationId=2 (Edit)
             $objRoleEntityQTypeBuiltInAuthEdit = RoleEntityQtypeBuiltInAuthorization::LoadByRoleIdEntityQtypeIdAuthorizationId($this->objRole->RoleId, $entity['intEntity'], 2);
             // If the entry doesn't exists, we create it.
             if (!$objRoleEntityQTypeBuiltInAuthEdit) {
                 $objRoleEntityQTypeBuiltInAuthEdit = new RoleEntityQtypeBuiltInAuthorization();
                 $objRoleEntityQTypeBuiltInAuthEdit->RoleId = $this->objRole->RoleId;
                 $objRoleEntityQTypeBuiltInAuthEdit->EntityQtypeId = $entity['intEntity'];
                 $objRoleEntityQTypeBuiltInAuthEdit->AuthorizationId = 2;
             }
             $objRoleEntityQTypeBuiltInAuthEdit->AuthorizedFlag = $entity['objPanel']->chkBuiltInEdit->Checked;
             $objRoleEntityQTypeBuiltInAuthEdit->Save();
             //We must now save the View and Edit checkboxs values of the Custom checks.
             if ($entity['objPanel']->arrCustomChecks) {
                 foreach ($entity['objPanel']->arrCustomChecks as $objCustomCheck) {
                     //We look into EntityQtypeCustomFieldId because we need to get EntityQtypeCustomFieldId in order to save into the RoleEntityCustom tables
                     $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($entity['intEntity'], $objCustomCheck['id']);
                     //We look for the Custom View entry, searching by RoleId, EntityQtypeCustomFieldId and authorization_id=1(View)
                     $objRoleEntityQtypeCustomFieldView = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($this->objRole->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
                     // If the entry doesn't exists, we create it.
                     if (!$objRoleEntityQtypeCustomFieldView) {
                         $objRoleEntityQtypeCustomFieldView = new RoleEntityQtypeCustomFieldAuthorization();
                         $objRoleEntityQtypeCustomFieldView->RoleId = $this->objRole->RoleId;
                         $objRoleEntityQtypeCustomFieldView->EntityQtypeCustomFieldId = $objEntityQtypeCustomField->EntityQtypeCustomFieldId;
                         $objRoleEntityQtypeCustomFieldView->AuthorizationId = 1;
                     }
                     $objRoleEntityQtypeCustomFieldView->AuthorizedFlag = $objCustomCheck['view']->Checked;
                     $objRoleEntityQtypeCustomFieldView->Save();
                     //We look for the Custom View entry, searching by RoleId, EntityQtypeCustomFieldId and authorization_id=2(Edit)
                     $objRoleEntityQtypeCustomFieldEdit = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId($this->objRole->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
                     // If the entry doesn't exists, we create it.
                     if (!$objRoleEntityQtypeCustomFieldEdit) {
                         $objRoleEntityQtypeCustomFieldEdit = new RoleEntityQtypeCustomFieldAuthorization();
                         $objRoleEntityQtypeCustomFieldEdit->RoleId = $this->objRole->RoleId;
                         $objRoleEntityQtypeCustomFieldEdit->EntityQtypeCustomFieldId = $objEntityQtypeCustomField->EntityQtypeCustomFieldId;
                         $objRoleEntityQtypeCustomFieldEdit->AuthorizationId = 2;
                     }
                     $objRoleEntityQtypeCustomFieldEdit->AuthorizedFlag = $objCustomCheck['edit']->Checked;
                     $objRoleEntityQtypeCustomFieldEdit->Save();
                 }
             }
         }
     }
 }
Exemplo n.º 8
0
    /**
     * Deletes all associated EntityQtypeCustomFields
     * @return void
     */
    public function DeleteAllEntityQtypeCustomFields()
    {
        if (is_null($this->intCustomFieldId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateEntityQtypeCustomField on this unsaved CustomField.');
        }
        // Get the Database Object for this Class
        $objDatabase = CustomField::GetDatabase();
        // Journaling
        if ($objDatabase->JournalingDatabase) {
            foreach (EntityQtypeCustomField::LoadArrayByCustomFieldId($this->intCustomFieldId) as $objEntityQtypeCustomField) {
                $objEntityQtypeCustomField->Journal('DELETE');
            }
        }
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`entity_qtype_custom_field`
				WHERE
					`custom_field_id` = ' . $objDatabase->SqlVariable($this->intCustomFieldId) . '
			');
    }
Exemplo n.º 9
0
 protected function DeleteEntityQtypeCustomFields()
 {
     $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->objCustomField->CustomFieldId);
     if ($objEntityQtypeCustomFieldArray) {
         foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
             // If the EntityQtype needs to be deleted, you must delete EntityQtypeId for all roles in RoleEntityQTypeCustomFieldAuthorization
             $objRoleEntityCustomAuthArray = RoleEntityQtypeCustomFieldAuthorization::LoadArrayByEntityQtypeCustomFieldId($objEntityQtypeCustomField->EntityQtypeCustomFieldId);
             if ($objRoleEntityCustomAuthArray) {
                 foreach ($objRoleEntityCustomAuthArray as $objRoleEntityCustomAuth) {
                     $objRoleEntityCustomAuth->Delete();
                 }
             }
             // If there was Asset Type Custom field Delete AssetCustomField
             if ($objEntityQtypeCustomField->EntityQtypeId == 1) {
                 $this->DeleteAssetCustomFieldAssetModels();
             }
             // If the helper table exists for that EntityQtype delete the columns in the helper table
             if ($strHelperTableArray = CustomFieldValue::GetHelperTableByEntityQtypeId($objEntityQtypeCustomField->EntityQtypeId)) {
                 $strHelperTable = $strHelperTableArray[0];
                 $objDatabase = CustomField::GetDatabase();
                 $strQuery = sprintf("ALTER TABLE %s DROP `cfv_%s`;", $strHelperTable, $objEntityQtypeCustomField->CustomFieldId);
                 $objDatabase->NonQuery($strQuery);
             }
             // Delete the EntityQtypeCustomField last
             $objEntityQtypeCustomField->Delete();
         }
     }
 }
Exemplo n.º 10
0
 protected function chkAssetCustomFields_Refresh()
 {
     $arrAssetCustomFieldOptions = EntityQtypeCustomField::LoadArrayByEntityQtypeId(QApplication::Translate(EntityQtype::Asset));
     if (count($arrAssetCustomFieldOptions) > 0) {
         if ($this->blnEditMode) {
             $arrChosenCustomFieldId = array();
             $arrChosenCustomField = AssetCustomFieldAssetModel::LoadArrayByAssetModelId($this->objAssetModel->AssetModelId);
             foreach ($arrChosenCustomField as $objChosenCustomField) {
                 $arrChosenCustomFieldId[] = $objChosenCustomField->CustomFieldId;
             }
         }
         foreach ($arrAssetCustomFieldOptions as $arrAssetCustomFieldOption) {
             $selected = false;
             if ($this->blnEditMode) {
                 $selected = in_array($arrAssetCustomFieldOption->CustomField->CustomFieldId, $arrChosenCustomFieldId);
             }
             /*     else{
             	   $selected = $arrAssetCustomFieldOption->CustomField->AllAssetModelsFlag;
             	 }
             */
             //Excluding AllAssetModelsFlaged Items just until setup qcodo 4.22
             $role = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objRoleModule->RoleId, $arrAssetCustomFieldOption->EntityQtypeCustomFieldId, 2);
             if ($role instanceof RoleEntityQtypeCustomFieldAuthorization) {
                 $role = $role->AuthorizedFlag;
             }
             if (!$arrAssetCustomFieldOption->CustomField->AllAssetModelsFlag && $arrAssetCustomFieldOption->CustomField->ActiveFlag && (int) $role == 1) {
                 $this->chkAssetCustomFields->AddItem(new QListItem($arrAssetCustomFieldOption->CustomField->ShortDescription, $arrAssetCustomFieldOption->CustomField->CustomFieldId, $selected));
             }
         }
     }
     if ($this->chkAssetCustomFields->ItemCount == 0) {
         $this->chkAssetCustomFields->Display = false;
     }
     if ($this->blnEditMode) {
         $this->chkAssetCustomFields->Enabled = false;
     }
 }
 public function dtgEntityQtypeCustomField_Bind()
 {
     // Get Total Count b/c of Pagination
     $this->dtgEntityQtypeCustomField->TotalItemCount = EntityQtypeCustomField::CountAll();
     $objClauses = array();
     if ($objClause = $this->dtgEntityQtypeCustomField->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     if ($objClause = $this->dtgEntityQtypeCustomField->LimitClause) {
         array_push($objClauses, $objClause);
     }
     $this->dtgEntityQtypeCustomField->DataSource = EntityQtypeCustomField::LoadAll($objClauses);
 }
 protected function dtgEntityQtypeCustomField_Bind()
 {
     // Because we want to enable pagination AND sorting, we need to setup the $objClauses array to send to LoadAll()
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     $this->dtgEntityQtypeCustomField->TotalItemCount = EntityQtypeCustomField::CountAll();
     // Setup the $objClauses Array
     $objClauses = array();
     // 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->dtgEntityQtypeCustomField->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->dtgEntityQtypeCustomField->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be the array of all EntityQtypeCustomField objects, given the clauses above
     $this->dtgEntityQtypeCustomField->DataSource = EntityQtypeCustomField::LoadAll($objClauses);
 }
 /**
  * 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 EntityQtypeCustomFieldMetaControl
  * @param integer $intEntityQtypeCustomFieldId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing EntityQtypeCustomField object creation - defaults to CreateOrEdit
  * @return EntityQtypeCustomFieldMetaControl
  */
 public static function Create($objParentObject, $intEntityQtypeCustomFieldId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intEntityQtypeCustomFieldId)) {
         $objEntityQtypeCustomField = EntityQtypeCustomField::Load($intEntityQtypeCustomFieldId);
         // EntityQtypeCustomField was found -- return it!
         if ($objEntityQtypeCustomField) {
             return new EntityQtypeCustomFieldMetaControl($objParentObject, $objEntityQtypeCustomField);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a EntityQtypeCustomField object with PK arguments: ' . $intEntityQtypeCustomFieldId);
             }
         }
         // 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 EntityQtypeCustomFieldMetaControl($objParentObject, new EntityQtypeCustomField());
 }
Exemplo n.º 14
0
 /**
  * This loads the array of custom fields, and their selections and values if an existing entity
  * If it is a new entity, it only loads the custom fields without values.
  *
  * @param integer $intEntityQtypeId e.g., 1 == Asset, 2 == Inventory
  * @param bool $blnEditMode if creating a new entity or editing an existing one
  * @param integer $intEntityId e.g., AssetId, InventoryId
  * @return Array $objCustomFieldArray of CustomField objects
  */
 public static function LoadObjCustomFieldArray($intEntityQtypeId, $blnEditMode, $intEntityId = null)
 {
     $objExpansionMap[CustomField::ExpandDefaultCustomFieldValue] = true;
     $objCustomFieldArray = CustomField::LoadArrayByActiveFlagEntity(true, $intEntityQtypeId, null, null, $objExpansionMap);
     if ($objCustomFieldArray && $blnEditMode) {
         foreach ($objCustomFieldArray as $objCustomField) {
             $objCustomField->LoadExpandedArrayByEntity($intEntityQtypeId, $intEntityId);
         }
     }
     if ($objCustomFieldArray) {
         foreach ($objCustomFieldArray as $objCustomField) {
             $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($intEntityQtypeId, $objCustomField->CustomFieldId);
             if ($objEntityQtypeCustomField) {
                 $objRoleEntityQtypeCustomFieldAuthorization = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objUserAccount->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
                 if ($objRoleEntityQtypeCustomFieldAuthorization) {
                     $objCustomField->objRoleAuthView = $objRoleEntityQtypeCustomFieldAuthorization;
                 }
                 $objRoleEntityQtypeCustomFieldAuthorization2 = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objUserAccount->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
                 if ($objRoleEntityQtypeCustomFieldAuthorization2) {
                     $objCustomField->objRoleAuthEdit = $objRoleEntityQtypeCustomFieldAuthorization2;
                 }
             }
         }
     }
     return $objCustomFieldArray;
 }
Exemplo n.º 15
0
 /**
  * Load a single EntityQtypeCustomField object,
  * by EntityQtypeId and CustomFieldId index(es)
  * This assumes that there is only one object per combination of these two parameters, which is the case but not enforced
  * @param integer $intEntityQtypeCustomFieldId
  * @return EntityQtypeCustomField
  */
 public static function LoadByEntityQtypeIdCustomFieldId($intEntityQtypeId, $intCustomFieldId)
 {
     return EntityQtypeCustomField::QuerySingle(QQ::AndCondition(QQ::Equal(QQN::EntityQtypeCustomField()->EntityQtypeId, $intEntityQtypeId), QQ::Equal(QQN::EntityQtypeCustomField()->CustomFieldId, $intCustomFieldId)));
 }
Exemplo n.º 16
0
 protected function substactNotAllowedFields($intAssetModelId, $intCustomFieldId = null)
 {
     $arrAllowed = array();
     foreach (AssetCustomFieldAssetModel::LoadArrayByAssetModelId($intAssetModelId) as $objAssetCustomField) {
         $arrAllowed[] = $objAssetCustomField->CustomFieldId;
     }
     $arrToClear = array();
     foreach (EntityQtypeCustomField::LoadArrayByEntityQtypeId(1) as $objAssetCustomField) {
         if (!in_array($objAssetCustomField->CustomFieldId, $arrAllowed) && $objAssetCustomField->CustomField->AllAssetModelsFlag != 1) {
             $arrToClear[] = $objAssetCustomField->CustomFieldId;
         }
     }
     if ($intCustomFieldId) {
         if ($arrToClear && count($arrToClear) > 0) {
             foreach ($arrToClear as $idToBeNull) {
                 $arrForQuery[] = sprintf("`cfv_%s`= NULL", $idToBeNull);
             }
             return sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", str_replace('""', '"', implode(", ", $arrForQuery)), $intCustomFieldId);
         }
     } else {
         return $arrToClear;
     }
 }
 protected function lstEntityQtypeCustomField_Create()
 {
     $this->lstEntityQtypeCustomField = new QListBox($this);
     $this->lstEntityQtypeCustomField->Name = QApplication::Translate('Entity Qtype Custom Field');
     $this->lstEntityQtypeCustomField->Required = true;
     if (!$this->blnEditMode) {
         $this->lstEntityQtypeCustomField->AddItem(QApplication::Translate('- Select One -'), null);
     }
     $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadAll();
     if ($objEntityQtypeCustomFieldArray) {
         foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
             $objListItem = new QListItem($objEntityQtypeCustomField->__toString(), $objEntityQtypeCustomField->EntityQtypeCustomFieldId);
             if ($this->objRoleEntityQtypeCustomFieldAuthorization->EntityQtypeCustomField && $this->objRoleEntityQtypeCustomFieldAuthorization->EntityQtypeCustomField->EntityQtypeCustomFieldId == $objEntityQtypeCustomField->EntityQtypeCustomFieldId) {
                 $objListItem->Selected = true;
             }
             $this->lstEntityQtypeCustomField->AddItem($objListItem);
         }
     }
 }
Exemplo n.º 18
0
 /**
  * This loads the array of custom fields, and their selections and values if an existing entity
  * If it is a new entity, it only loads the custom fields without values.
  *
  * @param integer $intEntityQtypeId e.g., 1 == Asset, 2 == Inventory
  * @param bool $blnEditMode if creating a new entity or editing an existing one
  * @param integer $intEntityId e.g., AssetId, InventoryId
  * @return Array $objCustomFieldArray of CustomField objects
  */
 public static function LoadObjCustomFieldArray($intEntityQtypeId, $blnEditMode, $intEntityId = null, $searchable = false, $intAssetModel = null)
 {
     $objExpansionMap[CustomField::ExpandDefaultCustomFieldValue] = true;
     $objCustomFieldArray = CustomField::LoadArrayByActiveFlagEntity(true, $intEntityQtypeId, null, null, $objExpansionMap, $searchable);
     if ($objCustomFieldArray && $blnEditMode) {
         foreach ($objCustomFieldArray as $objCustomField) {
             $objCustomField->LoadExpandedArrayByEntity($intEntityQtypeId, $intEntityId);
         }
     }
     // Custom Fiedls load for Asset in asset_edit
     if ($intAssetModel) {
         $arrCustomFieldsForAssetModel = array();
         // Select only
         if (is_int($intAssetModel)) {
             $arrAssetCustomFields = AssetCustomFieldAssetModel::LoadArrayByAssetModelId($intAssetModel);
             foreach ($arrAssetCustomFields as $anAssetCustomField) {
                 $arrCustomFieldsForAssetModel[] = $anAssetCustomField->CustomField->CustomFieldId;
             }
         } elseif ($intAssetModel == 'all') {
             $arrAssetCustomFields = EntityQtypeCustomField::LoadArrayByEntityQtypeId(1);
             foreach ($arrAssetCustomFields as $anAssetCustomField) {
                 if ($anAssetCustomField->CustomField->AllAssetModelsFlag) {
                     $arrCustomFieldsForAssetModel[] = $anAssetCustomField->CustomField->CustomFieldId;
                 }
             }
         }
         $arrForAssetModel = array();
         foreach ($objCustomFieldArray as $objCustomField) {
             if (in_array($objCustomField->CustomFieldId, $arrCustomFieldsForAssetModel) || $objCustomField->AllAssetModelsFlag == 1) {
                 $arrForAssetModel[] = $objCustomField;
             }
         }
         $objCustomFieldArray = $arrForAssetModel;
     }
     if ($objCustomFieldArray) {
         foreach ($objCustomFieldArray as $objCustomField) {
             $objEntityQtypeCustomField = EntityQtypeCustomField::LoadByEntityQtypeIdCustomFieldId($intEntityQtypeId, $objCustomField->CustomFieldId);
             if ($objEntityQtypeCustomField) {
                 $objRoleEntityQtypeCustomFieldAuthorization = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objUserAccount->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 1);
                 if ($objRoleEntityQtypeCustomFieldAuthorization) {
                     $objCustomField->objRoleAuthView = $objRoleEntityQtypeCustomFieldAuthorization;
                 }
                 $objRoleEntityQtypeCustomFieldAuthorization2 = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objUserAccount->RoleId, $objEntityQtypeCustomField->EntityQtypeCustomFieldId, 2);
                 if ($objRoleEntityQtypeCustomFieldAuthorization2) {
                     $objCustomField->objRoleAuthEdit = $objRoleEntityQtypeCustomFieldAuthorization2;
                 }
             }
         }
     }
     return $objCustomFieldArray;
 }
         $strTableName = "shipment";
         $strObjectId = "ShipmentId";
         $strId = 'shipment`.`shipment_id';
         $strHelperTable = '`shipment_custom_field_helper`';
         break;
     case 11:
         $strTableName = "receipt";
         $strObjectId = "ReceiptId";
         $strId = 'receipt`.`receipt_id';
         $strHelperTable = '`receipt_custom_field_helper`';
         break;
     default:
         throw new Exception('Not a valid EntityQtypeId.');
 }
 $blnNoAlterTable = false;
 $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadArrayByEntityQtypeId($intEntityQtypeId, QQ::Clause(QQ::Expand(QQN::EntityQtypeCustomField()->CustomField)));
 if ($objEntityQtypeCustomFieldArray) {
     foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
         echo 'ALTER TABLE ' . $strHelperTable . ' ADD cfv_' . $objEntityQtypeCustomField->CustomFieldId . " TEXT DEFAULT NULL;<br />";
     }
 } else {
     $blnNoAlterTable = true;
 }
 $arrCustomFieldSql = array();
 $arrCustomFieldSql['strSelect'] = '';
 $arrCustomFieldSql['strFrom'] = '';
 $arrCustomFieldSql['strInsertColumnHeader'] = '';
 $arrCustomFieldSql['strInsertValues'] = '';
 if ($objEntityQtypeCustomFieldArray) {
     foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
         $strAlias = $objEntityQtypeCustomField->CustomFieldId;
 /**
  * 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 = EntityQtypeCustomField::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 EntityQtypeCustomField, given the clauses above
     $this->DataSource = EntityQtypeCustomField::QueryArray($objCondition, $objClauses);
 }
Exemplo n.º 21
0
 /**
  * Counts all associated EntityQtypeCustomFields
  * @return int
  */
 public function CountEntityQtypeCustomFields()
 {
     if (is_null($this->intCustomFieldId)) {
         return 0;
     }
     return EntityQtypeCustomField::CountByCustomFieldId($this->intCustomFieldId);
 }
 protected function chkCustomFieldsForAll_Create()
 {
     $this->chkCustomFieldsForAllModels = new QCheckBoxList($this);
     $this->chkCustomFieldsForAllModels->Name = 'Asset Custom Fields for all Models:';
     $arrAssetCustomFieldOptions = EntityQtypeCustomField::LoadArrayByEntityQtypeId(QApplication::Translate(EntityQtype::Asset));
     if (count($arrAssetCustomFieldOptions) > 0) {
         if ($this->blnEditMode) {
             $arrChosenCustomFieldId = array();
             $arrChosenCustomField = AssetCustomFieldAssetModel::LoadArrayByAssetModelId($this->objAssetModel->AssetModelId);
             foreach ($arrChosenCustomField as $objChosenCustomField) {
                 $arrChosenCustomFieldId[] = $objChosenCustomField->CustomFieldId;
             }
         }
         foreach ($arrAssetCustomFieldOptions as $arrAssetCustomFieldOption) {
             $selected = false;
             if ($this->blnEditMode) {
                 $selected = in_array($arrAssetCustomFieldOption->CustomField->CustomFieldId, $arrChosenCustomFieldId);
             }
             $role = RoleEntityQtypeCustomFieldAuthorization::LoadByRoleIdEntityQtypeCustomFieldIdAuthorizationId(QApplication::$objRoleModule->RoleId, $arrAssetCustomFieldOption->EntityQtypeCustomFieldId, 2);
             if ($role instanceof RoleEntityQtypeCustomFieldAuthorization) {
                 $role = $role->AuthorizedFlag;
             }
             if ($arrAssetCustomFieldOption->CustomField->AllAssetModelsFlag && $arrAssetCustomFieldOption->CustomField->ActiveFlag && (int) $role == 1) {
                 $this->chkCustomFieldsForAllModels->AddItem(new QListItem($arrAssetCustomFieldOption->CustomField->ShortDescription, $arrAssetCustomFieldOption->CustomField->CustomFieldId, true));
             }
         }
     }
     $this->chkCustomFieldsForAllModels->Enabled = false;
 }
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, EntityQtypeCustomField::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
Exemplo n.º 24
0
 protected function btnNext_Click()
 {
     $blnError = false;
     if ($this->intStep == 1) {
         if ($this->chkHeaderRow->Checked) {
             $this->blnHeaderRow = true;
         } else {
             $this->blnHeaderRow = false;
         }
         // Check errors
         if ($this->lstFieldSeparator->SelectedValue == 'other' && !$this->txtFieldSeparator->Text) {
             $this->flcFileCsv->Warning = "Please enter the field separator.";
             $blnError = true;
         } elseif ($this->lstTextDelimiter->SelectedValue == 'other' && !$this->txtTextDelimiter->Text) {
             $this->flcFileCsv->Warning = "Please enter the text delimiter.";
             $blnError = true;
         } else {
             // Step 1 complete
             // File Not Uploaded
             if (!file_exists($this->flcFileCsv->File) || !$this->flcFileCsv->Size) {
                 //throw new QCallerException('FileAssetType must be a valid QFileAssetType constant value');
                 $this->flcFileCsv->Warning = 'The file could not be uploaded. Please provide a valid file.';
                 $blnError = true;
                 // File Has Incorrect MIME Type (only if an acceptiblemimearray is setup)
             } elseif (is_array($this->strAcceptibleMimeArray) && !array_key_exists($this->flcFileCsv->Type, $this->strAcceptibleMimeArray)) {
                 $this->flcFileCsv->Warning = "Extension must be 'csv' or 'txt'";
                 $blnError = true;
                 // File Successfully Uploaded
             } else {
                 $this->flcFileCsv->Warning = "";
                 // Setup Filename, Base Filename and Extension
                 $strFilename = $this->flcFileCsv->FileName;
                 $intPosition = strrpos($strFilename, '.');
             }
             if (!$blnError) {
                 $this->FileCsvData = new File_CSV_DataSource();
                 // Setup the settings which have got on step 1
                 $this->FileCsvData->settings($this->GetCsvSettings());
                 $file = fopen($this->flcFileCsv->File, "r");
                 // Counter of files
                 $i = 1;
                 // Counter of rows
                 $j = 1;
                 $this->strFilePathArray = array();
                 // The uploaded file splits up in order to avoid out of memory
                 while ($row = fgets($file, 1000)) {
                     if ($j == 1) {
                         $strFilePath = sprintf('%s/%s_mod_%s.csv', __TRACMOR_TMP__, $_SESSION['intUserAccountId'], $i);
                         $this->strFilePathArray[] = $strFilePath;
                         $file_part = fopen($strFilePath, "w+");
                         if ($i == 1) {
                             $strHeaderRow = $row;
                         } else {
                             fwrite($file_part, $strHeaderRow);
                         }
                     }
                     fwrite($file_part, $row);
                     $j++;
                     if ($j > 200) {
                         $j = 1;
                         $i++;
                         fclose($file_part);
                     }
                 }
                 $this->intTotalCount = ($i - 1) * 200 + $j - 1;
                 if (false) {
                     $blnError = true;
                     $this->btnNext->Warning = $i . " " . $j . "Sorry that is too many assets. Your asset limit is = " . QApplication::$TracmorSettings->AssetLimit . ", this import has " . $this->intTotalCount . " assets, and you already have " . Asset::CountAll() . " assets in the database.";
                 } else {
                     $this->arrMapFields = array();
                     $this->arrTracmorField = array();
                     // Load first file
                     $this->FileCsvData->load($this->strFilePathArray[0]);
                     $file_skipped = fopen($this->strFilePath = sprintf('%s/%s_skipped.csv', __TRACMOR_TMP__, $_SESSION['intUserAccountId']), "w+");
                     // Get Headers
                     if ($this->blnHeaderRow) {
                         $this->arrCsvHeader = $this->FileCsvData->getHeaders();
                         // Create the header row in the skipped error file
                         $this->PutSkippedRecordInFile($file_skipped, $this->arrCsvHeader);
                     }
                     /*else {
                         // If it is not first file
                         $this->FileCsvData->appendRow($this->FileCsvData->getHeaders());
                       }*/
                     $strFirstRowArray = $this->FileCsvData->getRow(0);
                     for ($i = 0; $i < count($strFirstRowArray); $i++) {
                         $this->arrMapFields[$i] = array();
                         if ($this->blnHeaderRow && array_key_exists($i, $this->arrCsvHeader)) {
                             if ($this->arrCsvHeader[$i] == '') {
                                 $this->arrCsvHeader[$i] = ' ';
                             }
                             $this->lstMapHeader_Create($this, $i, $this->arrCsvHeader[$i]);
                             $this->arrMapFields[$i]['header'] = $this->arrCsvHeader[$i];
                         } else {
                             $this->lstMapHeader_Create($this, $i);
                         }
                         // Create Default Value TextBox, ListBox and DateTimePicker
                         if ($this->blnHeaderRow && array_key_exists($i, $this->arrCsvHeader) && $this->arrCsvHeader[$i] || !$this->blnHeaderRow) {
                             $txtDefaultValue = new QTextBox($this);
                             $txtDefaultValue->Width = 200;
                             $this->txtMapDefaultValueArray[] = $txtDefaultValue;
                             $lstDefaultValue = new QListBox($this);
                             $lstDefaultValue->Width = 200;
                             $lstDefaultValue->Display = false;
                             $this->lstMapDefaultValueArray[] = $lstDefaultValue;
                             $dtpDate = new QDateTimePicker($this);
                             $dtpDate->DateTimePickerType = QDateTimePickerType::Date;
                             $dtpDate->DateTimePickerFormat = QDateTimePickerFormat::MonthDayYear;
                             $dtpDate->Display = false;
                             $this->dtpDateArray[] = $dtpDate;
                             if (array_key_exists($i, $this->lstMapHeaderArray)) {
                                 $this->lstTramorField_Change(null, $this->lstMapHeaderArray[$i]->ControlId, null);
                             }
                         }
                         $this->arrMapFields[$i]['row1'] = $strFirstRowArray[$i];
                     }
                     $this->btnNext->Text = "Import Now";
                     fclose($file_skipped);
                     // Create Add Field button
                     $btnAddField = new QButton($this);
                     $btnAddField->Text = "Add Field";
                     $btnAddField->AddAction(new QClickEvent(), new QServerAction('btnAddField_Click'));
                     $btnAddField->AddAction(new QEnterKeyEvent(), new QServerAction('btnAddField_Click'));
                     $btnAddField->AddAction(new QEnterKeyEvent(), new QTerminateAction());
                     $this->lstMapHeaderArray[] = $btnAddField;
                 }
             }
         }
     } elseif ($this->intStep == 2) {
         // Step 2 complete
         $blnError = false;
         $blnAssetModelCode = false;
         $blnAssetModelShortDescription = false;
         $blnCategory = false;
         $blnManufacturer = false;
         $blnModelId = false;
         // Checking errors (Model Short Description, Model Code, Category and Manufacturer must be selected)
         for ($i = 0; $i < count($this->lstMapHeaderArray) - 1; $i++) {
             $lstMapHeader = $this->lstMapHeaderArray[$i];
             $strSelectedValue = strtolower($lstMapHeader->SelectedValue);
             if ($strSelectedValue == "short description") {
                 $blnAssetModelShortDescription = true;
             } elseif ($strSelectedValue == "model number") {
                 $blnAssetModelCode = true;
             } elseif ($strSelectedValue == "category") {
                 $blnCategory = true;
             } elseif ($strSelectedValue == "manufacturer") {
                 $blnManufacturer = true;
             } elseif ($strSelectedValue == "id") {
                 $blnModelId = true;
             }
         }
         if ($this->lstMapDefaultValueArray) {
             // Checking errors for required Default Value text fields
             foreach ($this->lstMapDefaultValueArray as $lstDefault) {
                 if ($lstDefault->Display && $lstDefault->Required && !$lstDefault->SelectedValue) {
                     $lstDefault->Warning = "You must select one default value.";
                     $blnError = true;
                     break;
                 } else {
                     $blnError = false;
                     $lstDefault->Warning = "";
                 }
             }
         }
         if ($this->txtMapDefaultValueArray) {
             // Checking errors for required Default Value lst fields
             foreach ($this->txtMapDefaultValueArray as $txtDefault) {
                 if ($txtDefault->Display && $txtDefault->Required && !$txtDefault->Text) {
                     $txtDefault->Warning = "You must enter default value.";
                     $blnError = true;
                     break;
                 } else {
                     $blnError = false;
                     $txtDefault->Warning = "";
                 }
             }
         }
         // If all required fields have no errors
         if (!$blnError && $blnAssetModelCode && $blnAssetModelShortDescription && $blnCategory && $blnManufacturer && ($this->lstImportAction->SelectedValue != 2 || $blnModelId)) {
             $this->btnNext->Warning = "";
             // Setup keys for main required fields
             foreach ($this->arrTracmorField as $key => $value) {
                 if ($value == 'category') {
                     $this->intCategoryKey = $key;
                 } elseif ($value == 'manufacturer') {
                     $this->intManufacturerKey = $key;
                 } elseif (QApplication::$TracmorSettings->DepreciationFlag == '1' && $value == 'depreciation class') {
                     $this->intDepreciationKey = $key;
                 } elseif ($this->lstImportAction->SelectedValue == 2 && $value == 'id') {
                     $this->intItemIdKey = $key;
                 }
                 /*elseif ($value == 'created by') {
                     $this->intCreatedByKey = $key;
                   }
                   elseif ($value == 'created date') {
                     $this->intCreatedDateKey = $key;
                   }
                   elseif ($value == 'modified by') {
                     $this->intModifiedByKey = $key;
                   }
                   elseif ($value == 'modified date') {
                     $this->intModifiedDateKey = $key;
                   }*/
             }
             $this->objNewAssetModelArray = array();
             $this->strModelValuesArray = array();
             $this->blnImportEnd = false;
             $j = 1;
             $this->btnNext->RemoveAllActions('onclick');
             // Add new ajax actions for button
             $this->btnNext->AddAction(new QClickEvent(), new QAjaxAction('btnNext_Click'));
             $this->btnNext->AddAction(new QClickEvent(), new QToggleEnableAction($this->btnNext));
             $this->btnNext->AddAction(new QEnterKeyEvent(), new QAjaxAction('btnNext_Click'));
             $this->btnNext->AddAction(new QEnterKeyEvent(), new QToggleEnableAction($this->btnNext));
             $this->btnNext->AddAction(new QEnterKeyEvent(), new QTerminateAction());
             $this->btnNext->Warning = "Please wait...";
             $this->intImportStep = 2;
             $this->intCurrentFile = 0;
             $this->strSelectedValueArray = array();
             // New asset models
             $this->dtgAssetModel = new QDataGrid($this);
             $this->dtgAssetModel->Name = 'asset_model_list';
             $this->dtgAssetModel->CellPadding = 5;
             $this->dtgAssetModel->CellSpacing = 0;
             $this->dtgAssetModel->CssClass = "datagrid";
             $this->dtgAssetModel->UseAjax = true;
             $this->dtgAssetModel->ShowColumnToggle = false;
             $this->dtgAssetModel->ShowExportCsv = false;
             $this->dtgAssetModel->ShowHeader = false;
             $this->dtgAssetModel->AddColumn(new QDataGridColumnExt('Model', '<?= $_ITEM ?>', 'CssClass="dtg_column"', 'HtmlEntities="false"'));
             // Updated assets
             $this->dtgUpdatedAsset = new QDataGrid($this);
             $this->dtgUpdatedAsset->Name = 'updated_asset_list';
             $this->dtgUpdatedAsset->CellPadding = 5;
             $this->dtgUpdatedAsset->CellSpacing = 0;
             $this->dtgUpdatedAsset->CssClass = "datagrid";
             $this->dtgUpdatedAsset->UseAjax = true;
             $this->dtgUpdatedAsset->ShowColumnToggle = false;
             $this->dtgUpdatedAsset->ShowExportCsv = false;
             $this->dtgUpdatedAsset->ShowHeader = false;
             $this->dtgUpdatedAsset->AddColumn(new QDataGridColumnExt('Asset Tag', '<?= $_ITEM ?>', 'CssClass="dtg_column"', 'HtmlEntities="false"'));
             // Create the label for successful import
             $this->lblImportSuccess = new QLabel($this);
             $this->lblImportSuccess->HtmlEntities = false;
             $this->lblImportSuccess->Display = false;
             // Undo Last Import button
             $this->btnUndoLastImport = new QButton($this);
             $this->btnUndoLastImport->Text = "Undo Last Import";
             $this->btnUndoLastImport->Display = false;
             $this->btnUndoLastImport->AddAction(new QClickEvent(), new QServerAction('btnCancel_Click'));
             $this->btnUndoLastImport->AddAction(new QEnterKeyEvent(), new QServerAction('btnCancel_Click'));
             $this->btnUndoLastImport->AddAction(new QEnterKeyEvent(), new QTerminateAction());
             // Import More button
             $this->btnImportMore = new QButton($this);
             $this->btnImportMore->Text = "Import More";
             $this->btnImportMore->Display = false;
             $this->btnImportMore->AddAction(new QClickEvent(), new QServerAction('btnImportMore_Click'));
             $this->btnImportMore->AddAction(new QEnterKeyEvent(), new QServerAction('btnImportMore_Click'));
             $this->btnImportMore->AddAction(new QEnterKeyEvent(), new QTerminateAction());
             // Return to Assets button
             $this->btnReturnToAssets = new QButton($this);
             $this->btnReturnToAssets->Text = "Return to Models";
             $this->btnReturnToAssets->Display = false;
             $this->btnReturnToAssets->AddAction(new QClickEvent(), new QServerAction('btnReturnToAssets_Click'));
             $this->btnReturnToAssets->AddAction(new QEnterKeyEvent(), new QServerAction('btnReturnToAssets_Click'));
             $this->btnReturnToAssets->AddAction(new QEnterKeyEvent(), new QTerminateAction());
         } else {
             $this->btnNext->Warning = "You must select all required fields (Model Number, Model Short Description, Category and Manufacturer).";
             $blnError = true;
         }
     } else {
         // Step 3 complete
         set_time_limit(0);
         $file_skipped = fopen($strFilePath = sprintf('%s/%s_skipped.csv', __TRACMOR_TMP__, $_SESSION['intUserAccountId']), "a");
         if (!$this->blnImportEnd) {
             // Asset Model
             if ($this->intImportStep == 2) {
                 $intCategoryArray = array();
                 // Load all categories with key=category_id
                 foreach (Category::LoadAllWithFlags(true, false) as $objCategory) {
                     $intCategoryArray[$objCategory->CategoryId] = strtolower($objCategory->ShortDescription);
                 }
                 $intManufacturerArray = array();
                 // Load all manufacturers with key=manufacturer_id
                 foreach (Manufacturer::LoadAll() as $objManufacturer) {
                     $intManufacturerArray[$objManufacturer->ManufacturerId] = strtolower($objManufacturer->ShortDescription);
                 }
                 if (QApplication::$TracmorSettings->DepreciationFlag == '1') {
                     $intDepreciationClassArray = array();
                     foreach (DepreciationClass::LoadAll() as $objDepreciationClass) {
                         $intDepreciationClassArray[$objDepreciationClass->DepreciationClassId] = strtolower($objDepreciationClass->ShortDescription);
                     }
                 }
                 $intModelCustomFieldKeyArray = array();
                 $arrModelCustomField = array();
                 // Setup keys
                 foreach ($this->arrTracmorField as $key => $value) {
                     if ($value == 'short description') {
                         $intModelShortDescriptionKey = $key;
                     } elseif ($value == 'long description') {
                         $intModelLongDescriptionKey = $key;
                     } elseif ($value == 'model number') {
                         $intModelCodeKey = $key;
                     } elseif (substr($value, 0, 6) == 'model_') {
                         $intModelCustomFieldKeyArray[substr($value, 6)] = $key;
                         if (array_key_exists(substr($value, 6), $this->arrModelCustomField)) {
                             $arrModelCustomField[substr($value, 6)] = $this->arrModelCustomField[substr($value, 6)];
                         }
                     }
                 }
                 $strAssetModelArray = array();
                 $strItemCFVArray = array();
                 $strUpdatedItemCFVArray = array();
                 $strUpdatedValuesArray = array();
                 $this->arrOldItemArray = array();
                 $this->objUpdatedItemArray = array();
                 // Load all asset models
                 foreach (AssetModel::LoadAllIntoExtendedArray() as $arrAssetModel) {
                     $strAssetModelArray[] = strtolower(sprintf("%s_%s_%s_%s", addslashes($arrAssetModel['model_code']), addslashes($arrAssetModel['short_description']), $arrAssetModel['category_id'], $arrAssetModel['manufacturer_id']));
                 }
                 $this->btnNext->Warning = sprintf("Please wait... Model import complete: %s%s", ceil(($this->intCurrentFile + 1) * 200 / $this->intTotalCount * 100), "%");
             }
             // Asset
             /*elseif ($this->intImportStep == 5) {
                         $intCategoryArray = array();
                         // Load all categories with keys=category_id
                         foreach (Category::LoadAllWithFlags(true, false) as $objCategory) {
                           //$intCategoryArray["'" . strtolower($objCategory->ShortDescription) . "'"] = $objCategory->CategoryId;
                           $intCategoryArray[$objCategory->CategoryId] = strtolower($objCategory->ShortDescription);
                         }
                         $intManufacturerArray = array();
                         // Load all manufacturers with keys=manufacturer_id
                         foreach (Manufacturer::LoadAll() as $objManufacturer) {
                           //$intManufacturerArray["'" . strtolower($objManufacturer->ShortDescription) . "'"] = $objManufacturer->ManufacturerId;
                           $intManufacturerArray[$objManufacturer->ManufacturerId] = strtolower($objManufacturer->ShortDescription);
                         }
                         if ($this->intCurrentFile == 0) {
                           $this->intAssetModelArray = array();
                           // Load all asset models with keys=asset_model_id
                           foreach (AssetModel::LoadAll() as $objAssetModel) {
                             //$intAssetModelArray["'" . strtolower($objAssetModel->ShortDescription) . "'"] = $objAssetModel->AssetModelId;
                             $this->intAssetModelArray[$objAssetModel->AssetModelId] = strtolower(sprintf("%s_%s_%s_%s", $objAssetModel->AssetModelCode, $objAssetModel->ShortDescription, $objAssetModel->CategoryId, $objAssetModel->ManufacturerId));
                           }
                         }
                         $intAssetCustomFieldKeyArray = array();
                         $arrAssetCustomField = array();
                         // Setup keys
                         foreach ($this->arrTracmorField as $key => $value) {
                           if ($value == 'asset model short description') {
                             $intModelShortDescriptionKey = $key;
                           }
                           elseif ($value == 'asset model code') {
                             $intModelCodeKey = $key;
                           }
                           elseif ($value == 'asset code') {
                             $intAssetCode = $key;
                           }
                           elseif (substr($value, 0, 6) == 'asset_') {
                             $intAssetCustomFieldKeyArray[substr($value, 6)] = $key;
                             if (array_key_exists(substr($value, 6), $this->arrAssetCustomField)) {
                             	$arrAssetCustomField[substr($value, 6)] = $this->arrAssetCustomField[substr($value, 6)];
                             }
                           }
                         }
                         $intLocationArray = array();
                         // Load all locations with keys=location_id
                         foreach (Location::LoadAll() as $objLocation) {
                           //$intLocationArray["'" . strtolower($objLocation->ShortDescription) . "'"] = $objLocation->LocationId;
                           $intLocationArray[$objLocation->LocationId] = strtolower($objLocation->ShortDescription);
                         }
             
                         $strAssetArray = array();
                         $strUpdatedAssetArray = array();
                         // Load all assets
                         foreach (Asset::LoadAll() as $objAsset) {
                           $strAssetArray[] = strtolower($objAsset->AssetCode);
                         }
                         $this->btnNext->Warning = sprintf("Please wait... Asset import complete: %s%s", ceil(($this->intCurrentFile+1)*200/$this->intTotalCount*100), "%");
                       }*/
             // Loads array of AssetModelId
             $arrAssetModelArray = AssetModel::LoadAllIntoArray();
             $arrAssetModelId = array();
             if (count($arrAssetModelArray)) {
                 foreach ($arrAssetModelArray as $arrAssetModel) {
                     $arrAssetModelId[$arrAssetModel['asset_model_id']] = true;
                 }
             }
             for ($j = $this->intCurrentFile; $j < count($this->strFilePathArray); $j++) {
                 $this->FileCsvData->load($this->strFilePathArray[$j]);
                 if (!$j) {
                     //$this->FileCsvData->appendRow($this->FileCsvData->getHeaders());
                 }
                 if ($this->intImportStep == 2) {
                     $objNewAssetModelArray = array();
                     for ($i = 0; $i < $this->FileCsvData->countRows(); $i++) {
                         $strRowArray = $this->FileCsvData->getRow($i);
                         if (isset($strRowArray[$intModelShortDescriptionKey])) {
                             $strShortDescription = trim($strRowArray[$intModelShortDescriptionKey]) ? addslashes(trim($strRowArray[$intModelShortDescriptionKey])) : false;
                         } elseif (isset($this->txtMapDefaultValueArray[$intModelShortDescriptionKey])) {
                             $strShortDescription = $this->txtMapDefaultValueArray[$intModelShortDescriptionKey]->Text;
                         } else {
                             $strShortDescription = false;
                         }
                         //$strShortDescription = (trim($strRowArray[$intModelShortDescriptionKey])) ? trim($strRowArray[$intModelShortDescriptionKey]) : false;
                         $strAssetModelCode = trim($strRowArray[$intModelCodeKey]) ? addslashes(trim($strRowArray[$intModelCodeKey])) : addslashes(trim($this->txtMapDefaultValueArray[$intModelCodeKey]->Text));
                         //$strAssetModelCode = trim($strRowArray[$intModelCodeKey]) ? trim($strRowArray[$intModelCodeKey]) : trim($this->txtMapDefaultValueArray[$intModelCodeKey]->Text);
                         $strKeyArray = array_keys($intCategoryArray, isset($strRowArray[$this->intCategoryKey]) ? strtolower(trim($strRowArray[$this->intCategoryKey])) : array());
                         if (count($strKeyArray)) {
                             $intCategoryId = $strKeyArray[0];
                         } else {
                             $strKeyArray = array_keys($intCategoryArray, strtolower(trim($this->txtMapDefaultValueArray[$this->intCategoryKey]->Text)));
                             if (count($strKeyArray)) {
                                 $intCategoryId = $strKeyArray[0];
                             } else {
                                 $intCategoryId = false;
                             }
                         }
                         $strKeyArray = array_keys($intManufacturerArray, isset($strRowArray[$this->intManufacturerKey]) ? strtolower(trim($strRowArray[$this->intManufacturerKey])) : array());
                         if (count($strKeyArray)) {
                             $intManufacturerId = $strKeyArray[0];
                         } else {
                             $strKeyArray = array_keys($intManufacturerArray, strtolower(trim($this->txtMapDefaultValueArray[$this->intManufacturerKey]->Text)));
                             if (count($strKeyArray)) {
                                 $intManufacturerId = $strKeyArray[0];
                             } else {
                                 $intManufacturerId = false;
                             }
                         }
                         // depreciation
                         if (QApplication::$TracmorSettings->DepreciationFlag == '1' && $this->intDepreciationKey != null) {
                             $strKeyArray = array_keys($intDepreciationClassArray, strtolower(trim($strRowArray[$this->intDepreciationKey])));
                             if (count($strKeyArray)) {
                                 $intDepreciationId = $strKeyArray[0];
                             } else {
                                 $strKeyArray = array_keys($intDepreciationClassArray, strtolower(trim($this->txtMapDefaultValueArray[$this->intDepreciationKey]->Text)));
                                 if (count($strKeyArray)) {
                                     $intDepreciationId = $strKeyArray[0];
                                 } else {
                                     if (trim($strRowArray[$this->intDepreciationKey]) == '') {
                                         // Depreciation class is blank, so null it out
                                         $intDepreciationId = 'NULL';
                                     } else {
                                         // Depreciation class is invalid, so skip this record
                                         $intDepreciationId = false;
                                     }
                                 }
                             }
                         } else {
                             $intDepreciationId = null;
                         }
                         //
                         $objAssetModel = false;
                         if (!$strShortDescription || $intCategoryId === false || $intManufacturerId === false || $intDepreciationId === false) {
                             //$blnError = true;
                             //echo sprintf("Desc: %s AssetCode: %s Cat: %s Man: %s<br/>", $strShortDescription, $strAssetModelCode, $intCategoryId, $intManufacturerId);
                             //break;
                             $strAssetModel = null;
                             $this->intSkippedRecordCount++;
                             $this->PutSkippedRecordInFile($file_skipped, $strRowArray);
                             continue;
                         } else {
                             //$blnError = false;
                             $strAssetModel = strtolower(sprintf("%s_%s_%s_%s", $strAssetModelCode, $strShortDescription, $intCategoryId, $intManufacturerId));
                             if ($this->lstImportAction->SelectedValue == 2) {
                                 $intItemId = intval(trim($strRowArray[$this->intItemIdKey]));
                                 if ($intItemId > 0 && array_key_exists($intItemId, $arrAssetModelId)) {
                                     $objAssetModelArray = AssetModel::LoadArrayBySearchHelper(null, null, null, null, null, null, null, null, null, null, null, null, $intItemId);
                                     if ($objAssetModelArray) {
                                         $objAssetModel = $objAssetModelArray[0];
                                     }
                                 }
                             } else {
                                 $intItemId = 0;
                             }
                         }
                         if ($strAssetModel && !$intItemId && !$this->in_array_nocase($strAssetModel, $strAssetModelArray)) {
                             // Custom Fields Section
                             $strCFVArray = array();
                             $objDatabase = CustomField::GetDatabase();
                             $blnCheckCFVError = false;
                             // Asset Model Custom Field import
                             foreach ($arrModelCustomField as $objCustomField) {
                                 if ($objCustomField->CustomFieldQtypeId != 2) {
                                     $strCSDescription = trim($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]);
                                     $strCSDescription = strlen($strCSDescription) > 0 ? addslashes($strCSDescription) : addslashes($this->txtMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text);
                                     $strCFVArray[$objCustomField->CustomFieldId] = strlen($strCSDescription) > 0 ? sprintf("'%s'", $strCSDescription) : "NULL";
                                 } else {
                                     $objDatabase = AssetModel::GetDatabase();
                                     $strCSDescription = addslashes(trim($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]));
                                     $blnInList = false;
                                     foreach (CustomFieldValue::LoadArrayByCustomFieldId($objCustomField->CustomFieldId) as $objCustomFieldValue) {
                                         if (strtolower($objCustomFieldValue->ShortDescription) == strtolower($strCSDescription)) {
                                             //$intCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId;
                                             $blnInList = true;
                                             break;
                                         }
                                     }
                                     // Add the CustomFieldValue
                                     // Removed adding new 'select' values
                                     /*if (!$blnInList && !in_array($strCSDescription, $strAddedCFVArray)) {
                                     			$strQuery = sprintf("INSERT INTO custom_field_value (custom_field_id, short_description, created_by, creation_date) VALUES (%s, '%s', %s, NOW());", $objCustomField->CustomFieldId, $strCSDescription, $_SESSION['intUserAccountId']);
                                     			$objDatabase->NonQuery($strQuery);
                                     			$strAddedCFVArray[] = $strCSDescription;
                                     		}
                                     		else*/
                                     if (!$blnInList && $this->lstMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) {
                                         $strCSDescription = $this->lstMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedName;
                                     } elseif (!$blnInList) {
                                         $blnCheckCFVError = true;
                                         break;
                                     }
                                     if (!$blnCheckCFVError) {
                                         if ($strCSDescription) {
                                             $strCFVArray[$objCustomField->CustomFieldId] = sprintf("'%s'", $strCSDescription);
                                         } else {
                                             $strCFVArray[$objCustomField->CustomFieldId] = "NULL";
                                         }
                                     }
                                 }
                             }
                             if (!$blnCheckCFVError) {
                                 $strAssetModelArray[] = $strAssetModel;
                                 // $this->strModelValuesArray[] = sprintf("('%s', '%s', '%s', '%s', '%s', '%s',  NOW())", $strShortDescription, (isset($intModelLongDescriptionKey)) ? addslashes(trim($strRowArray[$intModelLongDescriptionKey])) : null, $strAssetModelCode, $intCategoryId, $intManufacturerId, $_SESSION['intUserAccountId']);
                                 $this->strModelValuesArray[] = sprintf("('%s', '%s', '%s', '%s', '%s', '%s', NOW(), %s)", $strShortDescription, isset($intModelLongDescriptionKey) ? addslashes(trim($strRowArray[$intModelLongDescriptionKey])) : null, $strAssetModelCode, $intCategoryId, $intManufacturerId, $_SESSION['intUserAccountId'], $intDepreciationId ? $intDepreciationId : 'NULL');
                                 $objNewAssetModelArray[] = $strShortDescription;
                                 if (isset($strCFVArray) && count($strCFVArray)) {
                                     $strModelCFVArray[] = implode(', ', $strCFVArray);
                                 } else {
                                     $strModelCFVArray[] = "";
                                 }
                             } else {
                                 $this->intSkippedRecordCount++;
                                 $this->PutSkippedRecordInFile($file_skipped, $strRowArray);
                                 $strAssetModel = null;
                             }
                         } elseif ($strAssetModel && $this->lstImportAction->SelectedValue == 2 && $objAssetModel) {
                             $strUpdateFieldArray = array();
                             $strUpdateFieldArray[] = sprintf("`manufacturer_id`='%s'", $intManufacturerId);
                             $strUpdateFieldArray[] = sprintf("`category_id`='%s'", $intCategoryId);
                             $strUpdateFieldArray[] = sprintf("`short_description`='%s'", $strShortDescription);
                             $strUpdateFieldArray[] = sprintf("`asset_model_code`='%s'", $strAssetModelCode);
                             if (QApplication::$TracmorSettings->DepreciationFlag == '1' && $this->intDepreciationKey != null && $intDepreciationId != null) {
                                 $strUpdateFieldArray[] = sprintf("`depreciation_class_id` = %s", $intDepreciationId);
                             }
                             $strModelLongDescription = "";
                             if (isset($intModelLongDescription)) {
                                 if (trim($strRowArray[$intModelLongDescriptionKey])) {
                                     $strModelLongDescription = trim($strRowArray[$intModelLongDescriptionKey]);
                                 } else {
                                     $strModelLongDescription = isset($txtMapDefaultValueArray[$intModelLongDescriptionKey]) ? trim($txtMapDefaultValueArray[$intModelLongDescriptionKey]->Text) : '';
                                 }
                                 $strUpdateFieldArray[] = sprintf("`asset_model_long_description`='%s'", $strModelLongDescription);
                             }
                             $strUpdateFieldArray[] = sprintf("modified_by='%s'", $_SESSION['intUserAccountId']);
                             $blnCheckCFVError = false;
                             foreach ($arrModelCustomField as $objCustomField) {
                                 if ($objCustomField->CustomFieldQtypeId != 2) {
                                     $strCSDescription = isset($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? trim($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]) : "";
                                     $strCSDescription = strlen($strCSDescription) > 0 ? addslashes($strCSDescription) : addslashes($this->txtMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text);
                                     $strCFVArray[$objCustomField->CustomFieldId] = strlen($strCSDescription) > 0 ? sprintf("'%s'", $strCSDescription) : "NULL";
                                 } else {
                                     $objDatabase = CustomField::GetDatabase();
                                     $strCSDescription = isset($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? addslashes(trim($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]])) : "";
                                     $strCFVArray[$objCustomField->CustomFieldId] = $strCSDescription ? sprintf("'%s'", $strCSDescription) : "NULL";
                                     $blnInList = false;
                                     foreach (CustomFieldValue::LoadArrayByCustomFieldId($objCustomField->CustomFieldId) as $objCustomFieldValue) {
                                         if (strtolower($objCustomFieldValue->ShortDescription) == strtolower($strCSDescription)) {
                                             //$intItemKeyntCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId;
                                             $blnInList = true;
                                             break;
                                         }
                                     }
                                     if (!$blnInList && $this->lstMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) {
                                         $strCSDescription = $this->lstMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedName;
                                     } elseif (!$blnInList) {
                                         $blnCheckCFVError = true;
                                         break;
                                     }
                                     if (!$blnCheckCFVError) {
                                         if ($strCSDescription) {
                                             $strCFVArray[$objCustomField->CustomFieldId] = sprintf("'%s'", $strCSDescription);
                                         } else {
                                             $strCFVArray[$objCustomField->CustomFieldId] = "NULL";
                                         }
                                     }
                                 }
                             }
                             if (!$blnCheckCFVError) {
                                 $strUpdatedValuesArray[] = sprintf("UPDATE `asset_model` SET %s WHERE `asset_model_id`='%s'", implode(", ", $strUpdateFieldArray), $objAssetModel->AssetModelId);
                                 if (isset($strCFVArray) && count($strCFVArray)) {
                                     $strUpdatedItemCFVArray[$objAssetModel->AssetModelId] = $strCFVArray;
                                 } else {
                                     $strUpdatedItemCFVArray[$objAssetModel->AssetModelId] = "";
                                 }
                                 $this->objUpdatedItemArray[$objAssetModel->AssetModelId] = sprintf("%s", $objAssetModel->ShortDescription);
                                 //$this->arrOldItemArray[$objAssetModel->AssetModelId] = $objAssetModel;
                                 // $strItemQuery = sprintf("UPDATE `asset_model` SET `short_description`='%s', `long_description`='%s', `manufacturer_id`='%s', `category_id`='%s', `asset_model_code`='%s', `modified_by`=%s, `modified_date`=%s WHERE `asset_model_id`='%s'", $objAssetModel->ShortDescription, $objAssetModel->LongDescription, $objAssetModel->ManufacturerId, $objAssetModel->CategoryId, $objAssetModel->AssetModelCode, (!$objAssetModel->ModifiedBy) ? "NULL" : $objAssetModel->ModifiedBy, (!$objAssetModel->ModifiedBy) ? "NULL" : sprintf("'%s'", $objAssetModel->ModifiedDate), $objAssetModel->AssetModelId);
                                 $strItemQuery = sprintf("UPDATE `asset_model` SET `short_description`='%s', `long_description`='%s', `manufacturer_id`='%s', `category_id`='%s', `asset_model_code`='%s', `modified_by`=%s, `modified_date`=%s, `depreciation_class_id`=%s WHERE `asset_model_id`='%s'", $objAssetModel->ShortDescription, $objAssetModel->LongDescription, $objAssetModel->ManufacturerId, $objAssetModel->CategoryId, $objAssetModel->AssetModelCode, !$objAssetModel->ModifiedBy ? "NULL" : $objAssetModel->ModifiedBy, !$objAssetModel->ModifiedBy ? "NULL" : sprintf("'%s'", $objAssetModel->ModifiedDate), $objAssetModel->DepreciationClassId ? sprintf("'%s'", $objAssetModel->DepreciationClassId) : "NULL", $objAssetModel->AssetModelId);
                                 $strCFVArray = array();
                                 foreach ($this->arrModelCustomField as $objCustomField) {
                                     $strCFV = $objAssetModel->GetVirtualAttribute($objCustomField->CustomFieldId);
                                     $strCFVArray[] = sprintf("`cfv_%s`='%s'", $objCustomField->CustomFieldId, $strCFV);
                                 }
                                 if (isset($strCFVArray) && count($strCFVArray)) {
                                     $strCFVQuery = sprintf("UPDATE `asset_model_custom_field_helper` SET %s WHERE `asset_model_id`='%s'", implode(", ", $strCFVArray), $intItemId);
                                 } else {
                                     $strCFVQuery = false;
                                 }
                                 $this->arrOldItemArray[$objAssetModel->AssetModelId] = array("ItemSql" => $strItemQuery, "CFVSql" => $strCFVQuery);
                             }
                         } else {
                             $this->intSkippedRecordCount++;
                             $this->PutSkippedRecordInFile($file_skipped, $strRowArray);
                         }
                     }
                     //if ($this->intCurrentFile == count($this->strFilePathArray)) {
                     // Inserts
                     if (count($this->strModelValuesArray)) {
                         $objDatabase = AssetModel::GetDatabase();
                         //	print sprintf("INSERT INTO `asset_model` (`short_description`, `long_description`, `asset_model_code`, `category_id`, `manufacturer_id`, `created_by`, `creation_date`, `depreciation_class_id`) VALUES %s;", str_replace('""','"', implode(", ", $this->strModelValuesArray)));
                         //   exit();
                         //  $objDatabase->NonQuery(sprintf("INSERT INTO `asset_model` (`short_description`, `long_description`, `asset_model_code`, `category_id`, `manufacturer_id`, `created_by`, `creation_date`) VALUES %s;", str_replace('""','"', implode(", ", $this->strModelValuesArray))));
                         $objDatabase->NonQuery(sprintf("INSERT INTO `asset_model` (`short_description`, `long_description`, `asset_model_code`, `category_id`, `manufacturer_id`, `created_by`, `creation_date`, `depreciation_class_id`) VALUES %s;", str_replace('""', '"', implode(", ", $this->strModelValuesArray))));
                         $intInsertId = $objDatabase->InsertId();
                         if ($intInsertId) {
                             // Update for asset custom fields with allAssetModesF Flag
                             $arrAllAssetModelsFlaggedObjects = EntityQtypeCustomField::LoadArrayByEntityQtypeId(QApplication::Translate(EntityQtype::Asset));
                             foreach ($arrAllAssetModelsFlaggedObjects as $arrAllAssetModelsFlaggedObject) {
                                 if ($arrAllAssetModelsFlaggedObject->CustomField->AllAssetModelsFlag) {
                                     $newAssetCustomField = new AssetCustomFieldAssetModel();
                                     $newAssetCustomField->CustomFieldId = $arrAllAssetModelsFlaggedObject->CustomField->CustomFieldId;
                                     $newAssetCustomField->AssetModelId = $intInsertId;
                                     $newAssetCustomField->Save();
                                 }
                             }
                             $strModelIdArray = array();
                             $strCFVArray = array();
                             for ($i = 0; $i < count($objNewAssetModelArray); $i++) {
                                 $this->objNewAssetModelArray[$intInsertId + $i] = $objNewAssetModelArray[$i];
                                 $strCFVArray[$i] = sprintf("('%s', %s)", $intInsertId + $i, $strModelCFVArray[$i]);
                                 $strModelIdArray[$i] = sprintf("(%s)", $intInsertId + $i);
                             }
                             $strCFVNameArray = array();
                             foreach ($arrModelCustomField as $objCustomField) {
                                 $strCFVNameArray[] = sprintf("`cfv_%s`", $objCustomField->CustomFieldId);
                             }
                             if (count($strModelCFVArray) > 0 && count($strCFVNameArray) > 0) {
                                 $strQuery = sprintf("INSERT INTO `asset_model_custom_field_helper` (`asset_model_id`, %s) VALUES %s", implode(", ", $strCFVNameArray), implode(", ", $strCFVArray));
                             } else {
                                 $strQuery = sprintf("INSERT INTO `asset_model_custom_field_helper` (`asset_model_id`) VALUES %s", implode(", ", $strModelIdArray));
                             }
                             $objDatabase->NonQuery($strQuery);
                         }
                         $this->strModelValuesArray = array();
                     }
                     // Updates
                     if (count($strUpdatedValuesArray)) {
                         $objDatabase = AssetModel::GetDatabase();
                         foreach ($strUpdatedValuesArray as $query) {
                             $objDatabase->NonQuery($query);
                         }
                         foreach ($this->objUpdatedItemArray as $intItemKey => $objUpdatedItem) {
                             if (isset($strUpdatedItemCFVArray[$intItemKey]) && count($strUpdatedItemCFVArray[$intItemKey])) {
                                 $strCFVArray = array();
                                 foreach ($arrModelCustomField as $objCustomField) {
                                     $strCFVArray[] = sprintf("`cfv_%s`=%s", $objCustomField->CustomFieldId, $strUpdatedItemCFVArray[$intItemKey][$objCustomField->CustomFieldId]);
                                 }
                                 if (isset($strCFVArray) && count($strCFVArray)) {
                                     $strQuery = sprintf("UPDATE `asset_model_custom_field_helper` SET %s WHERE `asset_model_id`='%s'", implode(", ", $strCFVArray), $intItemKey);
                                     $objDatabase->NonQuery($strQuery);
                                 }
                             }
                         }
                     }
                     //}
                     //$this->intCurrentFile++;
                     //break;
                 }
                 //$j++;
             }
             if ($this->intImportStep == 3) {
                 /*if (count($this->strSelectedValueArray)) {
                     $objDatabase = CustomField::GetDatabase();
                     $strQuery = sprintf("INSERT INTO `custom_field_selection` " .
                                         "(`entity_id`,`entity_qtype_id`, `custom_field_value_id`) " .
                                         "VALUES %s;", implode(", ", $this->strSelectedValueArray));
                     $objDatabase->NonQuery($strQuery);
                   }*/
                 // Insert Values into helper tables
                 $objDatabase = Asset::GetDatabase();
                 $objDatabase->NonQuery("SET FOREIGN_KEY_CHECKS=0;");
                 // Insert into asset_model_custom_field_helper
                 $objDatabase->NonQuery(sprintf("INSERT INTO `asset_model_custom_field_helper` (`asset_model_id`) (SELECT `asset_model_id` FROM `asset_model` WHERE `asset_model_id` NOT IN (SELECT `asset_model_id` FROM `asset_model_custom_field_helper`));"));
                 // Inserts end
                 $objDatabase->NonQuery("SET FOREIGN_KEY_CHECKS=1;");
                 $this->blnImportEnd = true;
                 $this->btnNext->Warning = "";
                 $this->lblImportResults->Display = true;
                 if (count($this->objNewAssetArray)) {
                     $this->lblImportAssets->Display = true;
                     $this->dtgAsset->Paginator = new QPaginator($this->dtgAsset);
                     $this->dtgAsset->ItemsPerPage = 20;
                 }
                 if (count($this->objUpdatedAssetArray)) {
                     $this->lblImportUpdatedAssets->Display = true;
                     $this->dtgUpdatedAsset->Paginator = new QPaginator($this->dtgUpdatedAsset);
                     $this->dtgUpdatedAsset->ItemsPerPage = 20;
                 }
                 if (count($this->objNewAssetModelArray)) {
                     $this->lblImportModels->Display = true;
                     $this->dtgAssetModel->Paginator = new QPaginator($this->dtgAssetModel);
                     $this->dtgAssetModel->ItemsPerPage = 20;
                 }
                 $this->btnNext->Display = false;
                 $this->btnCancel->Display = false;
                 $this->btnUndoLastImport->Display = true;
                 $this->btnImportMore->Display = true;
                 $this->btnReturnToAssets->Display = true;
                 $this->lblImportSuccess->Display = true;
                 $this->lblImportSuccess->Text = sprintf("Success:<br/>" . "<b>%s</b> Records imported successfully<br/>" . "<b>%s</b> Records skipped due to error<br/>", count($this->objNewAssetModelArray) + count($this->objUpdatedItemArray), $this->intSkippedRecordCount);
                 if ($this->intSkippedRecordCount) {
                     $this->lblImportSuccess->Text .= sprintf("<a href='./asset_model_import.php?intDownloadCsv=1'>Click here to download records that could not be imported</a>");
                 }
                 $this->lblImportSuccess->Text .= "<br/><br/>";
                 $this->intImportStep = -1;
             }
             // Enable Next button
             $this->btnNext->Enabled = true;
             if (!$this->blnImportEnd && !$this->intCurrentFile) {
                 $this->intImportStep++;
             }
         }
         fclose($file_skipped);
     }
     if (!$blnError) {
         if (($this->blnImportEnd || $this->intImportStep == 2) && $this->intImportStep != -1) {
             $this->intStep++;
             $this->DisplayStepForm($this->intStep);
         }
         if (!$this->blnImportEnd) {
             QApplication::ExecuteJavaScript("document.getElementById('" . $this->btnNext->ControlId . "').click();");
         }
         if (!($this->intCurrentFile < count($this->strFilePathArray))) {
             $this->intCurrentFile = 0;
             $this->intImportStep++;
         }
     }
 }
 /**
  * Internally called method to assist with early binding of objects
  * on load methods.  Can only early-bind references that this class owns in the database.
  * @param string $strParentAlias the alias of the parent (if any)
  * @param string $strAlias the alias of this object
  * @param array $objExpansionMap map of referenced columns to be immediately expanded via early-binding
  * @param QueryExpansion an already instantiated QueryExpansion object (used as a utility object to assist with object expansion)
  */
 public static function ExpandQuery($strParentAlias, $strAlias, $objExpansionMap, QQueryExpansion $objQueryExpansion)
 {
     if ($strAlias) {
         $objQueryExpansion->AddFromItem(sprintf('LEFT JOIN `role_entity_qtype_custom_field_authorization` AS `%s__%s` ON `%s`.`%s` = `%s__%s`.`role_entity_qtype_custom_field_authorization_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`role_entity_qtype_custom_field_authorization_id` AS `%s__%s__role_entity_qtype_custom_field_authorization_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`role_id` AS `%s__%s__role_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`entity_qtype_custom_field_id` AS `%s__%s__entity_qtype_custom_field_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`authorization_id` AS `%s__%s__authorization_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`authorized_flag` AS `%s__%s__authorized_flag`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`created_by` AS `%s__%s__created_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`creation_date` AS `%s__%s__creation_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_by` AS `%s__%s__modified_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_date` AS `%s__%s__modified_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $strParentAlias = $strParentAlias . '__' . $strAlias;
     }
     if (is_array($objExpansionMap)) {
         foreach ($objExpansionMap as $strKey => $objValue) {
             switch ($strKey) {
                 case 'role_id':
                     try {
                         Role::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'entity_qtype_custom_field_id':
                     try {
                         EntityQtypeCustomField::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'authorization_id':
                     try {
                         Authorization::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'created_by':
                     try {
                         UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'modified_by':
                     try {
                         UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 default:
                     throw new QCallerException(sprintf('Unknown Object to Expand in %s: %s', $strParentAlias, $strKey));
             }
         }
     }
 }
 /**
  * Refresh this MetaControl with Data from the local RoleEntityQtypeCustomFieldAuthorization object.
  * @param boolean $blnReload reload RoleEntityQtypeCustomFieldAuthorization from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objRoleEntityQtypeCustomFieldAuthorization->Reload();
     }
     if ($this->lblRoleEntityQtypeCustomFieldAuthorizationId) {
         if ($this->blnEditMode) {
             $this->lblRoleEntityQtypeCustomFieldAuthorizationId->Text = $this->objRoleEntityQtypeCustomFieldAuthorization->RoleEntityQtypeCustomFieldAuthorizationId;
         }
     }
     if ($this->lstRole) {
         $this->lstRole->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstRole->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objRoleArray = Role::LoadAll();
         if ($objRoleArray) {
             foreach ($objRoleArray as $objRole) {
                 $objListItem = new QListItem($objRole->__toString(), $objRole->RoleId);
                 if ($this->objRoleEntityQtypeCustomFieldAuthorization->Role && $this->objRoleEntityQtypeCustomFieldAuthorization->Role->RoleId == $objRole->RoleId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstRole->AddItem($objListItem);
             }
         }
     }
     if ($this->lblRoleId) {
         $this->lblRoleId->Text = $this->objRoleEntityQtypeCustomFieldAuthorization->Role ? $this->objRoleEntityQtypeCustomFieldAuthorization->Role->__toString() : null;
     }
     if ($this->lstEntityQtypeCustomField) {
         $this->lstEntityQtypeCustomField->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstEntityQtypeCustomField->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadAll();
         if ($objEntityQtypeCustomFieldArray) {
             foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
                 $objListItem = new QListItem($objEntityQtypeCustomField->__toString(), $objEntityQtypeCustomField->EntityQtypeCustomFieldId);
                 if ($this->objRoleEntityQtypeCustomFieldAuthorization->EntityQtypeCustomField && $this->objRoleEntityQtypeCustomFieldAuthorization->EntityQtypeCustomField->EntityQtypeCustomFieldId == $objEntityQtypeCustomField->EntityQtypeCustomFieldId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstEntityQtypeCustomField->AddItem($objListItem);
             }
         }
     }
     if ($this->lblEntityQtypeCustomFieldId) {
         $this->lblEntityQtypeCustomFieldId->Text = $this->objRoleEntityQtypeCustomFieldAuthorization->EntityQtypeCustomField ? $this->objRoleEntityQtypeCustomFieldAuthorization->EntityQtypeCustomField->__toString() : null;
     }
     if ($this->lstAuthorization) {
         $this->lstAuthorization->RemoveAllItems();
         if (!$this->blnEditMode) {
             $this->lstAuthorization->AddItem(QApplication::Translate('- Select One -'), null);
         }
         $objAuthorizationArray = Authorization::LoadAll();
         if ($objAuthorizationArray) {
             foreach ($objAuthorizationArray as $objAuthorization) {
                 $objListItem = new QListItem($objAuthorization->__toString(), $objAuthorization->AuthorizationId);
                 if ($this->objRoleEntityQtypeCustomFieldAuthorization->Authorization && $this->objRoleEntityQtypeCustomFieldAuthorization->Authorization->AuthorizationId == $objAuthorization->AuthorizationId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstAuthorization->AddItem($objListItem);
             }
         }
     }
     if ($this->lblAuthorizationId) {
         $this->lblAuthorizationId->Text = $this->objRoleEntityQtypeCustomFieldAuthorization->Authorization ? $this->objRoleEntityQtypeCustomFieldAuthorization->Authorization->__toString() : null;
     }
     if ($this->chkAuthorizedFlag) {
         $this->chkAuthorizedFlag->Checked = $this->objRoleEntityQtypeCustomFieldAuthorization->AuthorizedFlag;
     }
     if ($this->lblAuthorizedFlag) {
         $this->lblAuthorizedFlag->Text = $this->objRoleEntityQtypeCustomFieldAuthorization->AuthorizedFlag ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
     if ($this->lstCreatedByObject) {
         $this->lstCreatedByObject->RemoveAllItems();
         $this->lstCreatedByObject->AddItem(QApplication::Translate('- Select One -'), null);
         $objCreatedByObjectArray = UserAccount::LoadAll();
         if ($objCreatedByObjectArray) {
             foreach ($objCreatedByObjectArray as $objCreatedByObject) {
                 $objListItem = new QListItem($objCreatedByObject->__toString(), $objCreatedByObject->UserAccountId);
                 if ($this->objRoleEntityQtypeCustomFieldAuthorization->CreatedByObject && $this->objRoleEntityQtypeCustomFieldAuthorization->CreatedByObject->UserAccountId == $objCreatedByObject->UserAccountId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstCreatedByObject->AddItem($objListItem);
             }
         }
     }
     if ($this->lblCreatedBy) {
         $this->lblCreatedBy->Text = $this->objRoleEntityQtypeCustomFieldAuthorization->CreatedByObject ? $this->objRoleEntityQtypeCustomFieldAuthorization->CreatedByObject->__toString() : null;
     }
     if ($this->calCreationDate) {
         $this->calCreationDate->DateTime = $this->objRoleEntityQtypeCustomFieldAuthorization->CreationDate;
     }
     if ($this->lblCreationDate) {
         $this->lblCreationDate->Text = sprintf($this->objRoleEntityQtypeCustomFieldAuthorization->CreationDate) ? $this->objRoleEntityQtypeCustomFieldAuthorization->__toString($this->strCreationDateDateTimeFormat) : null;
     }
     if ($this->lstModifiedByObject) {
         $this->lstModifiedByObject->RemoveAllItems();
         $this->lstModifiedByObject->AddItem(QApplication::Translate('- Select One -'), null);
         $objModifiedByObjectArray = UserAccount::LoadAll();
         if ($objModifiedByObjectArray) {
             foreach ($objModifiedByObjectArray as $objModifiedByObject) {
                 $objListItem = new QListItem($objModifiedByObject->__toString(), $objModifiedByObject->UserAccountId);
                 if ($this->objRoleEntityQtypeCustomFieldAuthorization->ModifiedByObject && $this->objRoleEntityQtypeCustomFieldAuthorization->ModifiedByObject->UserAccountId == $objModifiedByObject->UserAccountId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstModifiedByObject->AddItem($objListItem);
             }
         }
     }
     if ($this->lblModifiedBy) {
         $this->lblModifiedBy->Text = $this->objRoleEntityQtypeCustomFieldAuthorization->ModifiedByObject ? $this->objRoleEntityQtypeCustomFieldAuthorization->ModifiedByObject->__toString() : null;
     }
     if ($this->lblModifiedDate) {
         if ($this->blnEditMode) {
             $this->lblModifiedDate->Text = $this->objRoleEntityQtypeCustomFieldAuthorization->ModifiedDate;
         }
     }
 }
 public function btnSave_Click($strFormId, $strControlId, $strParameter)
 {
     try {
         // Get an instance of the database
         $objDatabase = QApplication::$Database[1];
         // Begin a MySQL Transaction to be either committed or rolled back
         $objDatabase->TransactionBegin();
         // Generate a new AssetCode based on the MinAssetCode value
         // This happens whether or not they are creating a new one or editing an existing one
         if ($this->chkAutoGenerateAssetCode->Checked) {
             $this->txtAssetCode->Text = Asset::GenerateAssetCode();
         }
         $this->objAsset->AssetCode = $this->txtAssetCode->Text;
         $this->objAsset->AssetModelId = $this->lstAssetModel->SelectedValue;
         $blnError = false;
         // If a new asset is being created
         if (!$this->blnEditMode) {
             // Do not allow creation of an asset if asset limit will be exceeded
             $intAssetLimit = is_numeric(QApplication::$TracmorSettings->AssetLimit) ? QApplication::$TracmorSettings->AssetLimit : false;
             if (!$this->blnEditMode) {
                 if ($intAssetLimit && Asset::CountActive() >= $intAssetLimit) {
                     $blnError = true;
                     $this->txtAssetCode->Warning = "Your asset limit has been reached.";
                 }
             }
             //				 Check Depreciation fields
             if (QApplication::$TracmorSettings->DepreciationFlag == '1') {
                 if ($this->chkAssetDepreciation->Checked) {
                     if (!preg_match("/\\b\\d{1,3}(?:,?\\d{3})*(?:\\.\\d{2})?\\b/", $this->txtPurchaseCost->Text) || $this->txtPurchaseCost->Text <= 0) {
                         $blnError = true;
                         $this->txtPurchaseCost->Warning = "Purchase Cost value isn't valid";
                     } elseif (AssetModel::Load($this->lstAssetModel->SelectedValue)->DepreciationClassId != null) {
                         //print $this->calPurchaseDate->DateTime ."||". $this->txtPurchaseCost->Text."|";exit;
                         $this->objAsset->DepreciationFlag = true;
                         $this->objAsset->PurchaseDate = $this->calPurchaseDate->DateTime;
                         $this->objAsset->PurchaseCost = str_replace(',', '', $this->txtPurchaseCost->Text);
                     } else {
                         $blnError = true;
                         $this->chkAssetDepreciation->Warning = "Chosen Model isn't assigned to any Depreciation Class";
                     }
                 }
             }
             // Check to see if the asset tag already exists
             $AssetDuplicate = Asset::LoadByAssetCode($this->txtAssetCode->Text);
             if ($AssetDuplicate) {
                 $blnError = true;
                 $this->txtAssetCode->Warning = "That asset tag is already in use. Please try another.";
             }
             if (!$blnError && $this->txtParentAssetCode->Text) {
                 if ($this->txtParentAssetCode->Text != $this->objAsset->AssetCode) {
                     $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                     if (!$objParentAsset) {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "That asset tag does not exist. Please try another.";
                     } else {
                         if ($this->chkLockToParent->Checked && $objParentAsset->LocationId != $this->lstLocation->SelectedValue) {
                             // If locking child to parent, make sure assets are at the same location
                             $blnError = true;
                             $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                         } else {
                             if ($this->chkLockToParent->Checked && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                                 $blnError = true;
                                 $this->chkLockToParent->Warning = "Parent asset tag (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                             } else {
                                 $this->objAsset->ParentAssetId = $objParentAsset->AssetId;
                                 if ($this->chkLockToParent->Checked) {
                                     $this->objAsset->LinkedFlag = 1;
                                 }
                             }
                         }
                     }
                 } else {
                     $blnError = true;
                     $this->txtParentAssetCode->Warning = "Parent asset tag must not be the same as asset tag. Please try another.";
                 }
             } else {
                 // If txtParentAssetCode is empty
                 $this->objAsset->LinkedFlag = false;
                 $this->objAsset->ParentAssetId = null;
             }
             if (!$blnError) {
                 // Location can only be decided when creating an asset. Otherwise they must conduct a transaction.
                 if (!$this->blnEditMode) {
                     $this->objAsset->LocationId = $this->lstLocation->SelectedValue;
                 }
                 // Save child assets
                 $this->SaveChildAssets();
                 // Object should be saved only if it is new, to obtain the proper AssetId to add to the custom field tables
                 $this->objAsset->Save();
                 $this->objParentObject->RefreshChildAssets();
             }
         }
         // Assign input values to custom fields
         if (is_array($this->arrCustomFields) && count($this->arrCustomFields) > 0 && !$blnError) {
             // Save the values from all of the custom field controls to save the asset
             CustomField::SaveControls($this->objAsset->objCustomFieldArray, $this->blnEditMode, $this->arrCustomFields, $this->objAsset->AssetId, 1);
         }
         if ($this->blnEditMode) {
             // Check to see if the asset tag already exists (and is not the asset tag of the asset that the user is currently editing
             $AssetDuplicate = Asset::LoadByAssetCode($this->txtAssetCode->Text);
             if ($AssetDuplicate && $AssetDuplicate->AssetId != $this->objAsset->AssetId) {
                 $blnError = true;
                 $this->txtAssetCode->Warning = "That asset tag is already in use. Please try another.";
             }
             if (!$blnError && $this->txtParentAssetCode->Text) {
                 // Check if the parent asset tag is already a child asset of this asset
                 $arrChildAsset = Asset::LoadArrayByParentAssetId($this->objAsset->AssetId);
                 foreach ($arrChildAsset as $objChildAsset) {
                     if ($objChildAsset->AssetCode == $this->txtParentAssetCode->Text) {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "Parent asset tag is already a child of this asset. Please try another.";
                         break;
                     }
                 }
                 if (!$blnError) {
                     if ($this->txtParentAssetCode->Text != $this->objAsset->AssetCode) {
                         $objParentAsset = Asset::LoadByAssetCode($this->txtParentAssetCode->Text);
                         if (!$objParentAsset) {
                             $blnError = true;
                             $this->txtParentAssetCode->Warning = "That asset tag does not exist. Please try another.";
                         } else {
                             if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && $objParentAsset->LocationId != $this->objAsset->LocationId) {
                                 // If locking child to parent, make sure assets are at the same location
                                 $blnError = true;
                                 $this->chkLockToParent->Warning = 'Cannot lock to parent asset at another location.';
                             } else {
                                 if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && ($objParentAsset->CheckedOutFlag || $objParentAsset->ReservedFlag || $objParentAsset->ArchivedFlag || $objParentAsset->LocationId == 2 || $objParentAsset->LocationId == 5 || AssetTransaction::PendingTransaction($objParentAsset->AssetId))) {
                                     $blnError = true;
                                     $this->chkLockToParent->Warning = "Parent asset tag (" . $objParentAsset->AssetCode . ") must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                 } else {
                                     if ($this->chkLockToParent->Checked && !($this->objAsset->ParentAssetId == $objParentAsset->AssetId && $this->objAsset->LinkedFlag == 1) && ($this->objAsset->CheckedOutFlag || $this->objAsset->ReservedFlag || $this->objAsset->ArchivedFlag || $this->objAsset->LocationId == 2 || $this->objAsset->LocationId == 5 || AssetTransaction::PendingTransaction($this->objAsset->AssetId))) {
                                         $blnError = true;
                                         $this->chkLockToParent->Warning .= "Child asset must not be currently Archived, Checked Out, Pending Shipment, Shipped/TBR, or Reserved.";
                                     } else {
                                         $this->objAsset->ParentAssetId = $objParentAsset->AssetId;
                                         if ($this->chkLockToParent->Checked) {
                                             $this->objAsset->LinkedFlag = 1;
                                         } else {
                                             $this->objAsset->LinkedFlag = 0;
                                         }
                                     }
                                 }
                             }
                         }
                     } else {
                         $blnError = true;
                         $this->txtParentAssetCode->Warning = "Parent asset tag must not be the same as asset tag. Please try another.";
                     }
                 }
             } else {
                 // If txtParentAssetCode is empty
                 $this->objAsset->LinkedFlag = false;
                 $this->objAsset->ParentAssetId = null;
                 $this->chkLockToParent->Checked = false;
             }
             //				 Check Depreciation fields
             if (QApplication::$TracmorSettings->DepreciationFlag == '1') {
                 if ($this->chkAssetDepreciation->Checked) {
                     if (!preg_match("/\\b\\d{1,3}(?:,?\\d{3})*(?:\\.\\d{2})?\\b/", $this->txtPurchaseCost->Text) || $this->txtPurchaseCost->Text <= 0) {
                         $blnError = true;
                         $this->txtPurchaseCost->Warning = "Purchase Cost isn't valid";
                     } elseif (AssetModel::Load($this->lstAssetModel->SelectedValue)->DepreciationClassId != null) {
                         //print $this->calPurchaseDate->DateTime ."||". $this->txtPurchaseCost->Text."|";exit;
                         $this->objAsset->DepreciationFlag = true;
                         $this->objAsset->PurchaseDate = $this->calPurchaseDate->DateTime;
                         $this->objAsset->PurchaseCost = str_replace(',', '', $this->txtPurchaseCost->Text);
                     } else {
                         $blnError = true;
                         $this->chkAssetDepreciation->Warning = "Chosen Model isn't assigned to any Depreciation Class";
                     }
                 } else {
                     $this->objAsset->DepreciationFlag = false;
                     $this->objAsset->PurchaseDate = null;
                     $this->objAsset->PurchaseCost = null;
                 }
             }
             if (!$blnError) {
                 // Update the values of all fields for an Ajax reload
                 $this->UpdateAssetFields();
                 // Save child assets
                 $this->SaveChildAssets();
                 // If asset is not new, it must be saved after updating the assetfields
                 $this->objAsset->Save();
                 // This is called to retrieve the new Modified Date and User
                 $this->objParentObject->SetupAsset($this);
                 // Give the labels their appropriate values before display
                 $this->UpdateAssetLabels();
                 // This was necessary because it was not saving the changes of a second edit/save in a row
                 // Reload all custom fields
                 $this->objAsset->objCustomFieldArray = CustomField::LoadObjCustomFieldArray(1, $this->blnEditMode, $this->objAsset->AssetId, false, $this->objAsset->AssetModelId);
                 // Update not allowed custom fields set to null
                 $arrAllowed = array();
                 foreach (AssetCustomFieldAssetModel::LoadArrayByAssetModelId($this->objAsset->AssetModelId) as $objAssetCustomField) {
                     $arrAllowed[] = $objAssetCustomField->CustomFieldId;
                 }
                 $arrToClear = array();
                 foreach (EntityQtypeCustomField::LoadArrayByEntityQtypeId(1) as $objAssetCustomField) {
                     if (!in_array($objAssetCustomField->CustomFieldId, $arrAllowed) && $objAssetCustomField->CustomField->AllAssetModelsFlag != 1) {
                         $arrToClear[] = $objAssetCustomField->CustomFieldId;
                     }
                 }
                 if ($this->objAsset->AssetId && count($arrToClear)) {
                     $arrForQuery = array();
                     foreach ($arrToClear as $idToBeNull) {
                         $arrForQuery[] = sprintf("`cfv_%s`= NULL", $idToBeNull);
                     }
                     $objDatabase = Asset::GetDatabase();
                     $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", implode(", ", $arrForQuery), $this->objAsset->AssetId);
                     //  print($strQuery); exit;
                     $objDatabase->NonQuery($strQuery);
                 }
                 // Commit the above transactions to the database
                 $objDatabase->TransactionCommit();
                 // Hide inputs and display labels
                 $this->displayLabels();
                 // Enable the appropriate transaction buttons
                 $this->EnableTransactionButtons();
                 $this->objParentObject->RefreshChildAssets();
             }
         } elseif (!$blnError) {
             // Commit the above transactions to the database
             $objDatabase->TransactionCommit();
             // Reload the edit asset page with the newly created asset
             $strRedirect = sprintf('asset_edit.php?intAssetId=%s', $this->objAsset->AssetId);
             QApplication::Redirect($strRedirect);
         }
     } catch (QOptimisticLockingException $objExc) {
         // Rollback the database
         $objDatabase->TransactionRollback();
         // Output the error
         $this->btnCancel->Warning = sprintf('This asset has been updated by another user. You must <a href="asset_edit.php?intAssetId=%s">Refresh</a> to edit this Asset.', $this->objAsset->AssetId);
     }
 }
Exemplo n.º 28
0
 protected function DeleteEntityQtypeCustomFields()
 {
     $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->objCustomField->CustomFieldId);
     if ($objEntityQtypeCustomFieldArray) {
         foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
             // If the EntityQtype needs to be deleted, you must delete EntityQtypeId for all roles in RoleEntityQTypeCustomFieldAuthorization
             $objRoleEntityCustomAuthArray = RoleEntityQtypeCustomFieldAuthorization::LoadArrayByEntityQtypeCustomFieldId($objEntityQtypeCustomField->EntityQtypeCustomFieldId);
             if ($objRoleEntityCustomAuthArray) {
                 foreach ($objRoleEntityCustomAuthArray as $objRoleEntityCustomAuth) {
                     $objRoleEntityCustomAuth->Delete();
                 }
             }
             // Delete the EntityQtypeCustomField last
             //$objEntityQtypeCustomField->Delete();
         }
     }
 }