Overview

Packages

  • CONTENIDO
  • Core
    • Authentication
    • Backend
    • Cache
    • CEC
    • Chain
    • ContentType
    • Database
    • Debug
    • Exception
    • Frontend
      • Search
      • URI
      • Util
    • GenericDB
      • Model
    • GUI
      • HTML
    • I18N
    • LayoutHandler
    • Log
    • Security
    • Session
    • Util
    • Validation
    • Versioning
    • XML
  • Module
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • PHP
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SmartyWrapper
    • UrlShortener
    • UserForum
    • Workflow
  • PluginManager
  • Setup
    • Form
    • GUI
    • Helper
      • Environment
      • Filesystem
      • MySQL
      • PHP
    • UpgradeJob

Classes

  • cContentTypePifaForm
  • DefaultFormModule
  • DefaultFormProcessor
  • ExampleOptionsDatasource
  • MailedFormProcessor
  • Pifa
  • PifaAbstractFormModule
  • PifaAbstractFormProcessor
  • PifaAjaxHandler
  • PifaExporter
  • PifaExternalOptionsDatasourceInterface
  • PifaField
  • PifaFieldCollection
  • PifaForm
  • PifaFormCollection
  • PifaImporter
  • PifaLeftBottomPage
  • PifaRightBottomFormDataPage
  • PifaRightBottomFormExportPage
  • PifaRightBottomFormFieldsPage
  • PifaRightBottomFormImportPage
  • PifaRightBottomFormPage

Exceptions

  • PifaDatabaseException
  • PifaException
  • PifaIllegalStateException
  • PifaMailException
  • PifaNotImplementedException
  • PifaNotYetStoredException
  • PifaValidationException
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  *
  5:  * @package Plugin
  6:  * @subpackage FormAssistant
  7:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
  8:  * @copyright four for business AG
  9:  * @link http://www.4fb.de
 10:  */
 11: 
 12: // assert CONTENIDO framework
 13: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
 14: 
 15: /**
 16:  * Class for area "form_ajax" handling all Ajax requests for the PIFA backend.
 17:  *
 18:  * @author Marcus Gnaß <marcus.gnass@4fb.de>
 19:  */
 20: class PifaAjaxHandler {
 21: 
 22:     /**
 23:      * Action constant to display a form for editing a PIFA form field.
 24:      *
 25:      * @var string
 26:      */
 27:     const GET_FIELD_FORM = 'pifa_get_field_form';
 28: 
 29:     /**
 30:      * Action constant to process a form for editing a PIFA form field.
 31:      *
 32:      * @var string
 33:      */
 34:     const POST_FIELD_FORM = 'pifa_post_field_form';
 35: 
 36:     /**
 37:      * Action constant.
 38:      *
 39:      * @var string
 40:      */
 41:     const REORDER_FIELDS = 'pifa_reorder_fields';
 42: 
 43:     /**
 44:      * Action constant.
 45:      *
 46:      * @var string
 47:      */
 48:     const EXPORT_DATA = 'pifa_export_data';
 49: 
 50:     /**
 51:      * Action constant.
 52:      *
 53:      * @var string
 54:      */
 55:     const EXPORT_FORM = 'pifa_export_form';
 56: 
 57:     /**
 58:      * Action constant.
 59:      *
 60:      * @var string
 61:      */
 62:     const IMPORT_FORM = 'pifa_import_form';
 63: 
 64:     /**
 65:      * Action constant.
 66:      *
 67:      * @var string
 68:      */
 69:     const GET_FILE = 'pifa_get_file';
 70: 
 71:     /**
 72:      * Action constant.
 73:      *
 74:      * @var string
 75:      */
 76:     const DELETE_FIELD = 'pifa_delete_field';
 77: 
 78:     /**
 79:      * Action constant.
 80:      *
 81:      * @var string
 82:      */
 83:     const GET_OPTION_ROW = 'pifa_get_option_row';
 84: 
 85:     /**
 86:      *
 87:      * @throws PifaException if action is unknown
 88:      */
 89:     function dispatch($action) {
 90:         global $area;
 91: 
 92:         // check for permission
 93:         if (!cRegistry::getPerm()->have_perm_area_action($area, $action)) {
 94:             $msg = Pifa::i18n('NO_PERMISSIONS');
 95:             throw new PifaIllegalStateException($msg);
 96:         }
 97: 
 98:         switch ($action) {
 99: 
100:             case self::GET_FIELD_FORM:
101:                 // display a form for editing a PIFA form field
102:                 $idform = cSecurity::toInteger($_GET['idform']);
103:                 $idfield = cSecurity::toInteger($_GET['idfield']);
104:                 $fieldType = cSecurity::toInteger($_GET['field_type']);
105:                 $this->_getFieldForm($idform, $idfield, $fieldType);
106:                 break;
107: 
108:             case self::POST_FIELD_FORM:
109:                 // process a form for editing a PIFA form field
110:                 $idform = cSecurity::toInteger($_POST['idform']);
111:                 $idfield = cSecurity::toInteger($_POST['idfield']);
112:                 // $this->_editFieldForm($idform, $idfield);
113:                 $this->_postFieldForm($idform, $idfield);
114:                 break;
115: 
116:             case self::DELETE_FIELD:
117:                 $idfield = cSecurity::toInteger($_GET['idfield']);
118:                 $this->_deleteField($idfield);
119:                 break;
120: 
121:             case self::REORDER_FIELDS:
122:                 $idform = cSecurity::toInteger($_POST['idform']);
123:                 $idfields = implode(',', array_map('cSecurity::toInteger', explode(',', $_POST['idfields'])));
124:                 $this->_reorderFields($idform, $idfields);
125:                 break;
126: 
127:             case self::EXPORT_DATA:
128:                 $idform = cSecurity::toInteger($_GET['idform']);
129:                 $this->_exportData($idform);
130:                 break;
131: 
132:             case self::EXPORT_FORM:
133:                 $idform = cSecurity::toInteger($_POST['idform']);
134:                 $withData = 'on' === $_POST['with_data'];
135:                 $this->_exportForm($idform, $withData);
136:                 break;
137: 
138:             case self::IMPORT_FORM:
139:                 $xml = $_FILES['xml'];
140:                 $this->_importForm($xml);
141:                 break;
142: 
143:             case self::GET_FILE:
144:                 $name = cSecurity::toString($_GET['name']);
145:                 $file = cSecurity::toString($_GET['file']);
146:                 $this->_getFile($name, $file);
147:                 break;
148: 
149:             case self::GET_OPTION_ROW:
150:                 $index = cSecurity::toInteger($_GET['index']);
151:                 $this->_getOptionRow($index);
152:                 break;
153: 
154:             default:
155:                 $msg = Pifa::i18n('UNKNOWN_ACTION');
156:                 // Util::log(get_class($this) . ': ' . $msg . ': ' . $action);
157:                 throw new PifaException($msg);
158:         }
159:     }
160: 
161:     /**
162:      * Displays a form for editing a PIFA form field.
163:      *
164:      * @param int $idform
165:      * @param int $idfield
166:      * @param int $fieldType
167:      * @throws PifaException
168:      */
169:     private function _getFieldForm($idform, $idfield, $fieldType) {
170:         $cfg = cRegistry::getConfig();
171: 
172:         // get field
173:         if (0 < $idfield) {
174:             // edit existing field
175:             $field = new PifaField();
176:             $field->loadByPrimaryKey($idfield);
177:         } elseif (0 < $fieldType) {
178:             // create new field by type
179:             $field = new PifaField();
180:             $field->loadByRecordSet(array(
181:                 'field_type' => $fieldType
182:             ));
183:         } else {
184:             // bugger off
185:             // TODO check error message
186:             $msg = Pifa::i18n('FORM_CREATE_ERROR');
187:             throw new PifaException($msg);
188:         }
189: 
190:         // get option classes
191:         $optionClasses = Pifa::getExtensionClasses('PifaExternalOptionsDatasourceInterface');
192:         array_unshift($optionClasses, array(
193:             'value' => '',
194:             'label' => Pifa::i18n('none')
195:         ));
196: 
197:         // create form
198:         $tpl = cSmartyBackend::getInstance(true);
199: 
200:         // translations
201:         $tpl->assign('trans', array(
202:             'idfield' => Pifa::i18n('ID'),
203:             'fieldRank' => Pifa::i18n('RANK'),
204:             'fieldType' => Pifa::i18n('FIELD_TYPE'),
205:             'columnName' => Pifa::i18n('COLUMN_NAME'),
206:             'label' => Pifa::i18n('LABEL'),
207:             'displayLabel' => Pifa::i18n('DISPLAY_LABEL'),
208:             'defaultValue' => Pifa::i18n('DEFAULT_VALUE'),
209:             'helpText' => Pifa::i18n('HELP_TEXT'),
210:             'rule' => Pifa::i18n('VALIDATION_RULE'),
211:             'errorMessage' => Pifa::i18n('ERROR_MESSAGE'),
212:             'database' => Pifa::i18n('DATABASE'),
213:             'options' => Pifa::i18n('OPTIONS'),
214:             'general' => Pifa::i18n('GENERAL'),
215:             'obligatory' => Pifa::i18n('OBLIGATORY'),
216:             'value' => Pifa::i18n('VALUE'),
217:             'addOption' => Pifa::i18n('ADD_OPTION'),
218:             'submitValue' => Pifa::i18n('SAVE'),
219:             'styling' => Pifa::i18n('STYLING'),
220:             'cssClass' => Pifa::i18n('CSS_CLASS'),
221:             'uri' => Pifa::i18n('URI'),
222:             'externalOptionsDatasource' => Pifa::i18n('EXTERNAL_OPTIONS_DATASOURCE'),
223:             'deleteAll' => Pifa::i18n('DELETE_CSS_CLASSES')
224:         ));
225: 
226:         // hidden form values (requires right to store form field)
227:         if (cRegistry::getPerm()->have_perm_area_action('form_ajax', self::POST_FIELD_FORM)) {
228:             $tpl->assign('contenido', cRegistry::getBackendSessionId());
229:             $tpl->assign('action', self::POST_FIELD_FORM);
230:             $tpl->assign('idform', $idform);
231:         }
232: 
233:         // field
234:         $tpl->assign('field', $field);
235: 
236:         // CSS classes
237:         $tpl->assign('cssClasses', explode(',', getEffectiveSetting('pifa', 'field-css-classes', 'half-row,full-row,line-bottom,line-top')));
238: 
239:         // option classes (external options datasources)
240:         $tpl->assign('optionClasses', $optionClasses);
241: 
242:         // build href to add new option row (requires right to add option)
243:         if (cRegistry::getPerm()->have_perm_area_action('form_ajax', self::POST_FIELD_FORM) && cRegistry::getPerm()->have_perm_area_action('form_ajax', self::GET_OPTION_ROW)) {
244:             $tpl->assign('hrefAddOption', 'main.php?' . implode('&', array(
245:                 'area=form_ajax',
246:                 'frame=4',
247:                 'contenido=' . cRegistry::getBackendSessionId(),
248:                 'action=' . PifaAjaxHandler::GET_OPTION_ROW
249:             )));
250:         }
251: 
252:         // path to partial template for displaying a single option row
253:         $tpl->assign('partialOptionRow', $cfg['templates']['pifa_ajax_option_row']);
254: 
255:         $tpl->display($cfg['templates']['pifa_ajax_field_form']);
256:     }
257: 
258:     /**
259:      * Processes a form for editing a PIFA form field.
260:      *
261:      * @param int $idform
262:      * @param int $idfield
263:      * @throws PifaException
264:      */
265:     private function _postFieldForm($idform, $idfield) {
266:         global $area;
267: 
268:         $string_cast_deep = function($value) {
269:             $value = cSecurity::unescapeDB($value);
270:             $value = cSecurity::toString($value);
271:             $value = trim($value);
272:             // replace comma by comma entity
273:             $value = str_replace(',', '&#44;', $value);
274:             return $value;
275:         };
276: 
277:         $cfg = cRegistry::getConfig();
278: 
279:         // load or create field
280:         if (0 < $idfield) {
281:             // load field
282:             $pifaField = new PifaField($idfield);
283:             if (!$pifaField->isLoaded()) {
284:                 $msg = Pifa::i18n('FIELD_LOAD_ERROR');
285:                 throw new PifaException($msg);
286:             }
287:             $isFieldCreated = false;
288:         } else {
289:             // get field type for new form field
290:             $fieldType = $_POST['field_type'];
291:             $fieldType = cSecurity::toInteger($fieldType);
292:             // create field
293:             $collection = new PifaFieldCollection();
294:             $pifaField = $collection->createNewItem(array(
295:                 'idform' => $idform,
296:                 'field_type' => $fieldType
297:             ));
298:             $isFieldCreated = true;
299:         }
300: 
301:         // remember old column name
302:         // will be an empty string for new fields
303:         $oldColumnName = $pifaField->get('column_name');
304: 
305:         // set the new rank of the item
306:         $fieldRank = $_POST['field_rank'];
307:         $fieldRank = cSecurity::toInteger($fieldRank);
308:         if ($fieldRank !== $pifaField->get('field_rank')) {
309:             $pifaField->set('field_rank', $fieldRank);
310:         }
311: 
312:         /*
313:          * Read item data from form, validate item data and finally set item
314:          * data. Which data is editable depends upon the field type. So certain
315:          * data will only be stored if its field is shown in the form. Never,
316:          * really never, call Item->set() if the value doesn't differ from the
317:          * previous one. Otherwise the genericDb thinks that the item is
318:          * modified and tries to store it, resulting in a return value of false!
319:          */
320: 
321:         // According to the MySQL documentation table and column names
322:         // must not be longer than 64 charcters.
323:         if ($pifaField->showField('column_name')) {
324:             $columnName = $_POST['column_name'];
325:             $columnName = cSecurity::unescapeDB($columnName);
326:             $columnName = cSecurity::toString($columnName);
327:             $columnName = trim($columnName);
328:             $columnName = cString::toLowerCase($columnName);
329:             // does not seem to work
330:             // $columnName = cString::replaceDiacritics($columnName);
331:             $columnName = preg_replace('/[^a-z0-9_]/', '_', $columnName);
332:             $columnName = cString::getPartOfString($columnName, 0, 64);
333:             if ($columnName !== $pifaField->get('column_name')) {
334:                 $pifaField->set('column_name', $columnName);
335:             }
336:         }
337: 
338:         if ($pifaField->showField('label')) {
339:             $label = $_POST['label'];
340:             $label = cSecurity::unescapeDB($label);
341:             $label = cSecurity::toString($label);
342:             $label = strip_tags($label);
343:             $label = trim($label);
344:             $label = cString::getPartOfString($label, 0, 1023);
345:             if ($label !== $pifaField->get('label')) {
346:                 $pifaField->set('label', $label);
347:             }
348:         }
349: 
350:         if ($pifaField->showField('display_label')) {
351:             $displayLabel = $_POST['display_label'];
352:             $displayLabel = cSecurity::unescapeDB($displayLabel);
353:             $displayLabel = cSecurity::toString($displayLabel);
354:             $displayLabel = trim($displayLabel);
355:             $displayLabel = 'on' === $displayLabel? 1 : 0;
356:             if ($displayLabel !== $pifaField->get('display_label')) {
357:                 $pifaField->set('display_label', $displayLabel);
358:             }
359:         }
360: 
361:         if ($pifaField->showField('uri')) {
362:             $uri = $_POST['uri'];
363:             $uri = cSecurity::unescapeDB($uri);
364:             $uri = cSecurity::toString($uri);
365:             $uri = trim($uri);
366:             $uri = cString::getPartOfString($uri, 0, 1023);
367:             if ($uri !== $pifaField->get('uri')) {
368:                 $pifaField->set('uri', $uri);
369:             }
370:         }
371: 
372:         if ($pifaField->showField('default_value')) {
373:             $defaultValue = $_POST['default_value'];
374:             $defaultValue = cSecurity::unescapeDB($defaultValue);
375:             $defaultValue = cSecurity::toString($defaultValue);
376:             $defaultValue = trim($defaultValue);
377:             $defaultValue = cString::getPartOfString($defaultValue, 0, 1023);
378:             if ($defaultValue !== $pifaField->get('default_value')) {
379:                 $pifaField->set('default_value', $defaultValue);
380:             }
381:         }
382: 
383:         if ($pifaField->showField('option_labels')) {
384:             if (array_key_exists('option_labels', $_POST) && is_array($_POST['option_labels'])) {
385:                 $optionLabels = implode(',', array_map($string_cast_deep, $_POST['option_labels']));
386:                 $optionLabels = cString::getPartOfString($optionLabels, 0, 1023);
387:             }
388:             if ($optionLabels !== $pifaField->get('option_labels')) {
389:                 $pifaField->set('option_labels', $optionLabels);
390:             }
391:         }
392: 
393:         if ($pifaField->showField('option_values')) {
394:             if (array_key_exists('option_values', $_POST) && is_array($_POST['option_values'])) {
395:                 $optionValues = implode(',', array_map($string_cast_deep, $_POST['option_values']));
396:                 $optionValues = cString::getPartOfString($optionValues, 0, 1023);
397:             }
398:             if ($optionValues !== $pifaField->get('option_values')) {
399:                 $pifaField->set('option_values', $optionValues);
400:             }
401:         }
402: 
403:         if ($pifaField->showField('help_text')) {
404:             $helpText = $_POST['help_text'];
405:             $helpText = cSecurity::unescapeDB($helpText);
406:             $helpText = cSecurity::toString($helpText);
407:             $helpText = trim($helpText);
408:             if ($helpText !== $pifaField->get('help_text')) {
409:                 $pifaField->set('help_text', $helpText);
410:             }
411:         }
412: 
413:         if ($pifaField->showField('obligatory')) {
414:             $obligatory = $_POST['obligatory'];
415:             $obligatory = cSecurity::unescapeDB($obligatory);
416:             $obligatory = cSecurity::toString($obligatory);
417:             $obligatory = trim($obligatory);
418:             $obligatory = 'on' === $obligatory? 1 : 0;
419:             if ($obligatory !== $pifaField->get('obligatory')) {
420:                 $pifaField->set('obligatory', $obligatory);
421:             }
422:         }
423: 
424:         if ($pifaField->showField('rule')) {
425:             $rule = $_POST['rule'];
426:             $rule = cSecurity::toString($rule, false);
427:             $rule = trim($rule);
428:             $rule = cString::getPartOfString($rule, 0, 1023);
429:             // check if rule is valid
430:             if (0 === cString::getStringLength($rule)) {
431:                 $pifaField->set('rule', $rule);
432:             } else if (false === @preg_match($rule, 'And always remember: the world is an orange!')) {
433:                 // PASS
434:             } else if ($rule === $pifaField->get('rule')) {
435:                 // PASS
436:             } else {
437:                 $pifaField->set('rule', $rule);
438:             }
439:         }
440: 
441:         if ($pifaField->showField('error_message')) {
442:             $errorMessage = $_POST['error_message'];
443:             $errorMessage = cSecurity::unescapeDB($errorMessage);
444:             $errorMessage = cSecurity::toString($errorMessage);
445:             $errorMessage = trim($errorMessage);
446:             $errorMessage = cString::getPartOfString($errorMessage, 0, 1023);
447:             if ($errorMessage !== $pifaField->get('error_message')) {
448:                 $pifaField->set('error_message', $errorMessage);
449:             }
450:         }
451: 
452:         if ($pifaField->showField('css_class') && array_key_exists('css_class', $_POST) && is_array($_POST['css_class'])) {
453:             $cssClass = implode(',', array_map($string_cast_deep, $_POST['css_class']));
454:             $cssClass = cString::getPartOfString($cssClass, 0, 1023);
455:         }
456:         if ($cssClass !== $pifaField->get('css_class')) {
457:             $pifaField->set('css_class', $cssClass);
458:         }
459: 
460:         if ($pifaField->showField('option_class')) {
461:             $optionClass = $_POST['option_class'];
462:             $optionClass = cSecurity::unescapeDB($optionClass);
463:             $optionClass = cSecurity::toString($optionClass);
464:             $optionClass = trim($optionClass);
465:             $optionClass = cString::getPartOfString($optionClass, 0, 1023);
466:             if ($optionClass !== $pifaField->get('option_class')) {
467:                 $pifaField->set('option_class', $optionClass);
468:             }
469:         }
470: 
471:         // store (add, drop or change) column in data table
472:         $pifaForm = new PifaForm($idform);
473:         try {
474:             $pifaForm->storeColumn($pifaField, $oldColumnName);
475:         } catch (PifaException $e) {
476:             // if column could not be created
477:             if ($isFieldCreated) {
478:                 // the field has to be deleted if its newly created
479:                 $pifaField->delete();
480:             } else {
481:                 // the field has to keep its old column name
482:                 $pifaField->set('column_name', $oldColumnName);
483:             }
484:             throw $e;
485:         }
486: 
487:         // store item
488:         if (false === $pifaField->store()) {
489:             $msg = Pifa::i18n('FIELD_STORE_ERROR');
490:             $msg = sprintf($msg, $pifaField->getLastError());
491:             throw new PifaException($msg);
492:         }
493: 
494:         // if a new field was created
495:         // younger siblings have to be moved
496:         if (true === $isFieldCreated) {
497: 
498:             // update ranks of younger siblings
499:             $sql = "-- PifaAjaxHandler->_postFieldForm()
500:                 UPDATE
501:                     " . cRegistry::getDbTableName('pifa_field') . "
502:                 SET
503:                     field_rank = field_rank + 1
504:                 WHERE
505:                     idform = " . cSecurity::toInteger($idform) . "
506:                     AND field_rank >= " . cSecurity::toInteger($fieldRank) . "
507:                     AND idfield <> " . cSecurity::toInteger($pifaField->get('idfield')) . "
508:                 ;";
509: 
510:             $db = cRegistry::getDb();
511:             if (false === $db->query($sql)) {
512:                 // false is returned if no fields were updated
513:                 // but that doesn't matter cause new field might
514:                 // have no younger siblings
515:             }
516:         }
517: 
518:         // return new row to be displayed in list
519:         $editField = new cHTMLLink();
520:         $editField->setCLink($area, 4, self::GET_FIELD_FORM);
521:         $editField->setCustom('idform', $idform);
522:         $editField = $editField->getHref();
523: 
524:         $deleteField = new cHTMLLink();
525:         $deleteField->setCLink($area, 4, self::DELETE_FIELD);
526:         $deleteField->setCustom('idform', $idform);
527:         $deleteField = $deleteField->getHref();
528: 
529:         $tpl = cSmartyBackend::getInstance(true);
530: 
531:         // translations
532:         $tpl->assign('trans', array(
533:             'edit' => Pifa::i18n('EDIT'),
534:             'delete' => Pifa::i18n('DELETE'),
535:             'obligatory' => Pifa::i18n('OBLIGATORY')
536:         ));
537: 
538:         // the field
539:         $tpl->assign('field', $pifaField);
540: 
541:         $tpl->assign('editField', $editField);
542:         $tpl->assign('deleteField', $deleteField);
543: 
544:         $tpl->display($cfg['templates']['pifa_ajax_field_row']);
545:     }
546: 
547:     /**
548:      *
549:      * @param int $idfield
550:      * @throws PifaException
551:      */
552:     private function _deleteField($idfield) {
553:         if (0 == $idfield) {
554:             $msg = Pifa::i18n('MISSING_IDFIELD');
555:             throw new PifaException($msg);
556:         }
557: 
558:         $pifaField = new PifaField($idfield);
559:         $pifaField->delete();
560:     }
561: 
562:     /**
563:      * reorder fields
564:      *
565:      * @param int $idform
566:      * @param string $idfields CSV of integers
567:      */
568:     private function _reorderFields($idform, $idfields) {
569:         PifaFieldCollection::reorder($idform, $idfields);
570:     }
571: 
572:     /**
573:      *
574:      * @param int $idform
575:      */
576:     private function _exportData($idform) {
577: 
578:         // read and echo data
579:         $pifaForm = new PifaForm($idform);
580:         $filename = $pifaForm->get('data_table') . date('_Y_m_d_H_i_s') . '.csv';
581:         $data = $pifaForm->getDataAsCsv();
582: 
583:         // prevent caching
584:         session_cache_limiter('private');
585:         session_cache_limiter('must-revalidate');
586: 
587:         // set header
588:         header('Pragma: cache');
589:         header('Expires: 0');
590:         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
591:         header('Cache-Control: private');
592:         header('Content-Type: text/csv');
593:         header('Content-Length: ' . cString::getStringLength($data));
594:         header('Content-Disposition: attachment; filename="' . $filename . '"');
595:         header('Content-Transfer-Encoding: binary');
596: 
597:         // echo payload
598:         echo $data;
599:     }
600: 
601:     /**
602:      * Create an PIFA form export file as XML and displays this as attachment
603:      * for download.
604:      *
605:      * @param int $idform of form to be exported
606:      * @param bool $withData if form data should be included
607:      */
608:     private function _exportForm($idform, $withData) {
609: 
610:         // read and echo data
611:         $pifaForm = new PifaForm($idform);
612:         $filename = $pifaForm->get('data_table') . date('_Y_m_d_H_i_s') . '.xml';
613: 
614:         $pifaExporter = new PifaExporter($pifaForm);
615:         $xml = $pifaExporter->export($withData);
616: 
617:         // prevent caching
618:         session_cache_limiter('private');
619:         session_cache_limiter('must-revalidate');
620: 
621:         // set header
622:         header('Pragma: cache');
623:         header('Expires: 0');
624:         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
625:         header('Cache-Control: private');
626:         header('Content-Type: text/xml');
627:         // header('Content-Type: application/xml');
628:         header('Content-Length: ' . cString::getStringLength($xml, '8bit'));
629:         header('Content-Disposition: attachment; filename="' . $filename . '"');
630:         header('Content-Transfer-Encoding: binary');
631: 
632:         // echo payload
633:         echo $xml;
634:     }
635: 
636:     /**
637:      *
638:      * @param string $name
639:      * @param string $file
640:      */
641:     private function _getFile($name, $file) {
642:         $cfg = cRegistry::getConfig();
643: 
644:         $path = $cfg['path']['contenido_cache'] . 'form_assistant/';
645: 
646:         $file = basename($file);
647: 
648:         header('Pragma: cache');
649:         header('Expires: 0');
650:         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
651:         header('Cache-Control: private');
652: 
653:         /*
654:          * TODO find solution application/zip works on Ubuntu 12.04 but has
655:          * problems on XP/IE7/IE8 application/octet-stream works on XP/IE7/IE8
656:          * but has problems on Ubuntu 12.04
657:          */
658:         header('Content-Type: application/octet-stream');
659: 
660:         header('Content-Length: ' . filesize($path . $file));
661:         header('Content-Disposition: attachment; filename="' . $name . '"');
662:         header('Content-Transfer-Encoding: binary');
663: 
664:         $buffer = '';
665:         $handle = fopen($path . $file, 'rb');
666:         if (false === $handle) {
667:             return false;
668:         }
669:         while (!feof($handle)) {
670:             print fread($handle, 1 * (1024 * 1024));
671:             ob_flush();
672:             flush();
673:         }
674:         fclose($handle);
675:     }
676: 
677:     /**
678:      *
679:      * @param int $index
680:      */
681:     private function _getOptionRow($index) {
682:         $cfg = cRegistry::getConfig();
683: 
684:         $tpl = cSmartyBackend::getInstance(true);
685: 
686:         // translations
687:         $tpl->assign('trans', array(
688:             'label' => Pifa::i18n('LABEL'),
689:             'value' => Pifa::i18n('VALUE')
690:         ));
691: 
692:         $tpl->assign('i', $index);
693: 
694:         // option
695:         $tpl->assign('option', array(
696:             'label' => '',
697:             'value' => ''
698:         ));
699: 
700:         $tpl->display($cfg['templates']['pifa_ajax_option_row']);
701:     }
702: }
703: 
704: ?>
705: 
CMS CONTENIDO 4.10.0 API documentation generated by ApiGen 2.8.0