'save','b_cancel' => 'list', 'b_pre' => 'pre'); $aState['edit'] = array ('b_cancel' => 'list', 'b_pre' => 'pre'); $aState['else'] = array ('b_new' => 'new', 'else' => 'list'); include_once( D_CMS_INC.'func.cms.php'); setStateAction($STATE, $aState, $ACTION); } $pass = 0; while ($ACTION) { if($pass++ > 10) { $INFO[] = array (1, 'Max. Iteration überschritten.'); break; } $ac = $ACTION; $ACTION = ''; switch ($ac) { case 'save' : safeVars($_POST); if(!validateForm( $INFO, $_POST, $obligatoryCsv)){ $STATE = 'edit'; break; } $crc = generateCrc($_POST, $varsCsv); if($_POST['crc'] !== $crc) { $INFO[] = array (1, 'Nach Änderungen bitte erst den Button Vorschau benutzen !'); $STATE = 'edit'; break; } $in = copyVars($_POST, $varsCsv); $in['_name'] = date('Y-m-d G:i:s '). $in['Name']; $in['_expire'] = 'unlimited'; if (!addLine(TYP_GUESTBOOK_ENTRY, $in)) { $INFO[] = array (1, 'Fehler beim Speichern !'); } else { $ACTION = 'list'; } break; case 'new' : $STATE = 'edit'; break; case 'pre' : safeVars($_POST); if(!validateForm( $INFO, $_POST, $obligatoryCsv)){ $STATE = 'edit'; break; } $_POST['crc'] = generateCrc($_POST, $varsCsv); $entry = $_POST; $STATE = $ac; break; case 'list' : $where = ''; $aList = getLines(TYP_GUESTBOOK_ENTRY, $where, '_modified desc'); $STATE = $ac; break; default: break; } } if(!$STATE) $STATE = 'list'; $_POST['ST'] = $STATE; //---- Outputview ---- include_once (D_MOD.$moduleName.'/'.'header.tpl.php'); $HTML .= '
'; if( $INFO ) $HTML .= genInfo( $INFO); include_once (D_MOD.$moduleName.'/'.$STATE.'.view.php'); $HTML .= '
'; //---- Model ---- function validateForm( &$INFO, &$form, $obligatoryCsv){ $ret = true; $aObligatory = explode(',', $obligatoryCsv); foreach ( $aObligatory as $value ) { if(!isset($form[$value]) or !$form[$value]) { $INFO[] = array( 1, 'Bitte füllen Sie folgende Felder aus : '. $value); $ret = false; } } return $ret; } function copyVars( &$a, $fieldsCsv){ $ret = array(); $aVars = explode(',', $fieldsCsv); foreach ( $aVars as $var ) { $ret[$var] = $a[$var]; } return $ret; } function generateCrc( &$a, $fieldsCsv){ $aVars = explode(',', $fieldsCsv); $s = ''; foreach ( $aVars as $var ) { $s .= $a[$var]; } return( md5( md5($s).'guest')); }