Example #1
0
 /**
  * Generate Select Box Element
  *
  * @param  array  $aInput
  * @return string
  */
 function genInputFiles(&$aInput, $sInfo = '', $sError = '')
 {
     bx_import('BxDolUploader');
     $sUniqId = genRndPwd(8, false);
     $sUploaders = '';
     $oUploader = null;
     foreach ($aInput['uploaders'] as $sUploaderObject) {
         $oUploader = BxDolUploader::getObjectInstance($sUploaderObject, $aInput['storage_object'], $sUniqId);
         if (!$oUploader) {
             continue;
         }
         $sGhostTemplate = false;
         if (isset($aInput['ghost_template']) && is_object($aInput['ghost_template'])) {
             // form is not submitted and ghost template is BxDolFormNested object
             $oFormNested = $aInput['ghost_template'];
             if ($oFormNested instanceof BxDolFormNested) {
                 $sGhostTemplate = $oFormNested->getCode();
             }
         } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && isset($aInput['ghost_template']['inputs'])) {
             // form is not submitted and ghost template is form array
             bx_import('BxDolFormNested');
             $oFormNested = new BxDolFormNested($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
             $sGhostTemplate = $oFormNested->getCode();
         } elseif (isset($aInput['ghost_template']) && is_array($aInput['ghost_template']) && $aInput['ghost_template']) {
             // form is submitted and ghost template is array of BxDolFormNested objects
             bx_import('BxDolFormNested');
             $sGhostTemplate = array();
             foreach ($aInput['ghost_template'] as $iFileId => $oFormNested) {
                 if (is_object($oFormNested) && $oFormNested instanceof BxDolFormNested) {
                     $sGhostTemplate[$iFileId] = $oFormNested->getCode();
                 }
             }
         } elseif (isset($aInput['ghost_template']) && is_string($aInput['ghost_template'])) {
             // ghost template is just string template, without nested form
             $sGhostTemplate = $aInput['ghost_template'];
         }
         $aParams = array('button_title' => bx_js_string($oUploader->getUploaderButtonTitle(isset($aInput['upload_buttons_titles']) ? $aInput['upload_buttons_titles'] : false)), 'content_id' => isset($aInput['content_id']) ? $aInput['content_id'] : '');
         if (isset($aInput['images_transcoder']) && $aInput['images_transcoder']) {
             $aParams['images_transcoder'] = bx_js_string($aInput['images_transcoder']);
         }
         $sUploaders .= $oUploader->getUploaderButton($sGhostTemplate, isset($aInput['multiple']) ? $aInput['multiple'] : true, $aParams);
     }
     return $this->oTemplate->parseHtmlByName('form_field_uploader.html', array('uploaders_buttons' => $sUploaders, 'info' => $sInfo, 'error' => $sError, 'id_container_errors' => $oUploader ? $oUploader->getIdContainerErrors() : '', 'id_container_result' => $oUploader ? $oUploader->getIdContainerResult() : '', 'uploader_instance_name' => $oUploader ? $oUploader->getNameJsInstanceUploader() : '', 'is_init_ghosts' => isset($aInput['init_ghosts']) && !$aInput['init_ghosts'] ? 0 : 1));
 }
Example #2
0
 function _initCheckerNestedForms()
 {
     $isValid = true;
     // process nested forms
     foreach ($this->aInputs as $sKey => $aInput) {
         if (isset($aInput['type']) && $aInput['type'] != 'files' || !isset($aInput['ghost_template'])) {
             continue;
         }
         if (!(is_array($aInput['ghost_template']) && isset($aInput['ghost_template']['inputs'])) && !(is_object($aInput['ghost_template']) && $aInput['ghost_template'] instanceof BxDolFormNested)) {
             continue;
         }
         $sName = $aInput['name'];
         $aIds = $this->getSubmittedValue($sName, $this->aFormAttrs['method']);
         if (!$aIds) {
             continue;
         }
         $aNestedForms = array();
         foreach ($aIds as $i => $iFileId) {
             // create separate form instance for each file
             $oFormNested = false;
             if (is_object($aInput['ghost_template'])) {
                 $oFormNested = clone $aInput['ghost_template'];
             } else {
                 $oFormNested = new BxDolFormNested($aInput['name'], $aInput['ghost_template'], $this->aParams['db']['submit_name'], $this->oTemplate);
             }
             $aNestedForms[$iFileId] = $oFormNested;
             // collect nested form values
             $aSpecificValues = array();
             if (isset($this->aParams['db']['submit_name'])) {
                 $aSpecificValues = array($this->aParams['db']['submit_name'] => 1);
             }
             foreach ($oFormNested->aInputs as $r) {
                 $sName = str_replace('[]', '', $r['name']);
                 $aValue = $this->getSubmittedValue($sName, $this->aFormAttrs['method']);
                 $aSpecificValues[$sName] = $aValue[$i];
             }
             $oFormNested->initChecker(array(), $aSpecificValues);
             // if nested form in invalid - then the whole worm is failed
             if (!$oFormNested->isValid()) {
                 $isValid = false;
             }
         }
         if ($aNestedForms) {
             $this->aInputs[$sKey]['ghost_template'] = $aNestedForms;
         }
     }
     return $isValid;
 }