protected function lstModel_Create() { $this->lstModel = new QListBox($this, 'Model'); $this->lstModel->Name = 'Model'; $this->lstModel->AddItem('- Select One -', null); $assetModelArray = AssetModel::LoadAllIntoArray(); if ($assetModelArray) { foreach ($assetModelArray as $assetModel) { $objListItem = new QListItem($assetModel['short_description'], $assetModel['asset_model_id']); $this->lstModel->AddItem($objListItem); } } $this->lstModel->Enabled = false; }
protected function SetupAssetModel() { // Lookup Object PK information from Query String (if applicable) // Set mode to Edit or New depending on what's found $intAssetModelId = QApplication::QueryString('intAssetModelId'); if ($intAssetModelId) { $this->objAssetModel = AssetModel::Load($intAssetModelId); if (!$this->objAssetModel) { throw new Exception('Could not find a AssetModel object with PK arguments: ' . $intAssetModelId); } $this->strTitleVerb = QApplication::Translate('Edit'); $this->blnEditMode = true; } else { $this->objAssetModel = new AssetModel(); $this->strTitleVerb = QApplication::Translate('Create'); $this->blnEditMode = false; } }
protected function rblAssetType_Change($strFormId, $strControlId, $strParameter) { $this->txtNewAssetCode->Text = ''; // If adding an existing asset to the receipt if ($this->rblAssetType->SelectedValue == 'existing') { $this->lstAssetModel->Display = false; $this->chkAutoGenerateAssetCode->Checked = false; $this->chkAutoGenerateAssetCode->Display = false; $this->txtNewAssetCode->Enabled = true; $this->lblAddAsset->Display = true; } elseif ($this->rblAssetType->SelectedValue == 'new') { $objAssetModelArray = AssetModel::LoadAll(QQ::Clause(QQ::OrderBy(QQN::AssetModel()->ShortDescription))); if ($objAssetModelArray) { foreach ($objAssetModelArray as $objAssetModel) { $objListItem = new QListItem($objAssetModel->__toString(), $objAssetModel->AssetModelId); $this->lstAssetModel->AddItem($objListItem); } } // Display the list of possible asset models $this->lstAssetModel->Display = true; // Display the Auto Generate Asset Code checkbox if a minimum value exists if (QApplication::$TracmorSettings->MinAssetCode) { $this->chkAutoGenerateAssetCode->Display = true; } $this->lblAddAsset->Display = false; } }
protected function dtgAssetModel_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->dtgAssetModel->TotalItemCount = AssetModel::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->dtgAssetModel->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->dtgAssetModel->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be the array of all AssetModel objects, given the clauses above $this->dtgAssetModel->DataSource = AssetModel::LoadAll($objClauses); }
/** * */ public function renderMaster() { // Build the master view if necessary if (in_array($this->_DeliveryType, array(DELIVERY_TYPE_ALL))) { $this->MasterView = $this->masterView(); // Only get css & ui components if this is NOT a syndication request if ($this->SyndicationMethod == SYNDICATION_NONE && is_object($this->Head)) { $CssAnchors = AssetModel::getAnchors(); $this->EventArguments['CssFiles'] =& $this->_CssFiles; $this->fireEvent('BeforeAddCss'); $ETag = AssetModel::eTag(); $CombineAssets = c('Garden.CombineAssets'); $ThemeType = isMobile() ? 'mobile' : 'desktop'; // And now search for/add all css files. foreach ($this->_CssFiles as $CssInfo) { $CssFile = $CssInfo['FileName']; if (!array_key_exists('Options', $CssInfo) || !is_array($CssInfo['Options'])) { $CssInfo['Options'] = array(); } $Options =& $CssInfo['Options']; // style.css and admin.css deserve some custom processing. if (in_array($CssFile, $CssAnchors)) { if (!$CombineAssets) { // Grab all of the css files from the asset model. $AssetModel = new AssetModel(); $CssFiles = $AssetModel->getCssFiles($ThemeType, ucfirst(substr($CssFile, 0, -4)), $ETag); foreach ($CssFiles as $Info) { $this->Head->addCss($Info[1], 'all', true, $CssInfo); } } else { $Basename = substr($CssFile, 0, -4); $this->Head->addCss(url("/asset/css/{$ThemeType}/{$Basename}-{$ETag}.css", '//'), 'all', false, $CssInfo['Options']); } continue; } $AppFolder = $CssInfo['AppFolder']; $LookupFolder = !empty($AppFolder) ? $AppFolder : $this->ApplicationFolder; $Search = AssetModel::CssPath($CssFile, $LookupFolder, $ThemeType); if (!$Search) { continue; } list($Path, $UrlPath) = $Search; if (isUrl($Path)) { $this->Head->AddCss($Path, 'all', val('AddVersion', $Options, true), $Options); continue; } else { // Check to see if there is a CSS cacher. $CssCacher = Gdn::factory('CssCacher'); if (!is_null($CssCacher)) { $Path = $CssCacher->get($Path, $AppFolder); } if ($Path !== false) { $Path = substr($Path, strlen(PATH_ROOT)); $Path = str_replace(DS, '/', $Path); $this->Head->addCss($Path, 'all', true, $Options); } } } // Add a custom js file. if (arrayHasValue($this->_CssFiles, 'style.css')) { $this->addJsFile('custom.js'); // only to non-admin pages. } $Cdns = array(); if (!c('Garden.Cdns.Disable', false)) { $Cdns = array('jquery.js' => "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"); } // And now search for/add all JS files. $this->EventArguments['Cdns'] =& $Cdns; $this->fireEvent('AfterJsCdns'); $this->Head->addScript('', 'text/javascript', false, array('content' => $this->definitionList(false))); foreach ($this->_JsFiles as $Index => $JsInfo) { $JsFile = $JsInfo['FileName']; if (!is_array($JsInfo['Options'])) { $JsInfo['Options'] = array(); } $Options =& $JsInfo['Options']; if (isset($Cdns[$JsFile])) { $JsFile = $Cdns[$JsFile]; } $AppFolder = $JsInfo['AppFolder']; $LookupFolder = !empty($AppFolder) ? $AppFolder : $this->ApplicationFolder; $Search = AssetModel::JsPath($JsFile, $LookupFolder, $ThemeType); if (!$Search) { continue; } list($Path, $UrlPath) = $Search; if ($Path !== false) { $AddVersion = true; if (!isUrl($Path)) { $Path = substr($Path, strlen(PATH_ROOT)); $Path = str_replace(DS, '/', $Path); $AddVersion = val('AddVersion', $Options, true); } $this->Head->addScript($Path, 'text/javascript', $AddVersion, $Options); continue; } } } // Add the favicon. $Favicon = C('Garden.FavIcon'); if ($Favicon) { $this->Head->setFavIcon(Gdn_Upload::url($Favicon)); } // Make sure the head module gets passed into the assets collection. $this->addModule('Head'); } // Master views come from one of four places: $MasterViewPaths = array(); if (strpos($this->MasterView, '/') !== false) { $MasterViewPaths[] = combinePaths(array(PATH_ROOT, str_replace('/', DS, $this->MasterView) . '.master*')); } else { if ($this->Theme) { // 1. Application-specific theme view. eg. root/themes/theme_name/app_name/views/ $MasterViewPaths[] = combinePaths(array(PATH_THEMES, $this->Theme, $this->ApplicationFolder, 'views', $this->MasterView . '.master*')); // 2. Garden-wide theme view. eg. /path/to/application/themes/theme_name/views/ $MasterViewPaths[] = combinePaths(array(PATH_THEMES, $this->Theme, 'views', $this->MasterView . '.master*')); } // 3. Plugin default. eg. root/plugin_name/views/ $MasterViewPaths[] = combinePaths(array(PATH_ROOT, $this->ApplicationFolder, 'views', $this->MasterView . '.master*')); // 4. Application default. eg. root/app_name/views/ $MasterViewPaths[] = combinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*')); // 5. Garden default. eg. root/dashboard/views/ $MasterViewPaths[] = combinePaths(array(PATH_APPLICATIONS, 'dashboard', 'views', $this->MasterView . '.master*')); } // Find the first file that matches the path. $MasterViewPath = false; foreach ($MasterViewPaths as $Glob) { $Paths = safeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $MasterViewPath = $Paths[0]; break; } } $this->EventArguments['MasterViewPath'] =& $MasterViewPath; $this->fireEvent('BeforeFetchMaster'); if ($MasterViewPath === false) { trigger_error(errorMessage("Could not find master view: {$this->MasterView}.master*", $this->ClassName, '_FetchController'), E_USER_ERROR); } /// A unique identifier that can be used in the body tag of the master view if needed. $ControllerName = $this->ClassName; // Strip "Controller" from the body identifier. if (substr($ControllerName, -10) == 'Controller') { $ControllerName = substr($ControllerName, 0, -10); } // Strip "Gdn_" from the body identifier. if (substr($ControllerName, 0, 4) == 'Gdn_') { $ControllerName = substr($ControllerName, 4); } $this->setData('CssClass', $this->Application . ' ' . $ControllerName . ' ' . $this->RequestMethod . ' ' . $this->CssClass, true); // Check to see if there is a handler for this particular extension. $ViewHandler = Gdn::factory('ViewHandler' . strtolower(strrchr($MasterViewPath, '.'))); if (is_null($ViewHandler)) { $BodyIdentifier = strtolower($this->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::alphaNumeric(strtolower($this->RequestMethod))); include $MasterViewPath; } else { $ViewHandler->render($MasterViewPath, $this); } }
/** * Gather all of the global styles together. * @param string ThemeType Either `desktop` or `mobile`. * @param string $Filename The basename of the file to * @since 2.1 */ public function Css($ThemeType, $Filename) { $AssetModel = new AssetModel(); $AssetModel->ServeCss($ThemeType, $Filename); }
/** * Add our CSS. * * @param AssetModel $sender */ public function assetModel_styleCss_handler($sender) { $sender->addCssFile('fileupload.css', 'plugins/FileUpload'); }
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_%s.csv', __DOCROOT__ . __SUBDIRECTORY__ . __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 (QApplication::$TracmorSettings->AssetLimit != null && QApplication::$TracmorSettings->AssetLimit < $this->intTotalCount + Asset::CountAll()) { $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', __DOCROOT__ . __SUBDIRECTORY__ . __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; $blnAssetCode = false; $blnLocation = false; $blnAssetModelCode = false; $blnAssetModelShortDescription = false; $blnCategory = false; $blnManufacturer = false; // Checking errors (Location, Asset Code, 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 == "location") { $blnLocation = true; } elseif ($strSelectedValue == "asset code") { $blnAssetCode = true; } elseif ($strSelectedValue == "asset model short description") { $blnAssetModelShortDescription = true; } elseif ($strSelectedValue == "asset model code") { $blnAssetModelCode = true; } elseif ($strSelectedValue == "category") { $blnCategory = true; } elseif ($strSelectedValue == "manufacturer") { $blnManufacturer = 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."; break; } else { $blnError = false; $txtDefault->Warning = ""; } } } // If all required fields have no errors if (!$blnError && $blnAssetCode && $blnAssetModelCode && $blnAssetModelShortDescription && $blnLocation && $blnCategory && $blnManufacturer) { $this->btnNext->Warning = ""; // Setup keys for main required fields foreach ($this->arrTracmorField as $key => $value) { if ($value == 'location') { $this->intLocationKey = $key; } elseif ($value == 'category') { $this->intCategoryKey = $key; } elseif ($value == 'manufacturer') { $this->intManufacturerKey = $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; } } $strLocationArray = array(); $strNewLocationArray = array(); // Load all locations foreach (Location::LoadAll() as $objLocation) { $strLocationArray[] = stripslashes($objLocation->ShortDescription); } $txtDefaultValue = trim($this->txtMapDefaultValueArray[$this->intLocationKey]->Text); // Add default value in database if it is not exist if ($txtDefaultValue && !$this->in_array_nocase($txtDefaultValue, $strLocationArray)) { $strLocationArray[] = $txtDefaultValue; $objNewLocation = new Location(); $objNewLocation->ShortDescription = addslashes($txtDefaultValue); $objNewLocation->EnabledFlag = 1; $objNewLocation->Save(); $this->objNewLocationArray[$objNewLocation->LocationId] = $objNewLocation->ShortDescription; } $this->objNewLocationArray = array(); $this->objNewCategoryArray = array(); $this->objNewManufacturerArray = array(); $this->objNewAssetModelArray = array(); $this->strModelValuesArray = array(); $this->blnImportEnd = false; $j = 1; $strLocationValuesArray = array(); // Add all unique locations in database foreach ($this->strFilePathArray as $strFilePath) { $this->FileCsvData->load($strFilePath); if ($j != 1) { //$this->FileCsvData->appendRow($this->FileCsvData->getHeaders()); } // Location Import for ($i = 0; $i < $this->FileCsvData->countRows(); $i++) { $strRowArray = $this->FileCsvData->getRow($i); if (trim($strRowArray[$this->intLocationKey]) && !$this->in_array_nocase(trim($strRowArray[$this->intLocationKey]), $strLocationArray)) { $strLocationArray[] = trim($strRowArray[$this->intLocationKey]); /*$objNewLocation = new Location(); $objNewLocation->ShortDescription = addslashes(trim($strRowArray[$this->intLocationKey])); $objNewLocation->Save();*/ $strLocationValuesArray[] = sprintf("('%s', '%s', NOW())", addslashes(trim($strRowArray[$this->intLocationKey])), $_SESSION['intUserAccountId']); $strNewLocation[] = addslashes(trim($strRowArray[$this->intLocationKey])); //$this->objNewLocationArray[$objNewLocation->LocationId] = $objNewLocation->ShortDescription; } } $j++; } if (count($strLocationValuesArray)) { $objDatabase = Location::GetDatabase(); $objDatabase->NonQuery(sprintf("INSERT INTO `location` (`short_description`, `created_by`, `creation_date`) VALUES %s;", implode(", ", $strLocationValuesArray))); $intStartId = $objDatabase->InsertId(); for ($i = 0; $i < count($strNewLocation); $i++) { $this->objNewLocationArray[$intStartId + $i] = $strNewLocation[$i]; } } $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 = "Locations have been imported. Please wait..."; $this->intImportStep = 2; $this->intCurrentFile = 0; $this->strSelectedValueArray = array(); // New locations $this->dtgLocation = new QDataGrid($this); $this->dtgLocation->Name = 'location_list'; $this->dtgLocation->CellPadding = 5; $this->dtgLocation->CellSpacing = 0; $this->dtgLocation->CssClass = "datagrid"; $this->dtgLocation->UseAjax = true; $this->dtgLocation->ShowColumnToggle = false; $this->dtgLocation->ShowExportCsv = false; $this->dtgLocation->ShowHeader = false; $this->dtgLocation->AddColumn(new QDataGridColumnExt('Location', '<?= $_ITEM ?>', 'CssClass="dtg_column"', 'HtmlEntities="false"')); // New categories $this->dtgCategory = new QDataGrid($this); $this->dtgCategory->Name = 'category_list'; $this->dtgCategory->CellPadding = 5; $this->dtgCategory->CellSpacing = 0; $this->dtgCategory->CssClass = "datagrid"; $this->dtgCategory->UseAjax = true; $this->dtgCategory->ShowColumnToggle = false; $this->dtgCategory->ShowExportCsv = false; $this->dtgCategory->ShowHeader = false; $this->dtgCategory->AddColumn(new QDataGridColumnExt('Manufacturer', '<?= $_ITEM ?>', 'CssClass="dtg_column"', 'HtmlEntities="false"')); // New manufacturers $this->dtgManufacturer = new QDataGrid($this); $this->dtgManufacturer->Name = 'manufacturer_list'; $this->dtgManufacturer->CellPadding = 5; $this->dtgManufacturer->CellSpacing = 0; $this->dtgManufacturer->CssClass = "datagrid"; $this->dtgManufacturer->UseAjax = true; $this->dtgManufacturer->ShowColumnToggle = false; $this->dtgManufacturer->ShowExportCsv = false; $this->dtgManufacturer->ShowHeader = false; $this->dtgManufacturer->AddColumn(new QDataGridColumnExt('Manufacturer', '<?= $_ITEM ?>', 'CssClass="dtg_column"', 'HtmlEntities="false"')); // 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"')); // New assets $this->dtgAsset = new QDataGrid($this); $this->dtgAsset->Name = 'asset_list'; $this->dtgAsset->CellPadding = 5; $this->dtgAsset->CellSpacing = 0; $this->dtgAsset->CssClass = "datagrid"; $this->dtgAsset->UseAjax = true; $this->dtgAsset->ShowColumnToggle = false; $this->dtgAsset->ShowExportCsv = false; $this->dtgAsset->ShowHeader = false; $this->dtgAsset->AddColumn(new QDataGridColumnExt('Asset Tag', '<?= $_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 Assets"; $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 (Asset Tag, Model Number, Model Short Description, Location, Category and Manufacturer)."; $blnError = true; } } else { // Step 3 complete set_time_limit(0); $file_skipped = fopen($strFilePath = sprintf('%s/%s_skipped.csv', __DOCROOT__ . __SUBDIRECTORY__ . __TRACMOR_TMP__, $_SESSION['intUserAccountId']), "a"); if (!$this->blnImportEnd) { // Category if ($this->intImportStep == 2) { $strCategoryArray = array(); $this->objNewCategoryArray = array(); // Load all categories foreach (Category::LoadAll() as $objCategory) { $strCategoryArray[] = stripslashes($objCategory->ShortDescription); } // Add Default value $txtDefaultValue = trim($this->txtMapDefaultValueArray[$this->intCategoryKey]->Text); if ($txtDefaultValue && !$this->in_array_nocase($txtDefaultValue, $strCategoryArray)) { $strCategoryArray[] = $txtDefaultValue; $objNewCategory = new Category(); $objNewCategory->ShortDescription = addslashes($txtDefaultValue); $objNewCategory->AssetFlag = true; $objNewCategory->InventoryFlag = false; $objNewCategory->Save(); $this->objNewCategoryArray[$objNewCategory->CategoryId] = $objNewCategory->ShortDescription; } $this->btnNext->Warning = "Categories have been imported. Please wait..."; } elseif ($this->intImportStep == 3) { $strManufacturerArray = array(); $this->objNewManufacturerArray = array(); // Load all manufacturers foreach (Manufacturer::LoadAll() as $objManufacturer) { $strManufacturerArray[] = stripslashes($objManufacturer->ShortDescription); } $txtDefaultValue = trim($this->txtMapDefaultValueArray[$this->intManufacturerKey]->Text); // Add Default Value if ($txtDefaultValue && !$this->in_array_nocase($txtDefaultValue, $strManufacturerArray)) { $strManufacturerArray[] = $txtDefaultValue; $objNewManufacturer = new Manufacturer(); $objNewManufacturer->ShortDescription = addslashes($txtDefaultValue); $objNewManufacturer->Save(); $this->objNewManufacturerArray[$objNewManufacturer->ManufacturerId] = $objNewManufacturer->ShortDescription; } $this->btnNext->Warning = "Manufacturers have been imported. Please wait..."; } elseif ($this->intImportStep == 4) { $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); } $intModelCustomFieldKeyArray = array(); $arrAssetModelCustomField = array(); // Setup keys foreach ($this->arrTracmorField as $key => $value) { if ($value == 'asset model short description') { $intModelShortDescriptionKey = $key; } elseif ($value == 'asset model long description') { $intModelLongDescriptionKey = $key; } elseif ($value == 'asset model code') { $intModelCodeKey = $key; } elseif ($value == 'asset code') { $intAssetCode = $key; } elseif (substr($value, 0, 6) == 'model_') { $intModelCustomFieldKeyArray[substr($value, 6)] = $key; if (array_key_exists(substr($value, 6), $this->arrAssetCustomField)) { $arrAssetModelCustomField[substr($value, 6)] = $this->arrAssetCustomField[substr($value, 6)]; } } } $strAssetModelArray = array(); // Load all asset models foreach (AssetModel::LoadAll() as $objAssetModel) { $strAssetModelArray[] = strtolower(sprintf("%s_%s_%s_%s", $objAssetModel->AssetModelCode, $objAssetModel->ShortDescription, $objAssetModel->CategoryId, $objAssetModel->ManufacturerId)); } $this->btnNext->Warning = sprintf("Please wait... Model import complete: %s%s", ceil(($this->intCurrentFile + 1) * 200 / $this->intTotalCount * 100), "%"); } 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), "%"); } for ($j = $this->intCurrentFile; $j < count($this->strFilePathArray); $j++) { $this->FileCsvData->load($this->strFilePathArray[$j]); if (!$j) { //$this->FileCsvData->appendRow($this->FileCsvData->getHeaders()); } // Category Import if ($this->intImportStep == 2) { $strCategoryValuesArray = array(); $strNewCategoryArray = array(); for ($i = 0; $i < $this->FileCsvData->countRows(); $i++) { $strRowArray = $this->FileCsvData->getRow($i); if (trim($strRowArray[$this->intCategoryKey]) && !$this->in_array_nocase(trim($strRowArray[$this->intCategoryKey]), $strCategoryArray)) { $strCategoryArray[] = trim($strRowArray[$this->intCategoryKey]); /*$objNewCategory = new Category(); $objNewCategory->ShortDescription = addslashes(trim($strRowArray[$this->intCategoryKey])); $objNewCategory->AssetFlag = true; $objNewCategory->InventoryFlag = false; $objNewCategory->Save(); $this->objNewCategoryArray[$objNewCategory->CategoryId] = $objNewCategory->ShortDescription;*/ $strCategoryValuesArray[] = sprintf("('%s', '1', '0', '%s', NOW())", addslashes(trim($strRowArray[$this->intCategoryKey])), $_SESSION['intUserAccountId']); $strNewCategoryArray[] = addslashes(trim($strRowArray[$this->intCategoryKey])); } } if (count($strCategoryValuesArray)) { $objDatabase = Category::GetDatabase(); $objDatabase->NonQuery(sprintf("INSERT INTO `category` (`short_description`, `asset_flag`, `inventory_flag`, `created_by`, `creation_date`) VALUES %s;", implode(", ", $strCategoryValuesArray))); $intStartId = $objDatabase->InsertId(); for ($i = 0; $i < count($strNewCategoryArray); $i++) { $this->objNewCategoryArray[$intStartId + $i] = $strNewCategoryArray[$i]; } } } elseif ($this->intImportStep == 3) { $strManufacturerValuesArray = array(); $strNewManufacturerArray = array(); for ($i = 0; $i < $this->FileCsvData->countRows(); $i++) { $strRowArray = $this->FileCsvData->getRow($i); if (trim($strRowArray[$this->intManufacturerKey]) && !$this->in_array_nocase(trim($strRowArray[$this->intManufacturerKey]), $strManufacturerArray)) { $strManufacturerArray[] = trim($strRowArray[$this->intManufacturerKey]); /*$objNewManufacturer = new Manufacturer(); $objNewManufacturer->ShortDescription = addslashes(trim($strRowArray[$this->intManufacturerKey])); $objNewManufacturer->Save(); $this->objNewManufacturerArray[$objNewManufacturer->ManufacturerId] = $objNewManufacturer->ShortDescription;*/ $strManufacturerValuesArray[] = sprintf("('%s', '%s', NOW())", addslashes(trim($strRowArray[$this->intManufacturerKey])), $_SESSION['intUserAccountId']); $strNewManufacturerArray[] = addslashes(trim($strRowArray[$this->intManufacturerKey])); } } if (count($strManufacturerValuesArray)) { $objDatabase = Manufacturer::GetDatabase(); $objDatabase->NonQuery(sprintf("INSERT INTO `manufacturer` (`short_description`, `created_by`, `creation_date`) VALUES %s;", implode(", ", $strManufacturerValuesArray))); $intStartId = $objDatabase->InsertId(); for ($i = 0; $i < count($strNewManufacturerArray); $i++) { $this->objNewManufacturerArray[$intStartId + $i] = $strNewManufacturerArray[$i]; } } } elseif ($this->intImportStep == 4) { $objNewAssetModelArray = array(); for ($i = 0; $i < $this->FileCsvData->countRows(); $i++) { $strRowArray = $this->FileCsvData->getRow($i); $strShortDescription = trim($strRowArray[$intModelShortDescriptionKey]) ? addslashes(trim($strRowArray[$intModelShortDescriptionKey])) : false; $strAssetModelCode = trim($strRowArray[$intModelCodeKey]) ? addslashes(trim($strRowArray[$intModelCodeKey])) : addslashes(trim($this->txtMapDefaultValueArray[$intModelCodeKey]->Text)); $strKeyArray = array_keys($intCategoryArray, addslashes(strtolower(trim($strRowArray[$this->intCategoryKey])))); if (count($strKeyArray)) { $intCategoryId = $strKeyArray[0]; } else { $strKeyArray = array_keys($intCategoryArray, addslashes(strtolower(trim($this->txtMapDefaultValueArray[$this->intCategoryKey]->Text)))); if (count($strKeyArray)) { $intCategoryId = $strKeyArray[0]; } else { $intCategoryId = false; } } $strKeyArray = array_keys($intManufacturerArray, addslashes(strtolower(trim($strRowArray[$this->intManufacturerKey])))); if (count($strKeyArray)) { $intManufacturerId = $strKeyArray[0]; } else { $strKeyArray = array_keys($intManufacturerArray, addslashes(strtolower(trim($this->txtMapDefaultValueArray[$this->intManufacturerKey]->Text)))); if (count($strKeyArray)) { $intManufacturerId = $strKeyArray[0]; } else { $intManufacturerId = false; } } if (!$strShortDescription || $intCategoryId === false || $intManufacturerId === false) { //$blnError = true; //$this->intSkippedRecordCount++; //$this->PutSkippedRecordInFile($file_skipped, $strRowArray); //echo sprintf("Desc: %s AssetCode: %s Cat: %s Man: %s<br/>", $strShortDescription, $strAssetModelCode, $intCategoryId, $intManufacturerId); //break; $strAssetModel = null; } else { //$blnError = false; $strAssetModel = strtolower(sprintf("%s_%s_%s_%s", $strAssetModelCode, $strShortDescription, $intCategoryId, $intManufacturerId)); } if ($strAssetModel && !$this->in_array_nocase($strAssetModel, $strAssetModelArray)) { $strAssetModelArray[] = $strAssetModel; /*$objNewAssetModel = new AssetModel(); $objNewAssetModel->ShortDescription = $strShortDescription; $objNewAssetModel->AssetModelCode = $strAssetModelCode; $objNewAssetModel->CategoryId = $intCategoryId; $objNewAssetModel->ManufacturerId = $intManufacturerId; if (isset($intModelLongDescriptionKey)) { $objNewAssetModel->LongDescription = addslashes(trim($strRowArray[$intModelLongDescriptionKey])); } $objNewAssetModel->Save(); // Asset Model Custom Field import foreach ($arrAssetModelCustomField as $objCustomField) { if ($objCustomField->CustomFieldQtypeId != 2) { $objCustomField->CustomFieldSelection = new CustomFieldSelection; $objCustomField->CustomFieldSelection->newCustomFieldValue = new CustomFieldValue; $objCustomField->CustomFieldSelection->newCustomFieldValue->CustomFieldId = $objCustomField->CustomFieldId; if (trim($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]])) { $objCustomField->CustomFieldSelection->newCustomFieldValue->ShortDescription = addslashes(trim($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]])); } else { $objCustomField->CustomFieldSelection->newCustomFieldValue->ShortDescription = addslashes($this->txtMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text); } $objCustomField->CustomFieldSelection->newCustomFieldValue->Save(); $objCustomField->CustomFieldSelection->EntityId = $objNewAssetModel->AssetModelId; $objCustomField->CustomFieldSelection->EntityQtypeId = 4; $objCustomField->CustomFieldSelection->CustomFieldValueId = $objCustomField->CustomFieldSelection->newCustomFieldValue->CustomFieldValueId; $objCustomField->CustomFieldSelection->Save(); } else { $data = trim($strRowArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]); $blnInList = false; $objCustomField->CustomFieldSelection = new CustomFieldSelection; $objCustomField->CustomFieldSelection->EntityId = $objNewAssetModel->AssetModelId; $objCustomField->CustomFieldSelection->EntityQtypeId = 4; foreach (CustomFieldValue::LoadArrayByCustomFieldId($objCustomField->CustomFieldId) as $objCustomFieldValue) { if (strtolower($objCustomFieldValue->ShortDescription) == $data) { $objCustomField->CustomFieldSelection->CustomFieldValueId = $objCustomFieldValue->CustomFieldValueId; $blnInList = true; break; } } if (!$blnInList && $this->lstMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) { $objCustomField->CustomFieldSelection->CustomFieldValueId = $this->lstMapDefaultValueArray[$intModelCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue; $objCustomField->CustomFieldSelection->Save(); } elseif ($data) { $objCustomField->CustomFieldSelection->Save(); } } }*/ $this->strModelValuesArray[] = sprintf("('%s', '%s', '%s', '%s', '%s', '%s', NOW())", $strShortDescription, isset($intModelLongDescriptionKey) ? addslashes(trim($strRowArray[$intModelLongDescriptionKey])) : null, $strAssetModelCode, $intCategoryId, $intManufacturerId, $_SESSION['intUserAccountId']); $objNewAssetModelArray[] = $strShortDescription; } } //if ($this->intCurrentFile == count($this->strFilePathArray)) { if (count($this->strModelValuesArray)) { //$strNewModelArray = array_merge($this->objNewAssetModelArray, array()); //$this->objNewAssetModelArray = array(); $objDatabase = AssetModel::GetDatabase(); //var_dump($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;", implode(", ", $this->strModelValuesArray))); $intStartId = $objDatabase->InsertId(); for ($i = 0; $i < count($objNewAssetModelArray); $i++) { //$objDatabase->NonQuery(sprintf("INSERT INTO `asset_model` (`short_description`, `long_description`, `asset_model_code`, `category_id`, `manufacturer_id`, `created_by`, `creation_date`) VALUES %s;", $this->strModelValuesArray[$i])); //$intStartId = $objDatabase->InsertId(); $this->objNewAssetModelArray[$intStartId + $i] = $objNewAssetModelArray[$i]; } $this->strModelValuesArray = array(); } //} //$this->intCurrentFile++; //break; } elseif ($this->intImportStep == 5) { $strAssetValuesArray = array(); $objAssetValuesArray = array(); $strAssetCFVArray = array(); $strUpdatedAssetCFVArray = array(); $strAssetCodeArray = array(); $strAddedCFVArray = array(); // This will add extra commas for blank values $this->FileCsvData->symmetrize(); for ($i = 0; $i < $this->FileCsvData->countRows(); $i++) { $strRowArray = $this->FileCsvData->getRow($i); // The addslashes was causing match-up problems //$strShortDescription = (trim($strRowArray[$intModelShortDescriptionKey])) ? addslashes(trim($strRowArray[$intModelShortDescriptionKey])) : false; $strShortDescription = trim($strRowArray[$intModelShortDescriptionKey]) ? trim($strRowArray[$intModelShortDescriptionKey]) : false; $strAssetModelCode = trim($strRowArray[$intModelCodeKey]) ? addslashes(trim($strRowArray[$intModelCodeKey])) : addslashes(trim($this->txtMapDefaultValueArray[$intModelCodeKey]->Text)); $strKeyArray = array_keys($intCategoryArray, addslashes(strtolower(trim($strRowArray[$this->intCategoryKey])))); if (count($strKeyArray)) { $intCategoryId = $strKeyArray[0]; } else { $strKeyArray = array_keys($intCategoryArray, addslashes(strtolower(trim($this->txtMapDefaultValueArray[$this->intCategoryKey]->Text)))); if (count($strKeyArray)) { $intCategoryId = $strKeyArray[0]; } else { $intCategoryId = false; } } $strKeyArray = array_keys($intManufacturerArray, addslashes(strtolower(trim($strRowArray[$this->intManufacturerKey])))); if (count($strKeyArray)) { $intManufacturerId = $strKeyArray[0]; } else { $strKeyArray = array_keys($intManufacturerArray, addslashes(strtolower(trim($this->txtMapDefaultValueArray[$this->intManufacturerKey]->Text)))); if (count($strKeyArray)) { $intManufacturerId = $strKeyArray[0]; } else { $intManufacturerId = false; } } if (!$strShortDescription || $intCategoryId === false || $intManufacturerId === false) { //$blnError = true; $this->intSkippedRecordCount++; $this->PutSkippedRecordInFile($file_skipped, $strRowArray); //break; } else { //$blnError = false; $strAssetModel = strtolower(sprintf("%s_%s_%s_%s", $strAssetModelCode, $strShortDescription, $intCategoryId, $intManufacturerId)); $strAssetCode = addslashes(trim($strRowArray[$intAssetCode])); if ($strAssetCode && !$this->in_array_nocase($strAssetCode, $strAssetArray)) { $intLocationKeyArray = array_keys($intLocationArray, addslashes(strtolower(trim($strRowArray[$this->intLocationKey])))); if (!count($intLocationKeyArray)) { $intLocationKeyArray = array_keys($intLocationArray, addslashes(strtolower(trim($this->txtMapDefaultValueArray[$this->intLocationKey]->Text)))); } $intModelKeyArray = array_keys($this->intAssetModelArray, $strAssetModel); if (count($intLocationKeyArray) && count($intModelKeyArray)) { $strAssetArray[] = strtolower($strAssetCode); $strAssetValuesArray[] = sprintf("('%s', '%s', '%s', '%s', NOW())", $strAssetCode, $intLocationKeyArray[0], $intModelKeyArray[0], $_SESSION['intUserAccountId']); /*$objNewAsset = new Asset(); $objNewAsset->AssetCode = $strAssetCode; $objNewAsset->LocationId = $intLocationKeyArray[0]; $objNewAsset->AssetModelId = $intModelKeyArray[0]; if (isset($this->intCreatedByKey)) { if (isset($this->intUserArray[strtolower(trim($strRowArray[$this->intCreatedByKey]))])) { $objNewAsset->CreatedBy = $this->intUserArray[strtolower(trim($strRowArray[$this->intCreatedByKey]))]; } else { $objNewAsset->CreatedBy = $this->lstMapDefaultValueArray[$this->intCreatedByKey]->SelectedValue; } } $objNewAsset->Save();*/ $strCFVArray = array(); $objDatabase = CustomField::GetDatabase(); // Asset Custom Field import foreach ($arrAssetCustomField as $objCustomField) { if ($objCustomField->CustomFieldQtypeId != 2) { $strShortDescription = trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]])) : addslashes($this->txtMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text); $strCFVArray[$objCustomField->CustomFieldId] = $strShortDescription ? sprintf("'%s'", $strShortDescription) : "NULL"; /*$strQuery = sprintf("INSERT INTO `custom_field_value` " . "(`custom_field_id`,`short_description`, `created_by`, `creation_date`) " . "VALUES ('%s', '%s', '%s', 'NOW()');", $objCustomField->CustomFieldId, $strShortDescription, $_SESSION['intUserAccountId']); $objDatabase->NonQuery($strQuery); $this->strSelectedValueArray[] = sprintf("('%s', '%s', '%s')", $objNewAsset->AssetId, 1, $objDatabase->InsertId()); $strCFVArray[] = sprintf("`cfv_%s`='%s'", $objCustomField->CustomFieldId, $strShortDescription); $objCustomField->CustomFieldSelection = new CustomFieldSelection; $objCustomField->CustomFieldSelection->newCustomFieldValue = new CustomFieldValue; $objCustomField->CustomFieldSelection->newCustomFieldValue->CustomFieldId = $objCustomField->CustomFieldId; if (trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]])) { $objCustomField->CustomFieldSelection->newCustomFieldValue->ShortDescription = addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]])); } else { $objCustomField->CustomFieldSelection->newCustomFieldValue->ShortDescription = addslashes($this->txtMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text); } $objCustomField->CustomFieldSelection->newCustomFieldValue->Save(); $objCustomField->CustomFieldSelection->EntityId = $objNewAsset->AssetId; $objCustomField->CustomFieldSelection->EntityQtypeId = 1; $objCustomField->CustomFieldSelection->CustomFieldValueId = $objCustomField->CustomFieldSelection->newCustomFieldValue->CustomFieldValueId; $objCustomField->CustomFieldSelection->Save();*/ } else { $objDatabase = Asset::GetDatabase(); $strShortDescription = addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]])); $blnInList = false; foreach (CustomFieldValue::LoadArrayByCustomFieldId($objCustomField->CustomFieldId) as $objCustomFieldValue) { if (strtolower($objCustomFieldValue->ShortDescription) == strtolower($strShortDescription)) { //$intCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId; $blnInList = true; break; } } // Add the CustomFieldValue if (!$blnInList && !in_array($strShortDescription, $strAddedCFVArray)) { $strQuery = sprintf("INSERT INTO custom_field_value (custom_field_id, short_description, created_by, creation_date) VALUES (%s, '%s', %s, NOW());", $objCustomField->CustomFieldId, $strShortDescription, $_SESSION['intUserAccountId']); $objDatabase->NonQuery($strQuery); $strAddedCFVArray[] = $strShortDescription; } elseif (!$blnInList && $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) { //$intCustomFieldValueId = $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue; $strShortDescription = $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedName; } if ($strShortDescription) { //$this->strSelectedValueArray[] = sprintf("('%s', '%s', '%s')", $objNewAsset->AssetId, 1, $intCustomFieldValueId); //$strCFVArray[] = sprintf("`cfv_%s`='%s'", $objCustomField->CustomFieldId, $strShortDescription); $strCFVArray[$objCustomField->CustomFieldId] = sprintf("'%s'", $strShortDescription); } else { $strCFVArray[$objCustomField->CustomFieldId] = "NULL"; } } } $strAssetCodeArray[] = $strAssetCode; /*$this->objNewAssetArray[$objNewAsset->AssetId] = $objNewAsset->AssetCode; if (count($strCFVArray)) { $strQuery = sprintf("UPDATE `asset_custom_field_helper` " . "SET %s " . "WHERE `asset_id`='%s';", implode(", ", $strCFVArray), $objNewAsset->AssetId); $objDatabase->NonQuery($strQuery); }*/ if (count($strCFVArray)) { $strAssetCFVArray[] = implode(', ', $strCFVArray); } else { $strAssetCFVArray[] = ""; } } else { $this->intSkippedRecordCount++; $this->PutSkippedRecordInFile($file_skipped, $strRowArray); } } elseif ($strAssetCode && $this->lstImportAction->SelectedValue == 2 && $this->in_array_nocase($strAssetCode, $strAssetArray)) { $intLocationKeyArray = array_keys($intLocationArray, addslashes(strtolower(trim($strRowArray[$this->intLocationKey])))); if (isset($this->intCreatedByKey)) { if (isset($strRowArray[$this->intCreatedByKey]) && isset($this->intUserArray[strtolower(trim($strRowArray[$this->intCreatedByKey]))])) { $intCreatedBy = $this->intUserArray[strtolower(trim($strRowArray[$this->intCreatedByKey]))]; } else { $intCreatedBy = $this->lstMapDefaultValueArray[$this->intCreatedByKey]->SelectedValue; } } else { $intCreatedBy = false; } if (!count($intLocationKeyArray)) { $intLocationKeyArray = array_keys($intLocationArray, addslashes(strtolower(trim($this->txtMapDefaultValueArray[$this->intLocationKey]->Text)))); } $intModelKeyArray = array_keys($this->intAssetModelArray, $strAssetModel); if (count($intLocationKeyArray) && count($intModelKeyArray)) { $objAssetArray = Asset::LoadArrayBySearchHelper($strAssetCode, null, null, null, null, false, null, null, null, null, null, null, null, null, null, false, null, null, null, false, false, false); $objAsset = $objAssetArray[0]; $strUpdatedAssetArray[] = strtolower($strAssetCode); $strCategoryKeyArray = array_keys($intCategoryArray, addslashes(strtolower(trim($strRowArray[$this->intCategoryKey])))); // Only fields that can normally be updated when editing an asset can be updated //if ($objAsset->LocationId != $intLocationKeyArray[0] || $objAsset->AssetModel->CategoryId != $intCategoryId || $objAsset->AssetModel->ManufacturerId != $intManufacturerId) { if ($objAsset->LocationId != $intLocationKeyArray[0] || $objAsset->CreatedBy != false && $objAsset->CreatedBy != $intCreatedBy) { $this->intSkippedRecordCount++; $this->PutSkippedRecordInFile($file_skipped, $strRowArray); } else { $this->arrOldAssetArray[$objAsset->AssetId] = array(); $this->arrOldAssetArray[$objAsset->AssetId]['AssetModelId'] = $objAsset->AssetModelId; $this->arrOldAssetArray[$objAsset->AssetId]['ModifiedBy'] = $objAsset->ModifiedBy; $this->arrOldAssetArray[$objAsset->AssetId]['ModifiedDate'] = $objAsset->ModifiedDate; $this->arrOldAssetArray[$objAsset->AssetId]['CFV'] = array(); $objAsset->AssetModelId = $intModelKeyArray[0]; $objAssetValuesArray[] = $objAsset; //$objAssetValuesArray[] = sprintf("('%s', '%s', '%s', '%s', NOW())", $strAssetCode, $intLocationKeyArray[0], $intModelKeyArray[0], $_SESSION['intUserAccountId']); $strCFVArray = array(); $objDatabase = CustomField::GetDatabase(); // Asset Custom Field import foreach ($arrAssetCustomField as $objCustomField) { $this->arrOldAssetArray[$objAsset->AssetId]['CFV'][$objCustomField->CustomFieldId] = $objAsset->GetVirtualAttribute($objCustomField->CustomFieldId); if ($objCustomField->CustomFieldQtypeId != 2) { $strShortDescription = trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]])) : addslashes($this->txtMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text); $strCFVArray[$objCustomField->CustomFieldId] = $strShortDescription ? sprintf("'%s'", $strShortDescription) : "NULL"; } else { $objDatabase = Asset::GetDatabase(); $strShortDescription = addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]])); $strCFVArray[$objCustomField->CustomFieldId] = $strShortDescription ? sprintf("'%s'", $strShortDescription) : "NULL"; $blnInList = false; foreach (CustomFieldValue::LoadArrayByCustomFieldId($objCustomField->CustomFieldId) as $objCustomFieldValue) { if (strtolower($objCustomFieldValue->ShortDescription) == strtolower($strShortDescription)) { //$intCustomFieldValueId = $objCustomFieldValue->CustomFieldValueId; $blnInList = true; break; } } // Add the CustomFieldValue if (!$blnInList && !in_array($strShortDescription, $strAddedCFVArray)) { $strQuery = sprintf("INSERT INTO custom_field_value (custom_field_id, short_description, created_by, creation_date) VALUES (%s, '%s', %s, NOW());", $objCustomField->CustomFieldId, $strShortDescription, $_SESSION['intUserAccountId']); $objDatabase->NonQuery($strQuery); $strAddedCFVArray[] = $strShortDescription; } elseif (!$blnInList && $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) { //$intCustomFieldValueId = $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue; $strShortDescription = $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedName; } if ($strShortDescription) { $strCFVArray[$objCustomField->CustomFieldId] = sprintf("'%s'", $strShortDescription); } else { $strCFVArray[$objCustomField->CustomFieldId] = "NULL"; } } } $strAssetCodeArray[] = $strAssetCode; if (count($strCFVArray)) { $strUpdatedAssetCFVArray[$objAsset->AssetId] = $strCFVArray; } else { $strUpdatedAssetCFVArray[$objAsset->AssetId] = ""; } } } else { $this->intSkippedRecordCount++; $this->PutSkippedRecordInFile($file_skipped, $strRowArray); } } elseif ($this->lstImportAction->SelectedValue == 1 && $this->in_array_nocase($strAssetCode, $strAssetArray)) { // Skipped and flagged as duplicates $this->intSkippedRecordCount++; $this->PutSkippedRecordInFile($file_skipped, $strRowArray); } } } $intAssetCount = count($strAssetValuesArray); if ($intAssetCount) { $objDatabase = Asset::GetDatabase(); $strQuery = sprintf("INSERT INTO `asset` (`asset_code`, `location_id`, `asset_model_id`, `created_by`, `creation_date`) VALUES %s;", implode(", ", $strAssetValuesArray)); $objDatabase->NonQuery($strQuery); $intInsertId = $objDatabase->InsertId(); if ($intInsertId) { $strAssetIdArray = array(); for ($i = 0; $i < $intAssetCount; $i++) { $strAssetCFVArray[$i] = sprintf("('%s', %s)", $intInsertId + $i, $strAssetCFVArray[$i]); $strAssetIdArray[$i] = sprintf("(%s)", $intInsertId + $i); } $strCFVNameArray = array(); foreach ($arrAssetCustomField as $objCustomField) { $strCFVNameArray[] = sprintf("`cfv_%s`", $objCustomField->CustomFieldId); } if (count($strAssetCFVArray) > 0 && count($strCFVNameArray) > 0) { $strQuery = sprintf("INSERT INTO `asset_custom_field_helper` (`asset_id`, %s) VALUES %s", implode(", ", $strCFVNameArray), implode(", ", $strAssetCFVArray)); } else { $strQuery = sprintf("INSERT INTO `asset_custom_field_helper` (`asset_id`) VALUES %s", implode(", ", $strAssetIdArray)); } $objDatabase->NonQuery($strQuery); for ($i = 0; $i < $intAssetCount; $i++) { $this->objNewAssetArray[$intInsertId + $i] = $strAssetCodeArray[$i]; } } } $intObjAssetCount = count($objAssetValuesArray); if ($intObjAssetCount) { $objDatabase = Asset::GetDatabase(); foreach ($objAssetValuesArray as $objAsset) { $this->objUpdatedAssetArray[$objAsset->AssetId] = $objAsset->AssetCode; if (count($strUpdatedAssetCFVArray[$objAsset->AssetId])) { $strCFVArray = array(); foreach ($arrAssetCustomField as $objCustomField) { $strCFVArray[] = sprintf("`cfv_%s`=%s", $objCustomField->CustomFieldId, $strUpdatedAssetCFVArray[$objAsset->AssetId][$objCustomField->CustomFieldId]); } if (count($strCFVArray)) { $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", implode(", ", $strCFVArray), $objAsset->AssetId); $objDatabase->NonQuery($strQuery); } } $objAsset->Save(); } } $this->intCurrentFile++; break; } //$j++; } if ($this->intImportStep == 6) { /*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`));")); // Insert into category_custom_field_helper $objDatabase->NonQuery(sprintf("INSERT INTO `category_custom_field_helper` (`category_id`) (SELECT `category_id` FROM `category` WHERE `category_id` NOT IN (SELECT `category_id` FROM `category_custom_field_helper`));")); // Insert into manufacturer_custom_field_helper $objDatabase->NonQuery(sprintf("INSERT INTO `manufacturer_custom_field_helper` (`manufacturer_id`) (SELECT `manufacturer_id` FROM `manufacturer` WHERE `manufacturer_id` NOT IN (SELECT `manufacturer_id` FROM `manufacturer_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; } if (count($this->objNewManufacturerArray)) { $this->lblImportManufacturers->Display = true; $this->dtgManufacturer->Paginator = new QPaginator($this->dtgManufacturer); $this->dtgManufacturer->ItemsPerPage = 20; } if (count($this->objNewCategoryArray)) { $this->lblImportCategories->Display = true; $this->dtgCategory->Paginator = new QPaginator($this->dtgCategory); $this->dtgCategory->ItemsPerPage = 20; } if (count($this->objNewLocationArray)) { $this->lblImportLocations->Display = true; $this->dtgLocation->Paginator = new QPaginator($this->dtgLocation); $this->dtgLocation->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->objNewAssetArray) + count($this->objUpdatedAssetArray), $this->intSkippedRecordCount); if ($this->intSkippedRecordCount) { $this->lblImportSuccess->Text .= sprintf("<a href='./asset_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++; } } }
`%s` AS `%s` %s WHERE 1=1 ', $strTableName, $strTableName, $strTableName, $arrCustomFieldSql['strSelect'], $strTableName, $strTableName, $arrCustomFieldSql['strFrom']); $objDatabase = QApplication::$Database[1]; $objDbResult = $objDatabase->Query($strQuery); switch ($intEntityQtypeId) { case 1: $objArray = Asset::InstantiateDbResult($objDbResult); break; case 2: $objArray = InventoryModel::InstantiateDbResult($objDbResult); break; case 4: $objArray = AssetModel::InstantiateDbResult($objDbResult); break; case 5: $objArray = Manufacturer::InstantiateDbResult($objDbResult); break; case 6: $objArray = Category::InstantiateDbResult($objDbResult); break; case 7: $objArray = Company::InstantiateDbResult($objDbResult); break; case 8: $objArray = Contact::InstantiateDbResult($objDbResult); break; case 9: $objArray = Address::InstantiateDbResult($objDbResult);
/** * Add the tag admin page CSS. * * @param AssetModel $sender */ public function assetModel_adminCss_handler($sender) { $sender->addCssFile('tagadmin.css', 'plugins/Tagging'); }
/** * Counts all associated AssetModels * @return int */ public function CountAssetModels() { if (is_null($this->intManufacturerId)) { return 0; } return AssetModel::CountByManufacturerId($this->intManufacturerId); }
public function btnAssetModelSearchToolAdd_Click() { $this->ctlAssetModelSearchTool->lblWarning->Text = ""; $intSelectedAssetModelId = $this->ctlAssetModelSearchTool->ctlAssetModelSearch->dtgAssetModel->GetSelected("AssetModelId"); if (count($intSelectedAssetModelId) < 1) { $this->ctlAssetModelSearchTool->lblWarning->Text = "No selected models."; } else { $lblNewWarning = ""; foreach (AssetModel::QueryArray(QQ::In(QQN::AssetModel()->AssetModelId, $intSelectedAssetModelId)) as $objNewAssetModel) { $blnExists = false; foreach ($this->arrAssetModels as $objAssetModel) { if ($objAssetModel->AssetModelId == $objNewAssetModel->AssetModelId) { $blnExists = true; } } if ($blnExists) { $lblNewWarning .= sprintf("<br />%s - already in list", $objNewAssetModel->AssetModelCode); } else { $objAssetModelToAdd = new AssetCustomFieldAssetModel(); $objAssetModelToAdd->AssetModelId = $objNewAssetModel->AssetModelId; $objAssetModelToAdd->CustomFieldId = $this->objCustomField->CustomFieldId; array_push($this->arrAssetModels, $objAssetModelToAdd); } } $this->lstAddAssetModel->Warning = $lblNewWarning; $this->ctlAssetModelSearchTool->dlgAssetModelSearchTool->HideDialogBox(); } // Uncheck all items but SelectAll checkbox $this->UncheckAllItems(); $this->dtgAssetModels->Refresh(); }
protected function dtgAssetModel_Bind() { if ($this->blnSearch) { $this->assignSearchValues(); } $intCategoryId = $this->intCategoryId; $intManufacturerId = $this->intManufacturerId; $strDescription = $this->strDescription; $strAssetModelCode = $this->strAssetModelCode; $arrCustomFields = $this->arrCustomFields; $strDateModifiedFirst = $this->strDateModifiedFirst; $strDateModifiedLast = $this->strDateModifiedLast; $strDateModified = $this->strDateModified; $blnAttachment = $this->blnAttachment; $objExpansionMap[AssetModel::ExpandCategory] = true; $objExpansionMap[AssetModel::ExpandManufacturer] = true; // If the search form has been posted // if ($intCategoryId || $intManufacturerId || $strDescription || $strAssetModelCode) { $this->dtgAssetModel->TotalItemCount = AssetModel::CountBySearch($intCategoryId, $intManufacturerId, $strDescription, $strAssetModelCode, $arrCustomFields, $strDateModified, $strDateModifiedFirst, $strDateModifiedLast, $blnAttachment, $objExpansionMap); $this->dtgAssetModel->DataSource = AssetModel::LoadArrayBySearch($intCategoryId, $intManufacturerId, $strDescription, $strAssetModelCode, $arrCustomFields, $strDateModified, $strDateModifiedFirst, $strDateModifiedLast, $blnAttachment, $this->dtgAssetModel->SortInfo, $this->dtgAssetModel->LimitInfo, $objExpansionMap); $this->blnSearch = false; }
protected function btnNext_Click() { $blnError = false; $this->btnNext->Warning = ''; 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_%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; $this->intTotalCount -= $this->chkHeaderRow->Checked ? 1 : 0; if ($this->lstImportAction->SelectedValue == 1 && $this->intAssetLimit != null && $this->intAssetLimit < $this->intTotalCount + $this->intAssetCount) { $blnError = true; $this->btnNext->Warning = sprintf('This import of %s assets would exceed your limit of %s assets.', $this->intTotalCount, $this->intAssetLimit); } 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 $blnRequiredAllAssetCustomFields = true; $blnError = false; $blnAssetCode = false; $blnAssetModelShortDescription = false; $blnLocation = false; $blnAssetId = false; // $array Required Custom Fields for All Asset Models $arrAssetCustomFieldOptions = EntityQtypeCustomField::LoadArrayByEntityQtypeId(QApplication::Translate(EntityQtype::Asset)); // generate error flag and field names which are required for export; $arrRequiredAllAssetCustomFields = array(); foreach ($arrAssetCustomFieldOptions as $arrAssetCustomFieldOption) { if ($arrAssetCustomFieldOption->CustomField->RequiredFlag && $arrAssetCustomFieldOption->CustomField->ActiveFlag && $arrAssetCustomFieldOption->CustomField->AllAssetModelsFlag) { $arrRequiredAllAssetCustomFields[] = $arrAssetCustomFieldOption->CustomField->ShortDescription; if (!in_array($arrAssetCustomFieldOption->CustomField->ShortDescription, $this->getLstKeys())) { $blnRequiredAllAssetCustomFields = 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 == "model") { $blnAssetModelShortDescription = true; } elseif ($strSelectedValue == "asset tag") { $blnAssetCode = true; } elseif ($strSelectedValue == "location") { $blnLocation = true; } elseif ($strSelectedValue == "id") { $blnAssetId = 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."; break; } else { $blnError = false; $txtDefault->Warning = ""; } } } // If all required fields have no errors if (!$blnError && $blnRequiredAllAssetCustomFields && $blnAssetCode && $blnAssetModelShortDescription && $blnLocation && ($this->lstImportAction->SelectedValue != 2 || $blnAssetId)) { $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; } else*/ if ($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->objNewAssetArray = array(); $this->strAssetValuesArray = 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->dtgAsset = new QDataGrid($this); $this->dtgAsset->Name = 'asset_list'; $this->dtgAsset->CellPadding = 5; $this->dtgAsset->CellSpacing = 0; $this->dtgAsset->CssClass = "datagrid"; $this->dtgAsset->UseAjax = true; $this->dtgAsset->ShowColumnToggle = false; $this->dtgAsset->ShowExportCsv = false; $this->dtgAsset->ShowHeader = false; $this->dtgAsset->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 Assets"; $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 { $strRequiredAllAssetCustomFields = ''; if (count($arrRequiredAllAssetCustomFields) > 0) { $strRequiredAllAssetCustomFields = implode(", ", $arrRequiredAllAssetCustomFields) . ", "; } $this->btnNext->Warning = "You must select all required fields (" . $strRequiredAllAssetCustomFields . "Asset Tag, Model Short Description and Location)."; $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 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); }*/ $intAssetCustomFieldKeyArray = array(); $arrAssetCustomField = array(); // Setup keys foreach ($this->arrTracmorField as $key => $value) { if ($value == 'asset tag') { $intAssetCodeKey = $key; } elseif ($value == 'model') { $intAssetModelDescriptionKey = $key; } elseif ($value == 'location') { $intLocationKey = $key; } elseif ($value == 'parent asset') { $intParentAssetKey = $key; } elseif ($value == 'locked to parent') { $intLinkedKey = $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)]; } } elseif (QApplication::$TracmorSettings->DepreciationFlag == '1' && $value == "depreciate asset") { $this->intDepreciationFlagKey = $key; } elseif (QApplication::$TracmorSettings->DepreciationFlag == '1' && $value == "purchase cost") { $this->intPurchaseCostKey = $key; } elseif (QApplication::$TracmorSettings->DepreciationFlag == '1' && $value == "purchase date") { $this->intPurchaseDateKey = $key; } } $intAssetModelArray = array(); $strItemCFVArray = array(); $strUpdatedItemCFVArray = array(); $strUpdatedValuesArray = array(); $this->arrOldItemArray = array(); $this->objUpdatedItemArray = array(); // Load all asset models foreach (AssetModel::LoadAllIntoArray() as $arrAssetModel) { //$strAssetModelArray[] = strtolower(sprintf("%s_%s_%s_%s", addslashes($arrAssetModel['model_code']), addslashes($arrAssetModel['short_description']), $arrAssetModel['category_id'], $arrAssetModel['manufacturer_id'])); $intAssetModelArray[$arrAssetModel['asset_model_id']] = strtolower($arrAssetModel['short_description']); } $intLocationArray = array(); // Load all locations with keys=location_id foreach (Location::LoadAll() as $objLocation) { $intLocationArray[$objLocation->LocationId] = strtolower($objLocation->ShortDescription); } // Depreciation /*if(QApplication::$TracmorSettings->DepreciationFlag == '1'){ foreach (DepreciationClass::LoadAll() as $objDepreciationClass){ $this->intDepreciationClassArray[$objDepreciationClass->DepreciationClassId] = strtolower($objDepreciationClass->ShortDescription); } }*/ $strAssetArray = array(); // Load all assets // Loads array of AssetModelId $arrAssetArray = Asset::LoadAllIntoArray(); $arrAssetId = array(); if (count($arrAssetArray)) { foreach ($arrAssetArray as $arrAsset) { $arrAssetId[$arrAsset['asset_id']] = addslashes(strtolower($arrAsset['asset_code'])); $strAssetArray[] = addslashes(strtolower($arrAsset['asset_code'])); } } } 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) { $strAssetCFVArray = array(); $objNewAssetArray = array(); for ($i = 0; $i < $this->FileCsvData->countRows(); $i++) { $strRowArray = $this->FileCsvData->getRow($i); $strAssetCode = trim($strRowArray[$intAssetCodeKey]) ? addslashes(trim($strRowArray[$intAssetCodeKey])) : false; //$strAssetCode = (trim($strRowArray[$intAssetCodeKey])) ? trim($strRowArray[$intAssetCodeKey]) : false; $strKeyArray = array_keys($intLocationArray, isset($strRowArray[$intLocationKey]) ? strtolower(trim($strRowArray[$intLocationKey])) : array()); if (count($strKeyArray)) { $intLocationId = $strKeyArray[0]; } else { $strKeyArray = array_keys($intLocationArray, strtolower(trim($this->txtMapDefaultValueArray[$intLocationKey]->Text))); if (count($strKeyArray)) { $intLocationId = $strKeyArray[0]; } else { $intLocationId = false; } } $strKeyArray = array_keys($intAssetModelArray, isset($strRowArray[$intAssetModelDescriptionKey]) ? strtolower(trim($strRowArray[$intAssetModelDescriptionKey])) : array()); if (count($strKeyArray)) { $intAssetModelId = $strKeyArray[0]; } else { $strKeyArray = array_keys($intAssetModelArray, strtolower(trim($this->txtMapDefaultValueArray[$intAssetModelDescriptionKey]->Text))); if (count($strKeyArray)) { $intAssetModelId = $strKeyArray[0]; } else { $intAssetModelId = false; } } $blnError = false; // Skip records with not filled required custom fields $log = ''; if ($intAssetModelId) { foreach ($intAssetCustomFieldKeyArray as $k => $v) { $log .= 'k' . $k . '=' . $v; } // Load Specific asset model custom field $arrRequiredSpecificAssetCustomFields = AssetCustomFieldAssetModel::LoadArrayByAssetModelId($intAssetModelId); foreach ($arrRequiredSpecificAssetCustomFields as $objRequiredCustomField) { if ($objRequiredCustomField->CustomField->RequiredFlag) { $log .= $objRequiredCustomField->CustomField->CustomFieldId; if (!array_key_exists($objRequiredCustomField->CustomField->CustomFieldId, $intAssetCustomFieldKeyArray) || empty($strRowArray[array_search($objRequiredCustomField->CustomField->CustomFieldId, $intAssetCustomFieldKeyArray)])) { $blnError = true; $this->intImportStep = 3; // $log .= "<h1>".$objRequiredCustomField->CustomField->ShortDescription.$objRequiredCustomField->CustomField->CustomFieldId." is empty</h1>"; } } } } //print $log; exit; if (!$blnError) { if (isset($intParentAssetKey) && isset($strRowArray[$intParentAssetKey])) { $strKeyArray = array_keys($arrAssetId, strtolower(trim($strRowArray[$intParentAssetKey]))); if (count($strKeyArray)) { $intParentAssetId = $strKeyArray[0]; } else { $strKeyArray = array_keys($arrAssetId, strtolower(trim($this->txtMapDefaultValueArray[$intParentAssetKey]->Text))); if (count($strKeyArray)) { $intParentAssetId = $strKeyArray[0]; } else { $intParentAssetId = null; $blnError = true; } } if (!$intParentAssetId || $strRowArray[$intParentAssetKey] == $strAssetCode) { $blnError = true; } $blnLinked = $intParentAssetId && isset($intLinkedKey) && strlen(trim($strRowArray[$intLinkedKey])) > 0 ? 1 : 0; } else { $intParentAssetId = null; $blnLinked = 0; } } /*$strKeyArray = array_keys($intCategoryArray, strtolower(trim($strRowArray[$this->intCategoryKey]))); 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, strtolower(trim($strRowArray[$this->intManufacturerKey]))); 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; } }*/ // If depreciation is enabled within Application // Any non-empty value sets to 1 $blnDepreciationError = false; $blnDepreciationFlag = null; $intPurchaseCost = null; $dttPurchaseDate = null; if (QApplication::$TracmorSettings->DepreciationFlag == '1' && $this->intDepreciationFlagKey && strlen(trim($strRowArray[$this->intDepreciationFlagKey]))) { // Verify that the model has a depreciation class assigned if ($intAssetModelId > 0 && AssetModel::Load($intAssetModelId)->DepreciationClassId) { // Verify that purchase date and purchase cost are set and valid if (isset($this->intPurchaseCostKey) && isset($this->intPurchaseDateKey)) { // Check intVal for Purchase cost $intPurchaseCost = trim($strRowArray[$this->intPurchaseCostKey]) ? addslashes(trim($strRowArray[$this->intPurchaseCostKey])) : false; if (!is_numeric($intPurchaseCost)) { $blnDepreciationError = true; } $strPurchaseDate = trim($strRowArray[$this->intPurchaseDateKey]); $dttPurchaseDate = new DateTime(); // Check isDate for Purchase date if (!strlen($strPurchaseDate) || !($dttPurchaseDate = $dttPurchaseDate->setTimestamp(strtotime($strPurchaseDate)))) { $blnDepreciationError = true; } else { $dttPurchaseDate = $dttPurchaseDate->format('Y-m-d'); } $blnDepreciationFlag = 1; } else { $blnDepreciationError = true; } } else { $blnDepreciationError = true; } } $objAsset = false; if (!$strAssetCode || $blnError || $intAssetModelId === false || $intLocationId === false || $blnDepreciationError) { //$blnError = true; //echo sprintf("Desc: %s AssetCode: %s Cat: %s Man: %s<br/>", $strAssetCode, $strLocation, $intCategoryId, $intManufacturerId); $strAssetCode = null; $this->intSkippedRecordCount++; $this->PutSkippedRecordInFile($file_skipped, $strRowArray); continue; } else { if ($this->lstImportAction->SelectedValue == 2) { $intItemId = intval(trim($strRowArray[$this->intItemIdKey])); if ($intItemId > 0 && array_key_exists($intItemId, $arrAssetId)) { //QApplication::$Database[1]->EnableProfiling(); $objAssetArray = Asset::LoadArrayBySearchHelper(null, null, null, null, null, false, null, null, null, null, null, null, null, null, null, false, null, null, null, false, false, false, null, null, false, $intItemId); //QApplication::$Database[1]->OutputProfiling(); if ($objAssetArray) { $objAsset = $objAssetArray[0]; } } } else { $intItemId = 0; } } if ($strAssetCode && !$intItemId && !$this->in_array_nocase($strAssetCode, $strAssetArray)) { // Custom Fields Section $strCFVArray = array(); $objDatabase = CustomField::GetDatabase(); $blnCheckCFVError = false; // Asset Model Custom Field import foreach ($arrAssetCustomField as $objCustomField) { if ($objCustomField->CustomFieldQtypeId != 2) { $strCSDescription = isset($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) : ""; $strCSDescription = strlen($strCSDescription) > 0 ? addslashes($strCSDescription) : addslashes($this->txtMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text); $strCFVArray[$objCustomField->CustomFieldId] = strlen($strCSDescription) > 0 ? sprintf("'%s'", $strCSDescription) : "NULL"; } else { $objDatabase = Asset::GetDatabase(); $strCSDescription = isset($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$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[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) { $strCSDescription = $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedName; } elseif (!$blnInList) { $blnCheckCFVError = true; break; } if (!$blnCheckCFVError) { if ($strCSDescription) { $strCFVArray[$objCustomField->CustomFieldId] = sprintf("'%s'", $strCSDescription); } else { $strCFVArray[$objCustomField->CustomFieldId] = "NULL"; } } } } // Check if asset limit has been reached $blnAssetLimitError = $this->intAssetLimit != null && $this->intAssetCount + count($objNewAssetArray) >= $this->intAssetLimit; if (!$blnCheckCFVError && !$blnAssetLimitError) { $strAssetArray[] = stripslashes($strAssetCode); $this->strAssetValuesArray[] = sprintf("('%s', '%s', '%s', %s, %s, '%s', NOW(), %s, %s, %s)", $strAssetCode, $intLocationId, $intAssetModelId, $intParentAssetId ? $intParentAssetId : "NULL", $blnLinked ? "1" : "0", $_SESSION['intUserAccountId'], $blnDepreciationFlag ? $blnDepreciationFlag : "NULL", $intPurchaseCost ? $intPurchaseCost : "NULL", $dttPurchaseDate ? '"' . $dttPurchaseDate . '"' : "NULL"); $objNewAssetArray[] = stripslashes($strAssetCode); if (isset($strCFVArray) && count($strCFVArray)) { $strAssetCFVArray[] = str_replace('""', '"', implode(', ', $strCFVArray)); /*if ($j == 2) { echo "strAssetCFVArray: "; print_r($strAssetCFVArray); echo "strCFVArray: "; print_r($strCFVArray); exit; }*/ } else { $strAssetCFVArray[] = ""; } } else { $this->intSkippedRecordCount++; if ($blnAssetLimitError) { $strRowArray[] = sprintf('Asset limit of %s reached', $this->intAssetLimit); } $this->PutSkippedRecordInFile($file_skipped, $strRowArray); $strAssetCode = null; } } elseif ($strAssetCode && $this->lstImportAction->SelectedValue == 2 && $objAsset) { // Import Action is "Create and Update Records" $strUpdateFieldArray = array(); $strUpdateFieldArray[] = sprintf("`asset_code`='%s'", $strAssetCode); $strUpdateFieldArray[] = sprintf("`asset_model_id`='%s'", $intAssetModelId); $strUpdateFieldArray[] = sprintf("`parent_asset_id`=%s", QApplication::$Database[1]->SqlVariable($intParentAssetId)); $strUpdateFieldArray[] = sprintf("`linked_flag`=b'%s'", $blnLinked ? 1 : 0); $strUpdateFieldArray[] = sprintf("`modified_by`='%s'", $_SESSION['intUserAccountId']); // Depreciation Fields $strUpdateFieldArray[] = sprintf("`depreciation_flag`=%s", $blnDepreciationFlag ? $blnDepreciationFlag : "NULL"); $strUpdateFieldArray[] = sprintf("`purchase_cost`=%s", $intPurchaseCost ? $intPurchaseCost : "NULL"); $strUpdateFieldArray[] = sprintf("`purchase_date`=%s", $dttPurchaseDate ? "'{$dttPurchaseDate}'" : "NULL"); $blnCheckCFVError = false; foreach ($arrAssetCustomField as $objCustomField) { if ($objCustomField->CustomFieldQtypeId != 2) { $strCSDescription = isset($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? trim($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) : ""; $strCSDescription = strlen($strCSDescription) > 0 ? addslashes($strCSDescription) : addslashes($this->txtMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->Text); $strCFVArray[$objCustomField->CustomFieldId] = strlen($strCSDescription) > 0 ? sprintf("'%s'", $strCSDescription) : "NULL"; } else { $objDatabase = CustomField::GetDatabase(); $strCSDescription = isset($strRowArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]) ? addslashes(trim($strRowArray[$intAssetCustomFieldKeyArray[$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[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedValue != null) { $strCSDescription = $this->lstMapDefaultValueArray[$intAssetCustomFieldKeyArray[$objCustomField->CustomFieldId]]->SelectedName; } elseif (!$blnInList) { $blnCheckCFVError = true; break; } if (!$blnCheckCFVError) { if ($strCSDescription) { $strCFVArray[$objCustomField->CustomFieldId] = sprintf("'%s'", $strCSDescription); } else { $strCFVArray[$objCustomField->CustomFieldId] = "NULL"; } } } } // The user can not change location if ($intLocationId != $objAsset->LocationId) { $blnCheckCFVError = true; } if (!$blnCheckCFVError) { $strUpdatedValuesArray[] = sprintf("UPDATE `asset` SET %s WHERE `asset_id`='%s'", str_replace('""', '"', implode(", ", $strUpdateFieldArray)), $objAsset->AssetId); if (isset($strCFVArray) && count($strCFVArray)) { $strUpdatedItemCFVArray[$objAsset->AssetId] = $strCFVArray; } else { $strUpdatedItemCFVArray[$objAsset->AssetId] = ""; } $this->objUpdatedItemArray[$objAsset->AssetId] = sprintf("%s", $objAsset->AssetCode); //$this->arrOldItemArray[$objAsset->AssetId] = $objAsset; //$strItemQuery = sprintf("UPDATE `asset` SET `asset_code`='%s', `asset_model_id`='%s', `parent_asset_id`=%s, `linked_flag`='%s', `modified_by`=%s, `modified_date`=%s WHERE `asset_id`='%s'", $objAsset->AssetCode, $objAsset->AssetModelId, (!$objAsset->ParentAssetId) ? "NULL" : $objAsset->ParentAssetId, $objAsset->LinkedFlag, (!$objAsset->ModifiedBy) ? "NULL" : $objAsset->ModifiedBy, (!$objAsset->ModifiedBy) ? "NULL" : sprintf("'%s'", $objAsset->ModifiedDate), $objAsset->AssetId); $strItemQuery = sprintf("UPDATE `asset` SET `asset_code`='%s', `asset_model_id`='%s', `parent_asset_id`=%s, `linked_flag`='%s', `modified_by`=%s, `modified_date`=%s, `depreciation_flag`=%s, `purchase_cost`=%s, `purchase_date`=%s WHERE `asset_id`='%s'", $objAsset->AssetCode, $objAsset->AssetModelId, !$objAsset->ParentAssetId ? "NULL" : $objAsset->ParentAssetId, $objAsset->LinkedFlag, !$objAsset->ModifiedBy ? "NULL" : $objAsset->ModifiedBy, !$objAsset->ModifiedBy ? "NULL" : sprintf("'%s'", $objAsset->ModifiedDate), $blnDepreciationFlag ? $blnDepreciationFlag : "NULL", $intPurchaseCost ? $intPurchaseCost : "NULL", $dttPurchaseDate ? '"' . $dttPurchaseDate . '"' : "NULL", $objAsset->AssetId); $strCFVArray = array(); foreach ($this->arrAssetCustomField as $objCustomField) { $strCFV = $objAsset->GetVirtualAttribute($objCustomField->CustomFieldId); $strCFVArray[] = sprintf("`cfv_%s`='%s'", $objCustomField->CustomFieldId, $strCFV); } // Update values for custom field set not allowed to model $arrToClear = $this->substactNotAllowedFields($objAsset->AssetModelId, null); foreach ($arrToClear as $idToBeNull) { $strCFVArray[] = sprintf("`cfv_%s`= NULL", $idToBeNull); } if (isset($strCFVArray) && count($strCFVArray)) { $strCFVQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", str_replace('""', '"', implode(", ", $strCFVArray)), $intItemId); } else { $strCFVQuery = false; } $this->arrOldItemArray[$objAsset->AssetId] = array("ItemSql" => $strItemQuery, "CFVSql" => $strCFVQuery); } } else { // If Import Action is "Create Records" and this Asset has already in the database /*elseif ($this->lstImportAction->SelectedValue == 1 && $this->in_array_nocase($strAssetCode, $strAssetArray)) { // Skipped and flagged as duplicates $this->intSkippedRecordCount++; $this->PutSkippedRecordInFile($file_skipped, $strRowArray); }*/ $this->intSkippedRecordCount++; $this->PutSkippedRecordInFile($file_skipped, $strRowArray); } } //if ($this->intCurrentFile == count($this->strFilePathArray)) { // Inserts if (count($this->strAssetValuesArray)) { $objDatabase = Asset::GetDatabase(); //var_dump($this->strAssetValuesArray); //exit(); // $objDatabase->NonQuery(sprintf("INSERT INTO `asset` (`asset_code`, `location_id`, `asset_model_id`, `parent_asset_id`, `linked_flag`, `created_by`, `creation_date`) VALUES %s;", str_replace('""','"',implode(", ", $this->strAssetValuesArray)))); $objDatabase->NonQuery(sprintf("INSERT INTO `asset` (`asset_code`, `location_id`, `asset_model_id`, `parent_asset_id`, `linked_flag`, `created_by`, `creation_date`, `depreciation_flag`, `purchase_cost`, `purchase_date` ) VALUES %s;", str_replace('""', '"', implode(", ", $this->strAssetValuesArray)))); $intInsertId = $objDatabase->InsertId(); if ($intInsertId) { $strAssetIdArray = array(); $strCFVArray = array(); for ($i = 0; $i < count($objNewAssetArray); $i++) { $this->objNewAssetArray[$intInsertId + $i] = $objNewAssetArray[$i]; $strCFVArray[$i] = sprintf("('%s', %s)", $intInsertId + $i, $strAssetCFVArray[$i]); $strAssetIdArray[$i] = sprintf("(%s)", $intInsertId + $i); } /*if ($j == 1) { echo "strCFVArray: "; print_r($strCFVArray); echo "strAssetCFVArray: "; print_r($strAssetCFVArray); exit; }*/ $strCFVNameArray = array(); foreach ($arrAssetCustomField as $objCustomField) { $strCFVNameArray[] = sprintf("`cfv_%s`", $objCustomField->CustomFieldId); } if (count($strAssetCFVArray) > 0 && count($strCFVNameArray) > 0) { $strQuery = sprintf("INSERT INTO `asset_custom_field_helper` (`asset_id`, %s) VALUES %s", str_replace('""', '"', implode(", ", $strCFVNameArray)), str_replace('""', '"', implode(", ", $strCFVArray))); } else { $strQuery = sprintf("INSERT INTO `asset_custom_field_helper` (`asset_id`) VALUES %s", str_replace('""', '"', implode(", ", $strAssetIdArray))); } $objDatabase->NonQuery($strQuery); $theAsset = Asset::Load($intInsertId); $strQuery = $this->substactNotAllowedFields($theAsset->AssetModelId, $theAsset->AssetId); if (!empty($strQuery)) { //$objDatabase->NonQuery($this->substactNotAllowedFields($theAsset->AssetModelId,$theAsset->AssetId)); $objDatabase->NonQuery($strQuery); } } $this->strAssetValuesArray = array(); } // Updates if (count($strUpdatedValuesArray)) { $objDatabase = Asset::GetDatabase(); foreach ($strUpdatedValuesArray as $query) { $objDatabase->NonQuery($query); } foreach ($this->objUpdatedItemArray as $intItemKey => $objUpdatedItem) { if (isset($strUpdatedItemCFVArray[$intItemKey]) && count($strUpdatedItemCFVArray[$intItemKey])) { $strCFVArray = array(); foreach ($arrAssetCustomField as $objCustomField) { $strCFVArray[] = sprintf("`cfv_%s`=%s", $objCustomField->CustomFieldId, $strUpdatedItemCFVArray[$intItemKey][$objCustomField->CustomFieldId]); } if (isset($strCFVArray) && count($strCFVArray)) { $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET %s WHERE `asset_id`='%s'", str_replace('""', '"', implode(", ", $strCFVArray)), $intItemKey); $objDatabase->NonQuery($strQuery); // insert nulls where not allowed $theAsset = Asset::Load($intItemKey); $strQuery = $this->substactNotAllowedFields($theAsset->AssetModelId, $theAsset->AssetId); if ($strQuery) { $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_custom_field_helper $objDatabase->NonQuery(sprintf("INSERT INTO `asset_custom_field_helper` (`asset_id`) (SELECT `asset_id` FROM `asset` WHERE `asset_id` NOT IN (SELECT `asset_id` FROM `asset_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->objNewAssetArray)) { $this->lblImportAsset->Display = true; $this->dtgAsset->Paginator = new QPaginator($this->dtgAsset); $this->dtgAsset->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->objNewAssetArray) + count($this->objUpdatedItemArray), $this->intSkippedRecordCount); if ($this->intSkippedRecordCount) { $this->lblImportSuccess->Text .= sprintf("<a href='./asset_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) { $this->btnNext->Warning = "Please wait..."; QApplication::ExecuteJavaScript("document.getElementById('" . $this->btnNext->ControlId . "').click();"); } if (!($this->intCurrentFile < count($this->strFilePathArray))) { $this->intCurrentFile = 0; $this->intImportStep++; } } }
/** * Refresh this MetaControl with Data from the local AssetModelCustomFieldHelper object. * @param boolean $blnReload reload AssetModelCustomFieldHelper from the database * @return void */ public function Refresh($blnReload = false) { if ($blnReload) { $this->objAssetModelCustomFieldHelper->Reload(); } if ($this->lstAssetModel) { $this->lstAssetModel->RemoveAllItems(); if (!$this->blnEditMode) { $this->lstAssetModel->AddItem(QApplication::Translate('- Select One -'), null); } $objAssetModelArray = AssetModel::LoadAll(); if ($objAssetModelArray) { foreach ($objAssetModelArray as $objAssetModel) { $objListItem = new QListItem($objAssetModel->__toString(), $objAssetModel->AssetModelId); if ($this->objAssetModelCustomFieldHelper->AssetModel && $this->objAssetModelCustomFieldHelper->AssetModel->AssetModelId == $objAssetModel->AssetModelId) { $objListItem->Selected = true; } $this->lstAssetModel->AddItem($objListItem); } } } if ($this->lblAssetModelId) { $this->lblAssetModelId->Text = $this->objAssetModelCustomFieldHelper->AssetModel ? $this->objAssetModelCustomFieldHelper->AssetModel->__toString() : null; } }
/** * Gather all of the global styles together. * @param string $Filename * @since 2.1 */ public function Css($Basename, $Revision) { $AssetModel = new AssetModel(); $AssetModel->ServeCss($Basename, $Revision); }
protected function lstAssetModel_Create() { $this->lstAssetModel = new QListBox($this); $this->lstAssetModel->Name = QApplication::Translate('Asset Model'); $this->lstAssetModel->Required = true; if (!$this->blnEditMode) { $this->lstAssetModel->AddItem(QApplication::Translate('- Select One -'), null); } $objAssetModelArray = AssetModel::LoadAll(); if ($objAssetModelArray) { foreach ($objAssetModelArray as $objAssetModel) { $objListItem = new QListItem($objAssetModel->__toString(), $objAssetModel->AssetModelId); if ($this->objAsset->AssetModel && $this->objAsset->AssetModel->AssetModelId == $objAssetModel->AssetModelId) { $objListItem->Selected = true; } $this->lstAssetModel->AddItem($objListItem); } } }
public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects) { if ($objObject->objAssetModel) { $objObject->objAssetModel = AssetModel::GetSoapObjectFromObject($objObject->objAssetModel, false); } else { if (!$blnBindRelatedObjects) { $objObject->intAssetModelId = null; } } if ($objObject->objLocation) { $objObject->objLocation = Location::GetSoapObjectFromObject($objObject->objLocation, false); } else { if (!$blnBindRelatedObjects) { $objObject->intLocationId = 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; }
/** * Undocumented method. * * @todo Method RenderMaster() needs a description. */ public function RenderMaster() { // Build the master view if necessary if (in_array($this->_DeliveryType, array(DELIVERY_TYPE_ALL))) { $this->MasterView = $this->MasterView(); // Only get css & ui components if this is NOT a syndication request if ($this->SyndicationMethod == SYNDICATION_NONE && is_object($this->Head)) { // if (ArrayHasValue($this->_CssFiles, 'style.css')) { // $this->AddCssFile('custom.css'); // // // Add the theme option's css file. // if ($this->Theme && $this->ThemeOptions) { // $Filenames = GetValueR('Styles.Value', $this->ThemeOptions); // if (is_string($Filenames) && $Filenames != '%s') // $this->_CssFiles[] = array('FileName' => ChangeBasename('custom.css', $Filenames), 'AppFolder' => FALSE, 'Options' => FALSE); // } // } elseif (ArrayHasValue($this->_CssFiles, 'admin.css')) { // $this->AddCssFile('customadmin.css'); // } $this->EventArguments['CssFiles'] =& $this->_CssFiles; $this->FireEvent('BeforeAddCss'); $ETag = AssetModel::ETag(); $CombineAssets = C('Garden.CombineAssets'); $ThemeType = IsMobile() ? 'mobile' : 'desktop'; // And now search for/add all css files. foreach ($this->_CssFiles as $CssInfo) { $CssFile = $CssInfo['FileName']; // style.css and admin.css deserve some custom processing. if (in_array($CssFile, array('style.css', 'admin.css'))) { if (!$CombineAssets) { // Grab all of the css files from the asset model. $AssetModel = new AssetModel(); $CssFiles = $AssetModel->GetCssFiles($ThemeType, ucfirst(substr($CssFile, 0, -4)), $ETag); foreach ($CssFiles as $Info) { $this->Head->AddCss($Info[1], 'all', TRUE, $CssInfo); } } else { $Basename = substr($CssFile, 0, -4); $this->Head->AddCss(Url("/utility/css/{$ThemeType}/{$Basename}-{$ETag}.css", '//'), 'all', FALSE, $CssInfo['Options']); } continue; } if (StringBeginsWith($CssFile, 'http')) { $this->Head->AddCss($CssFile, 'all', GetValue('AddVersion', $CssInfo, TRUE), $CssInfo['Options']); continue; } elseif (strpos($CssFile, '/') !== FALSE) { // A direct path to the file was given. $CssPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $CssFile)))); } else { // $CssGlob = preg_replace('/(.*)(\.css)/', '\1*\2', $CssFile); $AppFolder = $CssInfo['AppFolder']; if ($AppFolder == '') { $AppFolder = $this->ApplicationFolder; } // CSS comes from one of four places: $CssPaths = array(); if ($this->Theme) { // Use the default filename. $CssPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'design' . DS . $CssFile; } // 3. Application or plugin. if (StringBeginsWith($AppFolder, 'plugins/')) { // The css is coming from a plugin. $AppFolder = substr($AppFolder, strlen('plugins/')); $CssPaths[] = PATH_PLUGINS . "/{$AppFolder}/design/{$CssFile}"; $CssPaths[] = PATH_PLUGINS . "/{$AppFolder}/{$CssFile}"; } elseif (in_array($AppFolder, array('static', 'resources'))) { // This is a static css file. $CssPaths[] = PATH_ROOT . "/resources/css/{$CssFile}"; } else { // Application default. eg. root/applications/app_name/design/ $CssPaths[] = PATH_APPLICATIONS . DS . $AppFolder . DS . 'design' . DS . $CssFile; } // 4. Garden default. eg. root/applications/dashboard/design/ $CssPaths[] = PATH_APPLICATIONS . DS . 'dashboard' . DS . 'design' . DS . $CssFile; } // Find the first file that matches the path. $CssPath = FALSE; foreach ($CssPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $CssPath = $Paths[0]; break; } } // Check to see if there is a CSS cacher. $CssCacher = Gdn::Factory('CssCacher'); if (!is_null($CssCacher)) { $CssPath = $CssCacher->Get($CssPath, $AppFolder); } if ($CssPath !== FALSE) { $CssPath = substr($CssPath, strlen(PATH_ROOT)); $CssPath = str_replace(DS, '/', $CssPath); $this->Head->AddCss($CssPath, 'all', TRUE, $CssInfo['Options']); } } // Add a custom js file. if (ArrayHasValue($this->_CssFiles, 'style.css')) { $this->AddJsFile('custom.js'); } // only to non-admin pages. // And now search for/add all JS files. $Cdns = array(); if (Gdn::Request()->Scheme() != 'https' && !C('Garden.Cdns.Disable', FALSE)) { $Cdns = array('jquery.js' => 'http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'); } $this->EventArguments['Cdns'] =& $Cdns; $this->FireEvent('AfterJsCdns'); foreach ($this->_JsFiles as $Index => $JsInfo) { $JsFile = $JsInfo['FileName']; if (isset($Cdns[$JsFile])) { $JsFile = $Cdns[$JsFile]; } if (strpos($JsFile, '//') !== FALSE) { // This is a link to an external file. $this->Head->AddScript($JsFile, 'text/javascript', GetValue('Options', $JsInfo, array())); continue; } elseif (strpos($JsFile, '/') !== FALSE) { // A direct path to the file was given. $JsPaths = array(CombinePaths(array(PATH_ROOT, str_replace('/', DS, $JsFile)), DS)); } else { $AppFolder = $JsInfo['AppFolder']; if ($AppFolder == '') { $AppFolder = $this->ApplicationFolder; } // JS can come from a theme, an any of the application folder, or it can come from the global js folder: $JsPaths = array(); if ($this->Theme) { // 1. Application-specific js. eg. root/themes/theme_name/app_name/design/ $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . $AppFolder . DS . 'js' . DS . $JsFile; // 2. Garden-wide theme view. eg. root/themes/theme_name/design/ $JsPaths[] = PATH_THEMES . DS . $this->Theme . DS . 'js' . DS . $JsFile; } // 3. The application or plugin folder. if (StringBeginsWith(trim($AppFolder, '/'), 'plugins/')) { $JsPaths[] = PATH_PLUGINS . strstr($AppFolder, '/') . "/js/{$JsFile}"; $JsPaths[] = PATH_PLUGINS . strstr($AppFolder, '/') . "/{$JsFile}"; } else { $JsPaths[] = PATH_APPLICATIONS . "/{$AppFolder}/js/{$JsFile}"; } // 4. Global JS folder. eg. root/js/ $JsPaths[] = PATH_ROOT . DS . 'js' . DS . $JsFile; // 5. Global JS library folder. eg. root/js/library/ $JsPaths[] = PATH_ROOT . DS . 'js' . DS . 'library' . DS . $JsFile; } // Find the first file that matches the path. $JsPath = FALSE; foreach ($JsPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $JsPath = $Paths[0]; break; } } if ($JsPath !== FALSE) { $JsSrc = str_replace(array(PATH_ROOT, DS), array('', '/'), $JsPath); $Options = (array) $JsInfo['Options']; $Options['path'] = $JsPath; $Version = GetValue('Version', $JsInfo); if ($Version) { TouchValue('version', $Options, $Version); } $this->Head->AddScript($JsSrc, 'text/javascript', $Options); } } } // Add the favicon. $Favicon = C('Garden.FavIcon'); if ($Favicon) { $this->Head->SetFavIcon(Gdn_Upload::Url($Favicon)); } // Make sure the head module gets passed into the assets collection. $this->AddModule('Head'); } // Master views come from one of four places: $MasterViewPaths = array(); $MasterViewPath2 = ViewLocation($this->MasterView() . '.master', '', $this->ApplicationFolder); if (strpos($this->MasterView, '/') !== FALSE) { $MasterViewPaths[] = CombinePaths(array(PATH_ROOT, str_replace('/', DS, $this->MasterView) . '.master*')); } else { if ($this->Theme) { // 1. Application-specific theme view. eg. root/themes/theme_name/app_name/views/ $MasterViewPaths[] = CombinePaths(array(PATH_THEMES, $this->Theme, $this->ApplicationFolder, 'views', $this->MasterView . '.master*')); // 2. Garden-wide theme view. eg. /path/to/application/themes/theme_name/views/ $MasterViewPaths[] = CombinePaths(array(PATH_THEMES, $this->Theme, 'views', $this->MasterView . '.master*')); } // 3. Application default. eg. root/app_name/views/ $MasterViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, $this->ApplicationFolder, 'views', $this->MasterView . '.master*')); // 4. Garden default. eg. root/dashboard/views/ $MasterViewPaths[] = CombinePaths(array(PATH_APPLICATIONS, 'dashboard', 'views', $this->MasterView . '.master*')); } // Find the first file that matches the path. $MasterViewPath = FALSE; foreach ($MasterViewPaths as $Glob) { $Paths = SafeGlob($Glob); if (is_array($Paths) && count($Paths) > 0) { $MasterViewPath = $Paths[0]; break; } } if ($MasterViewPath != $MasterViewPath2) { Trace("Master views differ. Controller: {$MasterViewPath}, ViewLocation(): {$MasterViewPath2}", TRACE_WARNING); } $this->EventArguments['MasterViewPath'] =& $MasterViewPath; $this->FireEvent('BeforeFetchMaster'); if ($MasterViewPath === FALSE) { trigger_error(ErrorMessage("Could not find master view: {$this->MasterView}.master*", $this->ClassName, '_FetchController'), E_USER_ERROR); } /// A unique identifier that can be used in the body tag of the master view if needed. $ControllerName = $this->ClassName; // Strip "Controller" from the body identifier. if (substr($ControllerName, -10) == 'Controller') { $ControllerName = substr($ControllerName, 0, -10); } // Strip "Gdn_" from the body identifier. if (substr($ControllerName, 0, 4) == 'Gdn_') { $ControllerName = substr($ControllerName, 4); } $this->SetData('CssClass', $this->Application . ' ' . $ControllerName . ' ' . $this->RequestMethod . ' ' . $this->CssClass, TRUE); // Check to see if there is a handler for this particular extension. $ViewHandler = Gdn::Factory('ViewHandler' . strtolower(strrchr($MasterViewPath, '.'))); if (is_null($ViewHandler)) { $BodyIdentifier = strtolower($this->ApplicationFolder . '_' . $ControllerName . '_' . Gdn_Format::AlphaNumeric(strtolower($this->RequestMethod))); include $MasterViewPath; } else { $ViewHandler->Render($MasterViewPath, $this); } }
public static function LoadArrayBySearch($intCategoryId = null, $intManufacturerId = null, $strDescription = null, $strAssetModelCode = null, $arrCustomFields = null, $strDateModified = null, $strDateModifiedFirst = null, $strDateModifiedLast = null, $blnAttachment = null, $strOrderBy = null, $strLimit = null, $objExpansionMap = null) { AssetModel::ArrayQueryHelper($strOrderBy, $strLimit, $strLimitPrefix, $strLimitSuffix, $strExpandSelect, $strExpandFrom, $objExpansionMap, $objDatabase); // Setup QueryExpansion $objQueryExpansion = new QQueryExpansion(); if ($objExpansionMap) { try { AssetModel::ExpandQuery('asset_model', null, $objExpansionMap, $objQueryExpansion); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } $arrSearchSql = AssetModel::GenerateSearchSql($intCategoryId, $intManufacturerId, $strDescription, $strAssetModelCode, $arrCustomFields, $strDateModified, $strDateModifiedFirst, $strDateModifiedLast, $blnAttachment); $arrCustomFieldSql = CustomField::GenerateSql(EntityQtype::AssetModel); $arrAttachmentSql = Attachment::GenerateSql(EntityQtype::AssetModel); $strQuery = sprintf(' SELECT %s COUNT( `asset`.`asset_id`) AS asset_count, `asset_model`.`asset_model_id` AS `asset_model_id`, `asset_model`.`category_id` AS `category_id`, `asset_model`.`manufacturer_id` AS `manufacturer_id`, `asset_model`.`asset_model_code` AS `asset_model_code`, `asset_model`.`short_description` AS `short_description`, `asset_model`.`long_description` AS `long_description`, `asset_model`.`image_path` AS `image_path`, `asset_model`.`created_by` AS `created_by`, `asset_model`.`creation_date` AS `creation_date`, `asset_model`.`modified_by` AS `modified_by`, `asset_model`.`modified_date` AS `modified_date` %s %s %s FROM `asset_model` AS `asset_model` LEFT JOIN `asset` AS `asset` ON `asset_model`.`asset_model_id` = `asset`.`asset_model_id` AND `asset`.`location_id` != 2 AND `asset`.`location_id` != 5 %s %s %s WHERE 1=1 %s %s %s %s %s %s %s %s %s %s ', $strLimitPrefix, $objQueryExpansion->GetSelectSql(",\n\t\t\t\t\t", ",\n\t\t\t\t\t"), $arrCustomFieldSql['strSelect'], $arrAttachmentSql['strSelect'], $objQueryExpansion->GetFromSql("", "\n\t\t\t\t\t"), $arrCustomFieldSql['strFrom'], $arrAttachmentSql['strFrom'], $arrSearchSql['strCategorySql'], $arrSearchSql['strManufacturerSql'], $arrSearchSql['strDescriptionSql'], $arrSearchSql['strAssetModelCodeSql'], $arrSearchSql['strDateModifiedSql'], $arrSearchSql['strAttachmentSql'], $arrSearchSql['strAuthorizationSql'], $arrAttachmentSql['strGroupBy'], $strOrderBy, $strLimitSuffix); $objDbResult = $objDatabase->Query($strQuery); return AssetModel::InstantiateDbResult($objDbResult); }
private function _AddCLEditor($Sender, $Column = 'Body') { static $Added = FALSE; if ($Added) { return; } // Add the CLEditor to the form $Options = array('ie' => 'gt IE 6', 'notie' => TRUE); // Exclude IE6 //$Sender->RemoveJsFile('jquery.autosize.min.js'); $Sender->AddJsFile('jquery.cleditor' . (Debug() ? '' : '.min') . '.js', 'plugins/cleditor', $Options); $CssInfo = AssetModel::CssPath(FALSE, 'cleditor.css', 'plugins/cleditor'); if ($CssInfo) { $CssPath = Asset($CssInfo[1]); } $Sender->Head->AddString(<<<EOT <style type="text/css"> a.PreviewButton { \tdisplay: none !important; } </style> <script type="text/javascript"> \tjQuery(document).ready(function(\$) { \t\t// Make sure the removal of autogrow does not break anything \t\t\$.fn.autogrow = function(o) { return; } \t\t// Attach the editor to comment boxes. \t\t\$("textarea.BodyBox").livequery(function() { \t\t\tvar frm = \$(this).closest("form"); \t\t\ted = jQuery(this).cleditor({ width:"100%", height:"100%", controls: "bold italic strikethrough | font size " + "style | color highlight removeformat | bullets numbering | outdent indent | " + "alignleft center alignright | undo redo | " + "image link unlink | pastetext source", docType: '<!DOCTYPE html>', docCSSFile: "{$CssPath}" })[0]; \t\t\tthis.editor = ed; // Support other plugins! \t\t\tjQuery(frm).bind("clearCommentForm", {editor:ed}, function(e) { \t\t\t\tfrm.find("textarea").hide(); \t\t\t\te.data.editor.clear(); \t\t\t}); \t\t}); \t}); </script> EOT ); $Added = TRUE; }
protected function btnMassDeleteConfirmSkip_Click() { if (count($this->arrToDelete) > 0) { AssetModel::DeleteSelected($this->arrToDelete); $this->arrToDelete = array(); } $this->dlgMassDelete->HideDialogBox(); QApplication::Redirect(''); }
public function btnSave_Click($strFormId, $strControlId, $strParameter) { $this->EnableSelectedControls(); $this->ClearWarnings(); $blnError = false; // Make sure at least one checkbox is checked if (!$this->chkCategory->Checked && !$this->chkManufacturer->Checked && !$this->chkLongDescription->Checked) { $blnChecked = false; foreach ($this->arrCheckboxes as $objCheckBox) { if ($objCheckBox->Checked) { $blnChecked = true; break; } } if (!$blnChecked) { $blnError = true; $this->btnCancel->Warning = 'You must select at least one field to edit.'; return; } } // Get an instance of the database $objDatabase = QApplication::$Database[1]; // Begin a MySQL Transaction to be either committed or rolled back $objDatabase->TransactionBegin(); if (count($this->arrCustomFields) > 0) { $customFieldIdArray = array(); foreach ($this->arrCustomFields as $field) { if ($this->arrCheckboxes[$field['input']->strControlId]->Checked) { if ($field['input'] instanceof QTextBox && $field['input']->Required && $field['input']->Text == null || $field['input'] instanceof QListBox && $field['input']->Required && $field['input']->SelectedValue == null) { $blnError = true; $field['input']->Warning = "Required."; } else { $this->arrCustomFieldsToEdit[] = $field; $customFieldIdArray[] = (int) str_replace('cf', '', $field['input']->strControlId); } } } } $set = array(sprintf('`modified_by`= %s', QApplication::$objUserAccount->UserAccountId)); // Force modified_date timestamp update $set[] = '`modified_date` = NOW()'; if ($this->chkLongDescription->Checked) { $set[] = sprintf('`long_description`="%s"', $this->txtLongDescription->Text); } if ($this->chkManufacturer->Checked) { if ($this->lstManufacturer->SelectedValue !== null) { $set[] = sprintf('`manufacturer_id`=%s', $this->lstManufacturer->SelectedValue); } else { $blnError = true; $this->lstManufacturer->Warning = 'Manufacturer is required.'; } } if ($this->chkCategory->Checked) { if ($this->lstCategory->SelectedValue !== null) { $set[] = sprintf('`category_id`= %s', $this->lstCategory->SelectedValue); } else { $blnError = true; $this->lstCategory->Warning = 'Category is required.'; } } // First check that the user is authorized to edit these models foreach ($this->arrModelsToEdit as $intModelId) { $objAssetModel = AssetModel::Load($intModelId); if (!QApplication::AuthorizeEntityBoolean($objAssetModel, 2)) { $blnError = true; $this->btnCancel->Warning = 'You are not authorized to edit one or more of the selected models.'; break; } } if (!$blnError) { try { if (count($this->arrCustomFieldsToEdit) > 0) { // preparing data to edit // Save the values from all of the custom field controls to save the asset foreach ($this->arrModelsToEdit as $intModelId) { $objCustomFieldsArray = CustomField::LoadObjCustomFieldArray(EntityQtype::AssetModel, false); $selectedCustomFieldsArray = array(); foreach ($objCustomFieldsArray as $objCustomField) { if (in_array($objCustomField->CustomFieldId, $customFieldIdArray)) { $selectedCustomFieldsArray[] = $objCustomField; } } CustomField::SaveControls($selectedCustomFieldsArray, true, $this->arrCustomFieldsToEdit, $intModelId, EntityQtype::AssetModel); } } $strQuery = sprintf("UPDATE `asset_model`\n\t\t\t\t\t\t\t\t\t SET " . implode(",", $set) . "\n\t\t\t\t\t\t\t\t\t WHERE `asset_model_id` IN (%s)", implode(",", $this->arrModelsToEdit)); // print $strQuery; exit; $objDatabase->NonQuery($strQuery); $objDatabase->TransactionCommit(); QApplication::Redirect(''); } catch (QMySqliDatabaseException $objExc) { $objDatabase->TransactionRollback(); throw new QDatabaseException(); } } else { $objDatabase->TransactionRollback(); $this->arrCustomFieldsToEdit = array(); } }
public function lstAssetModel_Select($strFormId, $strControlId, $strParameter) { if ($this->lstAssetModel->SelectedValue != null) { $objAssetModel = AssetModel::Load($this->lstAssetModel->SelectedValue); if ($objAssetModel) { if ($objAssetModel->AssetModelCode) { $this->lblAssetModelCode->Text = $objAssetModel->AssetModelCode; } else { $this->lblAssetModelCode->Text = 'None'; } if ($objAssetModel->Manufacturer) { $this->lblManufacturer->Text = $objAssetModel->Manufacturer->ShortDescription; } else { $this->lblManufactuerer->Text = 'None'; } if ($objAssetModel->Category) { $this->lblCategory->Text = $objAssetModel->Category->ShortDescription; } } } }
/** * Deletes all associated AssetModels * @return void */ public function DeleteAllAssetModels() { if (is_null($this->intManufacturerId)) { throw new QUndefinedPrimaryKeyException('Unable to call UnassociateAssetModel on this unsaved Manufacturer.'); } // Get the Database Object for this Class $objDatabase = Manufacturer::GetDatabase(); // Journaling if ($objDatabase->JournalingDatabase) { foreach (AssetModel::LoadArrayByManufacturerId($this->intManufacturerId) as $objAssetModel) { $objAssetModel->Journal('DELETE'); } } // Perform the SQL Query $objDatabase->NonQuery(' DELETE FROM `asset_model` WHERE `manufacturer_id` = ' . $objDatabase->SqlVariable($this->intManufacturerId) . ' '); }
/** * Get the path to a view. * * @param string $view the name of the view. * @param string $controller the name of the controller invoking the view or blank. * @param string $folder the application folder or plugins/<plugin> folder. * @param array|null $extensions optional. list of extensions to allow * @return string|false The path to the view or false if it wasn't found. */ public static function viewLocation($view, $controller, $folder, $extensions = null) { $paths = []; // If the first character is a forward slash, this is an absolute path if (strpos($view, '/') === 0) { // This is a path to the view from the root. $paths[] = $view; } else { $view = strtolower($view); // Trim "controller" from the end of controller name, if its there $controller = strtolower(stringEndsWith($controller, 'Controller', true, true)); if ($controller) { $controller = '/' . $controller; } // Get list of permitted view extensions if (is_null($extensions)) { $extensions = AssetModel::viewExtensions(); } // 1. Gather paths from the theme, if enabled if (Gdn::controller() instanceof Gdn_Controller) { $theme = Gdn::controller()->Theme; if ($theme) { foreach ($extensions as $ext) { $paths[] = PATH_THEMES . "/{$theme}/views{$controller}/{$view}.{$ext}"; } } } // 2a. Gather paths from the plugin, if the folder is a plugin folder if (stringBeginsWith($folder, 'plugins/')) { // This is a plugin view. foreach ($extensions as $ext) { $paths[] = PATH_ROOT . "/{$folder}/views{$controller}/{$view}.{$ext}"; } // 2b. Gather paths from the application as a fallback } else { // This is an application view. $folder = strtolower($folder); foreach ($extensions as $ext) { $paths[] = PATH_APPLICATIONS . "/{$folder}/views{$controller}/{$view}.{$ext}"; } if ($folder != 'dashboard' && stringEndsWith($view, '.master')) { // This is a master view that can always fall back to the dashboard. foreach ($extensions as $ext) { $paths[] = PATH_APPLICATIONS . "/dashboard/views{$controller}/{$view}.{$ext}"; } } } } // Now let's search the paths for the view. foreach ($paths as $path) { if (file_exists($path)) { return $path; } } trace(['view' => $view, 'controller' => $controller, 'folder' => $folder], 'View'); trace($paths, __METHOD__); return false; }
/** * 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 `asset_custom_field_asset_model` AS `%s__%s` ON `%s`.`%s` = `%s__%s`.`asset_custom_field_asset_model_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`asset_custom_field_asset_model_id` AS `%s__%s__asset_custom_field_asset_model_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`asset_model_id` AS `%s__%s__asset_model_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`custom_field_id` AS `%s__%s__custom_field_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias)); $strParentAlias = $strParentAlias . '__' . $strAlias; } if (is_array($objExpansionMap)) { foreach ($objExpansionMap as $strKey => $objValue) { switch ($strKey) { case 'asset_model_id': try { AssetModel::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion); break; } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } case 'custom_field_id': try { CustomField::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)); } } } }
/** * 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 = AssetModel::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 AssetModel, given the clauses above $this->DataSource = AssetModel::QueryArray($objCondition, $objClauses); }
/** * Placed these components everywhere due to some Web sites loading the * editor in some areas where the values were not yet injected into HTML. */ public function base_render_before(&$Sender) { // Don't render any assets for editor if it's embedded. This effectively // disables the editor from embedded comments. Some HTML is still // inserted, because of the BeforeBodyBox handler, which does not contain any data relating to embedded content. if ($this->isEmbeddedComment($Sender)) { return false; } $c = Gdn::controller(); // If user wants to modify styling of Wysiwyg content in editor, // they can override the styles with this file. $CssInfo = AssetModel::cssPath('wysiwyg.css', 'plugins/editor'); if ($CssInfo) { $CssPath = asset($CssInfo[1]); } // Load JavaScript used by every editor view. $c->addJsFile('editor.js', 'plugins/editor'); // Fileuploads $c->addJsFile('jquery.ui.widget.js', 'plugins/editor'); $c->addJsFile('jquery.iframe-transport.js', 'plugins/editor'); $c->addJsFile('jquery.fileupload.js', 'plugins/editor'); // Set definitions for JavaScript to read $c->addDefinition('editorVersion', $this->pluginInfo['Version']); $c->addDefinition('editorInputFormat', $this->Format); $c->addDefinition('editorPluginAssets', $this->AssetPath); $c->addDefinition('wysiwygHelpText', t('editor.WysiwygHelpText', 'You are using <a href="https://en.wikipedia.org/wiki/WYSIWYG" target="_new">WYSIWYG</a> in your post.')); $c->addDefinition('bbcodeHelpText', t('editor.BBCodeHelpText', 'You can use <a href="http://en.wikipedia.org/wiki/BBCode" target="_new">BBCode</a> in your post.')); $c->addDefinition('htmlHelpText', t('editor.HtmlHelpText', 'You can use <a href="http://htmlguide.drgrog.com/cheatsheet.php" target="_new">Simple HTML</a> in your post.')); $c->addDefinition('markdownHelpText', t('editor.MarkdownHelpText', 'You can use <a href="http://en.wikipedia.org/wiki/Markdown" target="_new">Markdown</a> in your post.')); $c->addDefinition('textHelpText', t('editor.TextHelpText', 'You are using plain text in your post.')); $c->addDefinition('editorWysiwygCSS', $CssPath); $additionalDefinitions = array(); $this->EventArguments['definitions'] =& $additionalDefinitions; $this->fireEvent('GetJSDefinitions'); // Make sure we still have an array after all event handlers have had their turn and iterate through the result. if (is_array($additionalDefinitions)) { foreach ($additionalDefinitions as $defKey => $defVal) { $c->addDefinition($defKey, $defVal); } unset($defKey, $defVal); } // Set variables for file uploads $PostMaxSize = Gdn_Upload::unformatFileSize(ini_get('post_max_size')); $FileMaxSize = Gdn_Upload::unformatFileSize(ini_get('upload_max_filesize')); $ConfigMaxSize = Gdn_Upload::unformatFileSize(c('Garden.Upload.MaxFileSize', '1MB')); $MaxSize = min($PostMaxSize, $FileMaxSize, $ConfigMaxSize); $c->addDefinition('maxUploadSize', $MaxSize); // Set file input name $c->addDefinition('editorFileInputName', $this->editorFileInputName); $Sender->setData('_editorFileInputName', $this->editorFileInputName); // Save allowed file types $c->addDefinition('allowedFileExtensions', json_encode(c('Garden.Upload.AllowedFileExtensions'))); // Get max file uploads, to be used for max drops at once. $c->addDefinition('maxFileUploads', ini_get('max_file_uploads')); // Set canUpload definition here, but not Data (set in BeforeBodyBox) because it overwrites. $c->addDefinition('canUpload', $this->canUpload); }
/** * @param string $view The view name. * @param string $controllerName The controller name for the view. * @param string $applicationFolder The application folder for the view. * @return EmailTemplate $this The calling object. * @throws Exception */ public function setView($view, $controllerName = 'email', $applicationFolder = 'dashboard') { $this->view = AssetModel::viewLocation($view, $controllerName, $applicationFolder); return $this; }