* * * @author Luiz Gilberto Gregory Filho [luiz@solis.coop.br] * * @version $Id$ * * \b Maintainers: \n * Eduardo Bonfandini [eduardo@solis.coop.br] * Jamiel Spezia [jamiel@solis.coop.br] * Luiz Gregory Filho [luiz@solis.coop.br] * Moises Heberle [moises@solis.coop.br] * Sandro R. Weisheimer [sandrow@solis.coop.br] * * @since * Class created on 08/10/2008 * **/ $MIOLO->getClass('gnuteca3', 'controls/FileUploader'); $MIOLO->getClass('gnuteca3', 'GDictionaryField'); $MIOLO->getClass('gnuteca3', 'GnutecaMaterialDetail'); class FrmMaterial extends GnutecaForm { public $businessMaterialControl, $businessTag, $localFields, $grid, $event, $url, $aux, $upBox; public $repetitiveFields, $repeatFieldRequired, $requiredFields, $controlNumber; public $leaderFields, $spreadsheet, $tabs; public $imagePlusUrl = null, $imageMinusUrl = null; const DIV_CATALOGUE = "divCataloge"; const DIV_SPREADSHEET = "divSpreadsheet"; const REPEAT_FIELD_PREFIX_NAME = "gtcRepeatField_"; /** * Constructor Method **/ function __construct($data) { $MIOLO = MIOLO::getInstance(); $this->setBusiness('BusCataloge'); $this->setTransaction('material'); $this->setInsertFunction('save'); $this->businessMaterialControl = $MIOLO->getBusiness( 'gnuteca3', 'BusMaterialControl'); $this->businessTag = $MIOLO->getBusiness( 'gnuteca3', 'BusTag'); parent::__construct(); $this->keyDownHandler(112,113,114,115,116,117,118,119); $this->function = MIOLO::_REQUEST('function'); $this->event = MIOLO::_REQUEST($this->page->getFormId() . '__EVENTTARGETVALUE'); $this->imagePlusUrl = $this->ui->getImage($this->module, 'plus-8x8.png'); $this->imageMinusUrl = $this->ui->getImage($this->module, 'minus-8x8.png'); //cria variáveis JS para componente +/- $this->addJsCode("var imagePlusURL = '$this->imagePlusUrl'; var imageMinusURL = '$this->imageMinusUrl';"); //determina algumas variáveis no bus e no formulário $this->business->controlNumberFather = null; $this->business->controlNumber = null; $this->business->preCatalogue = $this->isPreCatalogue() ; $this->business->cameFromPreCat = $this->isPreCatalogue() ; switch($this->function) { case 'update': $this->controlNumber = $data->controlNumber; if(!is_null($this->controlNumber) && $this->event != "saveSpreadsheet" && $this->event != "createSpreadsheetFields") { $this->business->setLoadFields(); $this->business->controlNumber = $this->controlNumber; } break; case 'duplicate': $this->controlNumber = $data->controlNumber; if(!is_null($this->controlNumber) && $this->event != "saveSpreadsheet" && $this->event != "createSpreadsheetFields") { $this->business->setDuplicateMaterial(); $this->business->controlNumber = $this->controlNumber; } break; case 'addChildren' : $this->business->controlNumberFather = $data->controlNumber; break; case 'insert': default : $this->controlNumber = $data->controlNumber; break; } $this->setLabelWidth('300px'); //se não tiver nenhum evento monta a tela inicial if ( !$this->event || $this->event == 'tbBtnNew:click') { $this->getLeaderFields(); } $this->createFields(); $this->addJsCode(" expandRetractContainer = function(ContainerID, ImageID) { var st = dojo.byId(ContainerID).style.display; try { dojo.byId(ContainerID).style.display = (st == 'none') ? 'block' : 'none'; } catch(e){} try { dojo.byId(ImageID).src = (st == 'none') ? imageMinusURL : imagePlusURL; } catch(e){} } "); $this->box->setBoxClass("catalogueForm"); //usado no miolo.css } /** * retorna se esta ou não na pré-catalogação * * @return retorna se esta ou não na pré-catalogação */ public function isPreCatalogue() { return MIOLO::getCurrentAction() == 'main:catalogue:preCatalogue'; } /** * Define the form fields * */ function createFields() { $div[] = new MDiv(self::DIV_CATALOGUE, new MVContainer('container', $this->localFields)); $this->setFields( $div , true); } /** * Cria os campos de form leader * Primeira interface que aparece para o usuário * * @return void */ public function getLeaderFields() { $this->localFields = null; $leaderFields = $this->business->getLeaderFields(); if ( is_array( $leaderFields ) ) { foreach ( $leaderFields as $index => $content ) { $this->localFields[] = $this->addDefaultField($content, false, false); } } //controlar quando é leaderFields $this->localFields['leaderFields'] = new MTextField('leaderFields', DB_TRUE); $this->localFields['leaderFields']->addStyle('display', 'none'); $this->localFields[] = new MButton('btnNext', _M('Next', $this->module), ":createSpreadsheetFields", $this->ui->getImage($this->module, 'next-16x16.png') ); } /** * Evento chamado após apertar no "next" da primeira aba, realmente monta * o formulário de catalogação * */ function createSpreadsheetFields( $args ) { $this->imagePlusUrl = $this->ui->getImage($this->module, 'plus-8x8.png'); $this->imageMinusUrl = $this->ui->getImage($this->module, 'minus-8x8.png'); $this->localFields = null; $this->business->setFormValueLeaderFields($args); // set os parametros na classe Cataloge $leaderString = $this->business->getLeaderString(); $this->spreadsheet = $this->business->getSpreadsheet(); // busca a planilha correspondente // Se a planilha nao exitir if ( $this->spreadsheet === false ) { $error = $this->business->getErrors(); $this->error($error[0], $this->MIOLO->getCurrentURL(), _M("Errors", $this->module), null, true); return false; } $this->localFields = null; if ( $this->function == "update" && !$this->isPreCatalogue() ) { $entryDate = new GDate( $this->businessMaterialControl->getEntraceDate($args->controlNumber) ); $entryDate = $entryDate->generate(); $lastChange = new GDate( $this->businessMaterialControl->getLastChangeDate($args->controlNumber) ); $lastChange = $lastChange->generate(); } else { $entryDate = GDate::now()->generate(); } //para funcionar corretamente quando for adicionar um filho if ( MIOLO::_REQUEST('function') =='addChildren' || MIOLO::_REQUEST('function') =='duplicate' ) { unset($args->controlNumber); } $staticFields[] = new MTextField( 'controlNumber', $args->controlNumber, _M("Control number", $this->module), FIELD_DESCRIPTION_SIZE, _M('Control Number', $this->module), null, true); $staticFields[] = new MTextField( 'entryDate', $entryDate,_M("Entry date", $this->module), FIELD_DESCRIPTION_SIZE, _M("Entry date", $this->module), null, true); $staticFields[] = new MTextField( 'lastChange', $lastChange ,_M("Last change", $this->module), FIELD_DESCRIPTION_SIZE, _M("Last change", $this->module), null, true); $staticFields[] = new MTextField( 'marcLeader', $leaderString ,_M("Leader", $this->module), FIELD_DESCRIPTION_SIZE, _M("Leader", $this->module), null, true); $this->localFields[] = $this->addTagGroup('staticField', null, $staticFields, false ); //campo que controla se ja foi clicado no salvar $this->localFields[] = new MHiddenField('wasSaved'); $this->getSpreadsheetFields(); $this->getJsFunctionToAutoCompleteFields(); $this->getDefaultFieldsHidden(); $this->setResponse( new MDiv(self::DIV_SPREADSHEET, $this->localFields) , self::DIV_CATALOGUE); //altera a toolbar $toolbar = $this->getToolBar(null, true); $this->setResponse( new MDiv('divTool', $toolbar), 'toolBarContainer'); } /** * * */ function getSpreadsheetFields() { $this->controlNumber = MIOLO::_REQUEST('controlNumber'); $tabControl = new ATabControl('tabControlCatalogue'); //Define spreadsheets na sessao para ser obtido no editFromTable() - ref. ticket #5908 $session = new MSession(); $session->set('spreadsheets', $this->spreadsheet); foreach($this->spreadsheet as $tabName => $etiquetas) { $tabGroups = null; foreach($etiquetas as $etiquetaId => $etiContent) { $subFields = $etiContent->subFields; $tabFields = null; $repetitiveFields = null; $permiteRepetitiveField = ($etiContent->isRepetitive == 't'); if(!$subFields) { continue; } // Adiciona os indicadores if($etiContent->indicadores) { foreach($etiContent->indicadores as $i => $indValues) { $indValues->type = FIELD_TYPE_COMBO; $tabFields[] = $this->addDefaultField($indValues, true, true, false, false, true); } } $displayGroupForce = false; // Verifica se Tem repetitive field ca TAg if($permiteRepetitiveField) { if ( $etiquetaId == '949' ) { $opts = array('edit', 'remove', 'up', 'down', 'updateButton', 'includeButton'); } else { $opts = array('edit', 'remove', 'up', 'down', 'updateButton'); } $this->repetitiveFields[$etiquetaId] = new GnutecaRepetitiveField(self::REPEAT_FIELD_PREFIX_NAME. $etiquetaId, $etiContent->name, null, true, $opts, 'vertical'); $this->repetitiveFields[$etiquetaId]->clearData(); $this->repetitiveFields[$etiquetaId]->setOverflowWidth("85%"); $this->repetitiveFields[$etiquetaId]->actionCelWidth = 80; $this->repetitiveFields[$etiquetaId]->setValidators(); if($this->function != 'insert' && count($etiContent->loadValue)) { $displayGroupForce = true; $this->repetitiveFields[$etiquetaId]->setData($etiContent->loadValue); } $repetitiveFieldsValidators = null; } // Percorre os subfields da TAG foreach($subFields as $subFieldsId => $subFContent) { if($subFContent->isActive == 'f') { continue; } $subFContent->hasRepetitive = $permiteRepetitiveField; $subFContent->fieldId = $etiquetaId; $readOnly = $this->checkReadOnly($subFContent); if($permiteRepetitiveField && $subFContent->isRepetitive == DB_TRUE ) { $repetitiveFields[] = $this->addRepetitiveField($subFContent, $readOnly); if(isset($subFContent->repeatFieldValidator) && is_array($subFContent->repeatFieldValidator)) { foreach ($subFContent->repeatFieldValidator as $typeValidator) { switch($typeValidator) { case 'required' : $repetitiveFieldsValidators[] = new MRequiredValidator($subFContent->fieldName, $subFContent->label); break; case 'unique' : $repetitiveFieldsValidators[] = new GnutecaUniqueValidator($subFContent->fieldName, $subFContent->label); break; case 'date' : $repetitiveFieldsValidators[] = new GnutecaDateValidator($subFContent->fieldName, $subFContent->label); break; } } } } else { $tabFields[] = $this->addDefaultField($subFContent, ($etiquetaId != MARC_FIXED_DATA_FIELD), true, $readOnly, false, true); } if(isset($subFContent->workValidator) && is_array($subFContent->workValidator)) { $this->business->localValidator[] = $subFContent; } if( isset($subFContent->formValue) && strlen($subFContent->formValue[0]) || isset($subFContent->baseValue) && strlen($subFContent->baseValue[0]) || isset($subFContent->defaultValue) && count($subFContent->defaultValue) || isset($subFContent->loadValue) && count($subFContent->loadValue) ) { $displayGroupForce = true; } } // Se tem repetitive fields, adiciona eles no grupo de campos. if(!is_null($repetitiveFields)) { $tabFields[] = $this->generateRepetitiveFields($etiquetaId, $repetitiveFields); if(!is_null($repetitiveFieldsValidators)) { $this->repetitiveFields[$etiquetaId]->setValidators($repetitiveFieldsValidators); } } // Adiciona o grupo de campos $tabGroups[] = $this->addTagGroup($etiquetaId, $etiContent, $tabFields, $displayGroupForce); } $tabId = 'tab'.str_replace(" ", "_", $tabName); $tabName = $etiquetas['tabName'] ? $etiquetas['tabName'] : $tabName; $tabControl->addTab( $tabId, $tabName, $tabGroups); } //inicia a parte de capa/cover $fileUploader = new FileUploader('Anexe a capa do material'); FileUploader::setLimit(1); //somente uma imagem por capa FileUploader::clearData(); FileUploader::setExtensions(array('png','jpg','gif'), $deny); //carrega a capa if ( $this->function == "update" && !is_null($this->controlNumber) ) { $busFile = $this->MIOLO->getBusiness('gnuteca3','BusFile'); $busFile->folder= $this->isPreCatalogue() ? 'coverpre' : 'cover'; //escolhe a pasta certa para escolher a imagem $busFile->fileName = $this->controlNumber.'.'; //o ponto garante que não apareçam arquivos extras #$busFile->extension = 'png'; $fileUploader->setData( $busFile->searchFile(true) ); } $tabControl->addTab('tabCover', _M('Cover', $this->module), array( $fileUploader )); $this->localFields[] = $tabControl; $this->business->saveContent(); } /** * Verifica se deve setar readonly algum campo * * @param object $subFContent * @return boolean */ function checkReadOnly($subFContent) { if($subFContent->tag == MARC_EXEMPLARY_EXEMPLARY_STATUS_TAG) { //return true; } elseif($subFContent->tag == MARC_EXEMPLARY_EXEMPLARY_STATUS_FUTURE_TAG && $this->function == 'update') { //return true; } if(isset($subFContent->workValidator) && is_array($subFContent->workValidator)) { if(in_array("readonly", $subFContent->workValidator)) { return true; } } return $subFContent->readOnly; } /** * */ function addTagGroup($tagNumber, $tagObject, $fields, $displayBlockForce = false) { if($tagNumber == MARC_FIXED_DATA_FIELD) { array_unshift($fields, $separator); return new MVContainer("contTagGroup-$tagNumber", $fields); } if ( is_null($tagObject) ) { $leaderFields = $this->business->getLeaderFields(); $label = $this->business->getCategory() . ': ' . $leaderFields['000-6']->fieldContent->options[MIOLO::_REQUEST('000-6')] . ' - ' . $leaderFields['000-7']->fieldContent->options[MIOLO::_REQUEST('000-7')] . ' - ' . $leaderFields['000-17']->fieldContent->options[MIOLO::_REQUEST('000-17')]; $tagObject->name = $label; $labelValue = $label; $tagObject->baseGroupDisplay = 'none'; } else { $labelValue = "{$tagNumber} - {$tagObject->name}"; } $imagePlus = new MImage("iconTagGroup-$tagNumber", null, $displayBlockForce ? $this->imageMinusUrl : $this->imagePlusUrl); $imagePlus->addAttribute("style", "margin-top:2px;cursor:pointer;"); $label = new MDiv($tagObject->name, ''.$labelValue.'', null, array('style'=>'cursor: pointer;')); $containerH = new MHContainer("containerLabelFieldsGroup", array($imagePlus, $label)); $containerH->addAttribute('onclick', "expandRetractContainer('bgTagGroup-{$tagNumber}','iconTagGroup-{$tagNumber}')"); $display = $displayBlockForce ? "block" : $tagObject->baseGroupDisplay; $containerTagGroup = new MBaseGroup ("bgTagGroup-$tagNumber", null, $fields, 'vertical','css' , MControl::FORM_MODE_SHOW_NBSP ); $containerTagGroup->setAttribute ('style', "display: {$display}; border:0; "); $groupConteiner = new MDiv("contTagGroup-$tagNumber", array($separator, $containerH, $containerTagGroup)); $groupConteiner->addAttribute("style", "margin-left:5px;"); return $groupConteiner; } public function getToolBar($formContent, $spreadSheet = false) { $MIOLO = MIOLO::getInstance(); $module = MIOLO::getCurrentModule(); $action = MIOLO::getCurrentAction(); $imageMaterialMoviment= $MIOLO->getUI()->getImage($module,'materialMovement-32x32.png'); $this->_toolBar = new GToolBar('toolBar', $MIOLO->getActionURL($module, $action)); //verifica se existe um código leader na url, caso tiver, é porque está inserindo um material diferente do padrão $leaderString = MIOLO::_REQUEST('leaderString'); if ( $leaderString ) { $url = $MIOLO->getActionURL($module, "main:catalogue:material&frm__mainForm__EVENTTARGETVALUE=tbBtnNew:click&function=dinamicMenu&leaderString={$leaderString}"); } else { $url = $MIOLO->getActionURL($module, "main:catalogue:material&frm__mainForm__EVENTTARGETVALUE=tbBtnNew:click&function=insert"); } //refaz botão new para entrar na inserção de material sempre $imageNew = $MIOLO->getUI()->getImageTheme( $MIOLO->getTheme()->getId(), 'toolbar-new.png'); $this->_toolBar->addButton(MToolBar::BUTTON_NEW, null, "miolo.doLink('{$url}', 'frm__mainForm');", _M('Clique para inserir um novo registro'), true, $imageNew, $imageNew); $imageSave = $MIOLO->getUI()->getImageTheme( $MIOLO->getTheme()->getId(), 'toolbar-save.png'); $this->_toolBar->addButton("spreadSheetSave", null, ":saveSpreadsheet", _M("Salvar F3", $this->module), true, $imageSave, $imageSave); $imageSavePre = $MIOLO->getUI()->getImageTheme( $MIOLO->getTheme()->getId(), 'toolbar-savePreCatalogue.png'); $this->_toolBar->addButton("spreadSheetSavePreCatalogueButton$incrementName", null, ":saveSpreadsheetPreCatalogue", _M("Salvar na Pré-catalogação F8", $this->module), true, $imageSavePre, $imageSavePre); if ( $formContent ) { $this->_toolBar->setFormContent( $formContent ); } if ( !$spreadSheet ) //leader fields { $this->_toolBar->disableButtons(array("spreadSheetSave", "spreadSheetSavePreCatalogueButton$incrementName")); } else //campos da planilha { if ( !$this->business->cameFromPreCat && $this->function == 'update' ) { $this->_toolBar->disableButtons(array( "spreadSheetSavePreCatalogueButton$incrementName") ); } } //remover botões $this->_toolBar->removeButtons(array( MToolBar::BUTTON_SAVE, MToolBar::BUTTON_DELETE, MToolBar::BUTTON_RESET, "btnFormContent")); return $this->_toolBar; } /** * Mostra ajuda da tag (campo marc) * * @param $args a tag em si, exemplo 100.a * */ public function showHelp($args) { $tag = GnutecaUtils::getAjaxEventArgs(); $tag = explode('.', $tag); $busTag = $this->MIOLO->getBusiness('gnuteca3','BusTag'); $result = $busTag->getTag($tag[0],$tag[1]); $content = new MDiv('divHelp', nl2br($result->help)); $this->injectContent($content,true, _M('Ajuda para o subcampo') . ' ' . $tag[0].'.'.$tag[1]); } public function diffText($previousContent,$currentContent) { if ( $previousContent == $currentContent && $currentContent === '0' ) { return '0'; } $MIOLO = MIOLO::getInstance(); $module = MIOLO::getCurrentModule(); $MIOLO->uses('classes/Diff.php', $module); $MIOLO->uses('classes/Text/Diff/Renderer.php', $module); $MIOLO->uses('classes/Text/Diff/Renderer/inline.php', $module); $diff = new Text_Diff('native', array(array($previousContent), array($currentContent))); $renderer = new Text_Diff_Renderer_inline(); return $renderer->render($diff); } /** * Mostra ajuda da tag (campo marc) * * @param $args * */ public function showHistory($args) { $controlNumber = MIOLO::_REQUEST('controlNumber'); $tag = GnutecaUtils::getAjaxEventArgs(); $tag = explode('.', $tag); $busMaterialHistory = $this->MIOLO->getBusiness('gnuteca3', 'BusMaterialHistory'); $busMaterialHistory->clean(); $busMaterialHistory->controlNumber = $controlNumber; $busMaterialHistory->fieldId = $tag[0]; $busMaterialHistory->subFieldId = $tag[1]; $historyField = $busMaterialHistory->getMaterialHistory(); $columns = array ( _M("Revision", $this->module), _M("Operator", $this->module), _M("Date", $this->module), _M("Type", $this->module), _M("Changes", $this->module), ); $table = new MTableRaw( null, null, $columns, 'tableMaterialHistory'); $table->setAlternate(true); $table->setWidth("100%"); $table->setCellAttribute(0, 0, "width", "10%"); $table->setCellAttribute(0, 1, "width", "25%"); $arrayActions = GnutecaUtils::getDbActionList(); $tbCols = array( _M("Itens", $this->module),_M("Previous", $this->module),); foreach ($historyField as $object) { unset($tableArray); $changed = false; $tableArray[] = array(_M("Linha",$this->module). ":", $object->currentLine); $changed = true; if ($object->previousIndicator1 != $object->currentIndicator1) { $tableArray[] = array(_M("Previous indicator 1", $this->module). ":", $this->diffText($object->previousIndicator1, $object->currentIndicator1)); $changed = true; } if ($object->previousIndicator2 != $object->currentIndicator2) { $tableArray[] = array(_M("Previous indicator 2", $this->module). ":", $this->diffText($object->previousIndicator2, $object->currentIndicator2)); $changed = true; } if ($object->previousContent != $object->currentContent) { $tableArray[] = array(_M("Content",$this->module). ":", $this->diffText($object->previousContent,$object->currentContent), ''); $changed = true; } $tableChanges = new MTableRaw(NULL, $tableArray, $tbCols); $tableChanges->setAlternate(true); $tableChanges->addAttribute('width', '100%'); #limpa a tabela caso não exista nenhuma modificação if ( !$changed ) { $tableChanges = null; } $table->array[] = array ( $object->revisionNumber, $object->operator, GnutecaDate::identifyDateMask($object->data, GnutecaDate::getUserMask("TIMESTAMP")), array($arrayActions[$object->chancesType]), $tableChanges, ); } $tagTitle = $this->businessTag->getTag($tag[0], $tag[1]); $this->injectContent( $table->generate() ,true, _M('Material history', $this->module) . ' - ' .$controlNumber .' : ' . $tag[0].'.'.$tag[1] . ' - ' . $tagTitle->description); } /** * Trabalha o bloco de campo na interface * * Cria cada um dos campos da catalogação * * * @param $addSeparator não é mais utilizado * * **/ function addDefaultField($object, $doubleLabel = false, $addSeparator = true, $readOnly = false, $isRepetitive = false, $addKeyEvent = false) { $value = null; $n = $object->fieldName; list($etiqueta, $s) = explode(".", $object->tag); $setDefaultValue = (isset($object->defaultValue[0]->$n)) && ($isRepetitive || $this->function != 'update'); $setLoadValue = (isset($object->loadValue[0]->$n)) && ($this->function == 'update' || $this->function == 'duplicate') && (!$isRepetitive); if($setDefaultValue) { $value = $object->defaultValue[0]->$n; } if($setLoadValue) { $value = $object->loadValue[0]->$n; } if($isRepetitive && $readOnly) { $value = ''; } $label = $doubleLabel ? '' .$object->tag . ' - '. $object->label: $object->label; $labelObject = new MLabel($label); $labelObject->width = '300px' ; $principalField = $this->getCatalogueField($object, $value, $readOnly, $addKeyEvent); $field[] = new MHContainer( null, array($labelObject, $principalField) ); #caso o campo tenha ajuda if(isset($object->help) && strlen($object->help)) { $showHelp = GnutecaUtils::getAjax('showHelp',$object->tag).'; return false;'; $attr = array("onclick" => "javascript:$showHelp", 'alt' =>_M('Ajuda', $this->module), 'title' =>_M('Ajuda', $this->module)); $field[] = new MImageLink("help_{$object->fieldName}", null, "#", GnutecaUtils::getImageTheme('help-16x16'), $attr); } //caso o campo tenha histórico e não seja pré-catalogação if ( $object->history && !$this->isPreCatalogue() ) { $showHistory = GnutecaUtils::getAjax('showHistory',$object->tag).'; return false;'; $attr = array("onclick" => "javascript:$showHistory", 'alt' =>_M('Histórico', $this->module), 'title' =>_M('Histórico', $this->module) ); $field[] = new MImageLink("history_{$object->fieldName}", null, "#", GnutecaUtils::getImageTheme('history.png') , $attr); } #caso o campo tenha prefixo if($object->prefix) { $value = isset($object->loadPrefix[0]) && strlen($object->loadPrefix[0]) ? $object->loadPrefix[0] : null; $prefixField = new GnutecaSelection("prefix_{$object->fieldName}", $value, null, $object->prefix, false, '', '', false); $prefixField->addAttribute('style', 'width:60px'); $prefixLabel = new MDiv(null,_M("Prefix", $this->module),'prefixSuffixLabel'); $field[] = new MHContainer(null, array($prefixLabel, $prefixField)); } #caso o campo tenha sufixo if($object->suffix) { $value = isset($object->loadSuffix[0]) && strlen($object->loadSuffix[0]) ? $object->loadSuffix[0] : null; $suffixField = new GnutecaSelection("suffix_{$object->fieldName}", $value, null, $object->suffix, false, '', '', false); $suffixField->addAttribute('style', 'width:60px'); $suffixLabel = new MDiv(null,_M("Suffix", $this->module)); $field[] = new MHContainer(null, array($suffixLabel, $suffixField)); } #caso o campo tenha separador if($object->separator) { $value = isset($object->loadSeparator[0]) && strlen($object->loadSeparator[0]) ? $object->loadSeparator[0] : null; $separatorField = new GnutecaSelection("separator_{$object->fieldName}", $value, null, $object->separator); $separatorField->addAttribute('style', 'width:60px'); $separatorLabel = new MDiv(null, _M("Separator", $this->module)); $field[] = new MHContainer(null, array($separatorLabel, $separatorField)); } return new MHContainer("HcontainerField_{$object->tag}", $field); } /** * Retorna o campo trabalhado para adicionar no form * * @param object field $object * @param string $value * @param boolean $readOnly * @param boolean $addKeyEvent * @return object field */ private function getCatalogueField($object, $value = '', $readOnly = false, $addKeyEvent = false) { $addKeyEvent = FALSE; //esta asso, ára dizativar o dicionario switch($object->type) { case FIELD_TYPE_COMBO : $opts = (isset($object->fieldContent->options) ? $object->fieldContent->options : array() ); $fCombo = new MComboBox($object->fieldName . ($readOnly ? "_ro" : "") , $value , null, $opts); //FIXME dicionario if($addKeyEvent) { $fCombo->addAttribute('onkeypress', "return actionKeyPress(event)"); } if($readOnly) { $fCombo->setReadOnly(true); $fHidden = new MTextField($object->fieldName, $value, null, 4); $fHidden->addAttribute("gnutecaRepetitiveFieldExecute", "comboBoxSetValue_{$object->fieldName}(value, '{$object->fieldName}_ro')"); $fHidden->setReadOnly(true); $jsFunction = "comboBoxSetValue_{$object->fieldName} = function(value, fieldName) { content = ''; switch(value) { "; foreach ($opts as $index => $desc) { $jsFunction.= " case '{$index}' : content = '{$desc}'; break;"; } $jsFunction.= " } document.getElementById(fieldName).value = content; }"; $this->addJsCode($jsFunction); } return new MHContainer(null, array($fHidden, $fCombo)); case FIELD_TYPE_DATE : //converte a data do formato d/m/Y para Y-m-d, é necessário para o setData do calendário if ( strlen($value) > 0 ) { $date = new GDate($value); $value = $date->getDate(GDate::MASK_DATE_DB); } $field = new MCalendarField($object->fieldName, $value , null, FIELD_DATE_SIZE, null); //FIXME didicionario if($addKeyEvent) { $field->addAttribute('onkeypress', "return actionKeyPress(event)");} if($readOnly) { $field->addAttribute("readonly", "readonly"); } return $field; case FIELD_TYPE_MULTILINE : $field = new MMultiLineField($object->fieldName, $value , null, null, FIELD_MULTILINE_ROWS_SIZE, FIELD_MULTILINE_COLS_SIZE); //FIXME dicionario if ($addKeyEvent) { $field->addAttribute('onkeypress', "return actionKeyPress(event)");} if($readOnly) { $field->addAttribute("readonly", "readonly"); } return $field; case FIELD_TYPE_DICTIONARY : $lookUp = new GDictionaryField( $object->fieldName, $value ); $lookUp->setContext($this->module, $this->module, "Dictionary", 'filler', $object->fieldName, "{$object->fieldName}_Filter_DictionaryNumber,{$object->fieldName}_Filter_DictionaryContent", false); $lookUp->autocomplete = false; $lookUp->baseModule = $this->module; if($object->hasDictionary->readOnly == 't') { $lookUp->addAttribute("readonly", "readonly"); } if($readOnly) { $lookUp->setReadOnly(true); } //FIXME dicionario /*if($addKeyEvent) { $lookUp->addAttribute('onkeypress', "return actionKeyPress(event, '{$object->fieldName}', '{$object->hasDictionary->dictionaryId}', '". self::DIV_DICTIONARY ."')"); $lookUp->addAttribute('onblur', "dictionaryCloseTimeOut('". self::DIV_DICTIONARY ."', this.id)"); }*/ //campos necessários para filtrar o lookup $hiddenField1 = new MHiddenField("{$object->fieldName}_Filter_DictionaryNumber", $object->hasDictionary->dictionaryId); $hiddenField2 = new MHiddenField("{$object->fieldName}_Filter_DictionaryContent", $value); return new MHcontainer("lookUpContainer_{$object->fieldName}", array($lookUp, $hiddenField1, $hiddenField2)); case FIELD_TYPE_LOOKUP : $related = ereg("DescON", $object->lookUp->Desc) ? "{$object->fieldName},lookUpDesc_{$object->fieldName}_ro" : "{$object->fieldName}"; $size = ereg("DescON", $object->lookUp->Desc) ? FIELD_LOOKUPFIELD_SIZE : FIELD_DESCRIPTION_SIZE; $lookUp = new MLookupTextField($object->fieldName, $value, '', $size); $lookUp->setContext($this->module, $this->module, $object->lookUp->Name, 'filler', $related, '', false); $lookUp->baseModule = $this->module; //FIXME dicionario if($addKeyEvent) { $lookUp->addAttribute('onkeypress', "return actionKeyPress(event)");} if($readOnly) { $lookUp->setReadOnly(true); } $lookUpDesc = null; if(ereg("DescON", $object->lookUp->Desc)) { $lookUpDesc = new MTextField("lookUpDesc_{$object->fieldName}_ro", null, null, FIELD_DESCRIPTION_LOOKUP_SIZE); $lookUpDesc->setReadOnly(true); } return new MHcontainer("lookUpContainer_{$object->fieldName}", array($lookUp, $lookUpDesc)); case MARC_PERIODIC_INFORMATIONS: $fValues = explode(",", $value); $n = $v = $pt = $supl = ''; $lv = $this->business->getLevel() == "#" ? "Vol." : "v."; $ln = $this->business->getLevel() == "#" ? "no." : "n."; foreach ($fValues as $vx) { if(ereg("^v\.", trim($vx)) || ereg("^Vol\.", trim($vx)) ) { $v = trim(str_replace(array("v. ", "Vol. "), "", $vx)); } elseif(ereg("^n\.", trim($vx)) || ereg("^no\.", trim($vx)) ) { $n = trim(str_replace(array("n. ", "no. "), "", $vx)); } else { $pt = trim($vx); } } $field1 = new MHContainer(null, array(new MDiv(null, $lv), new MTextField("especialField_". MARC_PERIODIC_INFORMATIONS ."_{$object->fieldName}[]", $v, '', 10))); $field2 = new MHContainer(null, array(new MDiv(null,$ln), new MTextField("especialField_". MARC_PERIODIC_INFORMATIONS ."_{$object->fieldName}[]", $n, '', 10))); $field3 = new MHContainer(null, array(new MDiv(null,""), new MTextField("especialField_". MARC_PERIODIC_INFORMATIONS ."_{$object->fieldName}[]", $pt, '', 15))); return new MHcontainer("lookUpContainer_{$object->fieldName}", array($field1, $field2, $field3, $field4)); case FIELD_TYPE_TEXT : default : $field = new MTextField($object->fieldName, $value , null, FIELD_DESCRIPTION_SIZE); //FIXME dicionario if($addKeyEvent) { $field->addAttribute('onkeypress', "return actionKeyPress(event)"); } if ( $readOnly ) { $field->setReadOnly(true); } if ( !is_null($object->rulesToComplete ) ) { $originalField = str_replace(".", "_", "spreeadsheetField_{$object->rulesToComplete->originField}"); $field->addAttribute("onkeyup", "return autoCompleteMarcFields_{$originalField}(event)"); } return $field; } } /** * */ function addRepetitiveField($object, $readOnly = false) { $tableFields[] = $this->addDefaultField($object, true, true, $readOnly, true, true); $this->checkFieldFunction($object, $tableFields); $columns[] = new MGridColumn( "{$object->tag}
{$object->label}", 'left', true, null, true, $object->fieldName); if($object->prefix) { $columns[] = new MGridColumn(_M("Prefix", $this->module), 'left', true, null, true, "prefix_{$object->fieldName}"); } if($object->suffix) { $columns[] = new MGridColumn(_M("Suffix", $this->module), 'left', true, null, true, "suffix_{$object->fieldName}"); } if($object->separator) { $columns[] = new MGridColumn(_M("Separator", $this->module), 'left', true, null, true, "separator_{$object->fieldName}"); } return array('fields' => $tableFields, 'columns' => $columns); } /** * Função reescrita chamada na edição de registro da GnutecaRepetitiveField * @param $args */ public function editFromTable($args) { //pega somente os filtros da subdetail que está sendo editada $filters = array(); foreach($_SESSION['GnutecaRepetitiveField'][$args->GnutecaRepetitiveField][0] as $key=>$fields) { if ( substr($key, 0, 17 ) == 'spreeadsheetField' ) { $fieldsRep[] = $key; } } $js = ""; if ( is_array($filters) ) { foreach($fieldsRep as $field) { $fieldId = "{$field}_Filter_DictionaryNumber"; $fieldValue = $args->$fieldId; $js .= "field = dojo.byId('{$fieldId}'); if (field) {field.value = '{$fieldValue}';}\n"; } } autoEditAction($args); $MIOLO = MIOLO::getInstance(); $MIOLO->page->onload($js); } public function checkFieldFunction($object, &$tableFields) { switch($object->tag) { case MARC_EXEMPLARY_ORIGINAL_LIBRARY_UNIT_ID_TAG : list($f, $s) = explode(".", MARC_EXEMPLARY_ORIGINAL_LIBRARY_UNIT_ID_TAG); $function = "\$data->{$object->fieldName} = \$data->spreeadsheetField_{$f}_". MARC_EXEMPLARY_LIBRARY_UNIT_ID_SUBFIELD .";"; $function = new MTextField("Gnuteca3RepetitiveAddFunction_ro[]", $function, null, 1); $function ->addAttribute("style", "display:none"); $tableFields[] = $function; break; } } /** * */ function generateRepetitiveFields($etiquetaId, $rFields) { $f = null; $validators = null; foreach($rFields as $valores) { foreach($valores as $index => $objects) { foreach($objects as $obj) { eval("\$f->{$index}[] = \$obj;"); } } } $field[] = new MVContainer("containerV$etiquetaId", $f->fields); $this->repetitiveFields[$etiquetaId]->setFields ($field); $this->repetitiveFields[$etiquetaId]->setColumns($f->columns); $div = new MDiv("repeatId$etiquetaId", $this->repetitiveFields[$etiquetaId], null, array("style" => "width:95%;")); return $div; } /** * */ function setControlNumberFormFieldValue($nc) { $this->addJsCode("if(document.getElementById('controlNumber')){ document.getElementById('controlNumber').value = $nc; }"); } /** * */ function setLastChangeFormFieldValue() { $this->addJsCode("if(document.getElementById('lastChange')){ document.getElementById('lastChange').value = '". GnutecaDate::now(GnutecaDate::getUserMask('DATE')) ."'; }"); } /** * */ function setEntraceDateFormFieldValue() { $this->addJsCode("if(!document.getElementById('entryDate').value.length){ document.getElementById('entryDate').value = '". GnutecaDate::now(GnutecaDate::getUserMask('DATE')) ."'; }"); } /** * */ function setLeaderFormFieldValue() { $this->addJsCode("if(document.getElementById('marcLeader')){ document.getElementById('marcLeader').value = '". $this->business->getLeaderString() ."'; }"); } /** * */ function setWorkNumberValue() { $workNumberFieldName = $this->business->getWorkNumberFieldName(); $workNumberFieldValue = $this->business->getWorkNumberValue(); if(!strlen($workNumberFieldName)) { return; } $this->addJsCode("if(document.getElementById('$workNumberFieldName')){ document.getElementById('$workNumberFieldName').value = '$workNumberFieldValue'; }"); } public function prepareEspecialFields($args) { foreach ($args as $fieldName => $content) { if(ereg("^especialField_", $fieldName)) { $cont = ''; foreach ($content as $c) { if(strlen(trim($c))) { $cont.= "$c, "; } } $fName = preg_replace('/especialField_[0-9]{3}_[0-9a-zA-z]{1}_/', "", $fieldName); eval("\$args->{$fName} = \$cont;"); } } return $args; } public function logCover($msg) { clog( GDate::now()->getDate(GDate::MASK_TIMESTAMP_USER) . '-' . $msg ); } public function saveCover($controlNumber, $folder = 'cover') { $busFile = $this->MIOLO->getBusiness('gnuteca3','BusFile'); $busCatalogue = $this->MIOLO->getBusiness( 'gnuteca3', 'BusCataloge'); if ( !$controlNumber ) { $controlNumber = $busCatalogue->getControlNumberFromSession(); } //passando da pré-catalogação para catalogação definitiva if ( ( $folder == 'cover' && $this->isPreCatalogue() ) || ( $controlNumber != $busCatalogue->getControlNumberFromSession() ) ) { //$this->logCover('CAPA: Número de controle='. $controlNumber .' pasta=' .$folder ); $ori = $busFile->getAbsoluteFilePath( 'coverpre', $controlNumber, 'png'); $dst = $busFile->getAbsoluteFilePath( 'cover', $busCatalogue->getControlNumberFromSession() , 'png'); $this->logCover('Movendo capa da pré-catalalogação para catalogação ' . $ori.' | '.$dst); if ( file_exists($ori) ) { //move o arquivo $ok = rename($ori, $dst); //ajeita os dados para remontar a tabela no fim $folder = 'cover'; $controlNumber = $busCatalogue->getControlNumberFromSession(); $this->logCover('Capa movida com sucesso! Modificando número de controle da capa para '. $controlNumber ); } else { $this->logCover('Erro ao mover capa!'); } } $coverData = FileUploader::getData(); if ( $coverData ) { //converte o nome do arquivo para o número de controle, foreach caso o id seja diferente de i foreach ( $coverData as $line => $info) { if (is_array($info)) { $coverData[$line]['name'] = $controlNumber.'.png'; } if ( is_object($info) && $info->remove ) { $this->logCover('Removendo capa '. $info->absolute); } clog($info); } //caso já exista uma capa estocada, remove-a, só pode existir uma capa por arquivo if ( $busFile->fileExists( $folder, $controlNumber, 'png') && is_array($coverData[0]) ) { $filePath = $busFile->getAbsoluteFilePath( $folder, $controlNumber, 'png'); $busFile->deleteFile($filePath); $this->logCover('Capa existente removida com sucesso='.$filePath); } $busFile->folder = $folder; $busFile->files = $coverData; $ok = $busFile->insertFile(); //insere o arquivo if ( $ok ) { $this->logCover('Capa salva com sucesso ='.$folder.'/'.$controlNumber.'.png'); } FileUploader::clearData(); //limpa o sessão para evitar fazer 2 vezes a mesma coisa } //le novamente do disco e define no componente $busFile = $this->MIOLO->getBusiness('gnuteca3','BusFile'); $busFile->folder = $folder; $busFile->fileName = $controlNumber.'.'; //o ponto garante que não apareçam arquivos extras #$busFile->extension = 'png'; $data = $busFile->searchFile(true); FileUploader::clearData(); FileUploader::setData( $data ); /*if ( !$data[0]->absolute ) { throw new Exception( _M('Erro ao salvar capa @1, ela não se encontra no servidor!', $this->module, $controlNumber) ); }*/ FileUploader::generateTable(); //atualiza a tabela } public function tbBtnSave_click($args) { $this->saveSpreadsheet($args); } /** * */ function saveSpreadsheet($args) { $argsx = GnutecaRepetitiveField::prepareArgs($args); $argsx = $this->prepareEspecialFields($argsx); $argsx->controlNumber = MIOLO::_REQUEST('controlNumber','POST'); //valida a planilha $valid = $this->business->validatorSpreadsheetFields($argsx); if ( is_array($argsx->gtcRepeatField_949) ) { $ok = $this->business->verifyRepeatItemNumber($argsx->gtcRepeatField_949, $argsx->controlNumber); } $msgError = null; if ( !$valid || !$ok ) { $error = $this->business->getErrors(); if ( is_array($error) ) { foreach ($error as $msg) { $eDiv = new MDiv(null, $msg); $msgError.= $eDiv->generate(); } } } if ( $msgError ) { $this->error($msgError, null, _M("Errors", $this->module) ); return; } $r = $this->business->setFormValues($argsx); //manda os dados pro banco $NC = $this->business->save(); $this->setControlNumberFormFieldValue($NC); $this->setLastChangeFormFieldValue(); $this->setEntraceDateFormFieldValue(); $this->setWorkNumberValue(); //desabilita botão de pré-catalogação GToolBar::jsDisableButton('spreadSheetSavePreCatalogueButton'); $this->saveCover( MIOLO::_REQUEST('controlNumber','POST') ); //joga o valor 't' no campo escondido $this->page->onload("dojo.byId('wasSaved').value = 't';"); $this->injectContent( $this->getSaveContent()->generate() ,false, _M('Material salvo',$this->module ) ); } public function getSaveContent() { $MIOLO = MIOLO::getInstance(); $module = MIOLO::getCurrentModule(); $function = MIOLO::_REQUEST('function'); $busCatalogue = $MIOLO->getBusiness( $module, 'BusCataloge'); $busMaterial = $MIOLO->getBusiness( $module, 'BusMaterial'); $busKardexControl = $MIOLO->getBusiness( $module, 'BusKardexControl'); list($cat, $lev) = explode("-", SPREADSHEET_CATEGORY_FASCICLE); if ( $busCatalogue->getCategory() == $cat && $busCatalogue->getLevel() == $lev ) { $controlNumberFather = $busCatalogue->getTagValue(MARC_ANALITIC_ENTRACE_TAG); $unidades = $busCatalogue->getTagValue(MARC_EXEMPLARY_LIBRARY_UNIT_ID_TAG, true); if ( $unidades ) { $kardex = $busKardexControl->getKardexOfMaterial($controlNumberFather[0], $unidades); } if ( $kardex ) { $columsn[] = _M("Código do assinante", $module); $columsn[] = _M("Unidade de biblioteca", $module); $columsn[] = _M("Tipo de aquisição", $module); $columsn[] = _M("Publicação", $module); foreach ($kardex as $index => $kardexContent) { $content[$index][0] = $kardexContent->codigoDeAssinante; $content[$index][1] = $busMaterial->relationOfFieldsWithTable(MARC_KARDEX_LIBRARY_UNIT_ID_TAG, $kardexContent->libraryUnitId, true); $aquisitionType = $busMaterial->getContentTag($controlNumberFather[0], MARC_KARDEX_ACQUISITION_TYPE_TAG, $kardexContent->line); $publication = $busMaterial->getContentTag($controlNumberFather[0], MARC_KARDEX_PUBLICATION_TAG, $kardexContent->line); $content[$index][2] = $busMaterial->relationOfFieldsWithTable(MARC_KARDEX_ACQUISITION_TYPE_TAG, $aquisitionType, true); $content[$index][3] = $busMaterial->relationOfFieldsWithTable(MARC_KARDEX_PUBLICATION_TAG, $publication, true); } $table = new MTableRaw("Kardex", $content, $columsn); $table->addAttribute("style", "width:100%"); $fields[] = new MDiv("publicacao", $table); $fields[] = new MSeparator('
'); } } #info $table = new MTableRaw(_M("Informações da obra", $module), null , array('Campos', 'Conteúdos'), 'tableWorkInfo'); $table->setAlternate(true); $table->addAttribute("Style", "width:100%"); $table->setCellAttribute(0, 0, "width", "35%"); $table->setCellAttribute(0, 1, "width", "64%"); $spreadsheet = $busCatalogue->getSpreadsheetFromSession(); $controlNumber = $busCatalogue->getControlNumberFromSession(); $table->array[] = array(MARC_CONTROL_NUMBER_TAG ." - ". _M("Control Number", $module) , $controlNumber); if($spreadsheet) { foreach($spreadsheet as $tab => $spEti) { foreach($spEti as $etiqueta => $objEti) { if(!$objEti->subFields || $etiqueta == MARC_EXEMPLARY_FIELD || $etiqueta == MARC_KARDEX_FIELD) { continue; } foreach($objEti->subFields as $subfield => $object) { $value = null; foreach($object->formValue as $linha => $valor) { if($etiqueta == MARC_FIXED_DATA_FIELD && "$etiqueta.$subfield" != MARC_FIXED_DATA_TAG) { continue; } if(strlen($valor)) { if(isset($object->fieldContent) && isset($object->fieldContent->options)) { if(isset($object->fieldContent->options[$valor]) && strlen($object->fieldContent->options[$valor])) { $valor = $valor ." - ". $object->fieldContent->options[$valor]; } } if(isset($object->prefix) && is_array($object->prefix) && isset($object->loadPrefix[0]) && strlen($object->loadPrefix[0])) { $valor = "{$object->prefix[$object->loadPrefix[0]]}$valor"; } if(isset($object->suffix) && is_array($object->suffix) && isset($object->loadSuffix[0]) && strlen($object->loadSuffix[0])) { $valor.= "{$object->suffix[$object->loadSuffix[0]]}"; } $d = new MDiv("", "$valor"); $value.= $d->generate(); } } if(!is_null($value)) { $label = "{$object->name}" . (strlen($object->label) ? " - {$object->label}" : "" ); $table->array[] = array($label, $value); } } } } } $fields[] = new MDiv("divWorkInfos", $table); #exemplary $spreadsheet = $busCatalogue->getSpreadsheetFromSession(); $c = 0; if($spreadsheet) { foreach($spreadsheet as $tab => $spEti) { foreach($spEti as $etiqueta => $objEti) { if(!$objEti->subFields || ($etiqueta != MARC_EXEMPLARY_FIELD && $etiqueta != MARC_KARDEX_FIELD)) { continue; } foreach($objEti->subFields as $subfield => $object) { $tableColumns[$c] = "{$object->tag}
{$object->label}"; foreach($object->formValue as $linha => $valor) { if(strlen($valor)) { if(isset($object->fieldContent) && isset($object->fieldContent->options)) { if(isset($object->fieldContent->options[$valor]) && strlen($object->fieldContent->options[$valor])) { $valor = $valor ." - ". $object->fieldContent->options[$valor]; } } } else { $valor = ' '; } $d = new MDiv("", "$valor"); $tableArray[$linha][$c] = $d->generate(); } $c++; } } } } $table = new MTableRaw(_M("Exemplar", $module), null , $tableColumns, 'tableExemplaryInfo'); $table->setAlternate(true); $table->addAttribute("Style", "width:100%"); $table->array = $tableArray; $fields[] = new MDiv("divExemplaryInfos", $table); $fields[] = new MSeparator('
'); $args = array('controlNumber' => $this->business->controlNumber, 'searchFormat' => SIMPLE_SEARCH_SEARCH_FORMAT_ID); $buttons[] = new GnutecaRealLinkButton('gotoSearch', _M('Pesquisa', $this->module), 'main:search:simpleSearch', $this->MIOLO->getUI()->getImage( $this->module,'search-16x16.png'), $args); $buttons[] = GnutecaForm::getCloseButton(); $fields[] = new MDiv('contButtons', $buttons); return new MDiv('materialSaveContent', $fields ); } /** * Enter description here... * */ function saveSpreadsheetPreCatalogue($args) { $argsx = GnutecaRepetitiveField::prepareArgs($args); $r = $this->business->setFormValues($argsx); $NC = $this->business->savePreCatalogue(); $this->saveCover( null ,'coverpre'); $this->setControlNumberFormFieldValue($NC); $this->setLastChangeFormFieldValue(); $this->setWorkNumberValue(); $this->injectContent( $this->getSaveContent()->generate() ,false, _M('Material salvo',$this->module ) ); } /** * Enter description here... * */ function getDefaultFieldsHidden() { $hidden = $this->business->getHiddenDefaultFields(); if(!$hidden) { return; } foreach ($hidden as $eti => $cont) { foreach ($cont as $subf => $value) { $this->localFields[] = new MHiddenField("spreeadsheetField_{$eti}_{$subf}_defaultValue", $value); } } } /** * Enter description here... * */ function getJsFunctionToAutoCompleteFields() { $code = null; foreach($this->spreadsheet as $tabName => $etiquetas) { foreach($etiquetas as $etiquetaId => $etiContent) { $subFields = $etiContent->subFields; if(!$subFields) { continue; } foreach ($subFields as $content) { if(is_null($content->rulesToComplete)) { continue; } $originalField = str_replace(".", "_", "spreeadsheetField_{$content->rulesToComplete->originField}"); $destinField = str_replace(".", "_", "spreeadsheetField_{$content->rulesToComplete->fateField}"); $rule = $content->rulesToComplete->affectRecordsCompleted == 't' ? 'true' : 'false'; $code.= " autoCompleteMarcFields_{$originalField} = function(e) { var originalField = '$originalField'; var destinFields = '$destinField'; var rule = $rule; if(!document.getElementById(originalField)) return; if(!document.getElementById(destinFields)) return; var key = e.keyCode; var key2 = e.which; var keychar = String.fromCharCode(key2); if(typeof copy_{$originalField} == 'undefined' && !rule) { copy_{$originalField} = false; if(document.getElementById(destinFields).value.length == 0) { copy_{$originalField} = true; } } if(rule) { document.getElementById(destinFields).value = document.getElementById(originalField).value; } else if(copy_{$originalField}) { document.getElementById(destinFields).value = document.getElementById(originalField).value; } } "; } } } if(is_null($code)) { return; } $this->addJsCode($code); } /** * Método reescrito chamado ao apertar F2 * */ public function onkeydown113() { $MIOLO = MIOLO::getInstance(); $module = MIOLO::getCurrentModule(); //verifica se existe um código leader na url, caso tiver, é porque está inserindo um material diferente do padrão $leaderString = MIOLO::_REQUEST('leaderString'); if ( $leaderString ) { $url = $MIOLO->getActionURL($module, "main:catalogue:material&frm__mainForm__EVENTTARGETVALUE=tbBtnNew:click&function=dinamicMenu&leaderString={$leaderString}"); } else { $url = $MIOLO->getActionURL($module, "main:catalogue:material&frm__mainForm__EVENTTARGETVALUE=tbBtnNew:click&function=new"); } $MIOLO->page->redirect($url); } /** * Método reescrito para chamar o método que salvar a catalogação * */ public function onkeydown114($args) //F3 save { if ( !$args->leaderFields ) { $this->saveSpreadsheet($args); } else { $this->setResponse(null, 'limbo'); } } /** * Chama a pré-catalogação ao apertar a tecla F8 * */ public function onkeydown119($args) //F8 pre-catalogue { if ( (in_array($this->function, array('insert', 'new', 'dinamicMenu')) || $this->isPreCatalogue()) && ($args->wasSaved != 't') && (!$args->leaderFields) ) { $this->saveSpreadsheetPreCatalogue($args); } else { $this->setResponse(null, 'limbo'); } } /** * Método reescrito para não limpar com a tecla F7 * */ public function onkeydown118() { $this->setResponse('','limbo'); } } ?>