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
    • ContentRssCreator
    • ContentSitemapHtml
    • ContentSitemapXml
    • ContentUserForum
    • NavigationTop
    • ScriptCookieDirective
  • mpAutoloaderClassMap
  • None
  • Plugin
    • ContentAllocation
    • CronjobOverview
    • FormAssistant
    • FrontendLogic
    • FrontendUsers
    • Linkchecker
    • ModRewrite
    • Newsletter
    • Repository
      • FrontendNavigation
      • KeywordDensity
    • SearchSolr
    • 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
  • SolrRightBottomPage

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