{result}

{message}

{listing}
{formheader}{form}{formfooter}
'; var $form_header = ''; var $form_footer = ''; var $no_entries_message = ''; var $create_message = 'Create a new entry'; var $create_canceled_message = 'Creating a new entry was canceled.'; var $created_message = 'A new entry was created successfully.'; var $update_message = 'Update this entry'; var $update_canceled_message = 'Updating an entry was canceled.'; var $updated_message = 'The entry was updated successfully.'; var $save = 'save'; var $save_label = 'Save'; var $cancel = 'cancel'; var $cancel_label = 'Cancel'; var $invalid_mark = '[X]'; var $fields = array(); var $columns = array(); var $rows = array(); var $listing_style = ''; var $listing_class = ''; var $highlight_row_color = ''; var $highlight_row_class = ''; var $odd_row_color = ''; var $odd_row_class = ''; var $even_row_color = ''; var $even_row_class = ''; var $create = 1; var $read = 1; var $update = 1; var $delete = 1; var $preview = 1; var $update_label = 'Update'; var $id_column; var $create_parameter; var $update_parameter; var $state = ''; var $entry; Function HasEntries(&$has_entries) { $has_entries = (count($this->rows)!=0); return(''); } Function AddActionParameter($action, $parameter, $value) { return($action.(GetType(strpos($action, '?')) == 'integer' ? '&' : '?').UrlEncode($parameter).'='.UrlEncode($value)); } Function GetListing(&$form, &$listing) { $ro = $this->rows; $co = $this->columns; $tc = count($co); $listing = 'listing_class) ? ' class="'.$this->listing_class.'"' : '').''.(strlen($this->listing_style) ? ' style="'.$this->listing_style.'"' : '').">\n\n"; for($style = array(), $c = 0; $c < $tc; ++$c) { $style[$c] = (IsSet($co[$c]['Style']) ? ' style="'.HtmlSpecialChars($co[$c]['Style']).'"' : '').(IsSet($co[$c]['Class']) ? ' class="'.HtmlSpecialChars($co[$c]['Class']).'"' : ''); if(IsSet($co[$c]['HTML']) && !$co[$c]['HTML']) Unset($co[$c]['HTML']); $listing .= ''; if(IsSet($co[$c]['Header'])) $listing .= $co[$c]['Header']; $listing .= "\n"; } $listing .= "\n"; $highlight = ((strlen($this->highlight_row_color) || strlen($this->highlight_row_class)) ? ' onmouseover="'.HtmlSpecialChars((strlen($this->highlight_row_class) ? 'this.className='.$form->EncodeJavascriptString($this->highlight_row_class).';' : '').(strlen($this->highlight_row_color) ? 'this.style.backgroundColor='.$form->EncodeJavascriptString($this->highlight_row_color).';' : '')).'"' : ''); $lowlight = ((strlen($this->odd_row_color) || strlen($this->odd_row_class)) ? ' onmouseout="'.HtmlSpecialChars((strlen($this->odd_row_class) ? 'this.className='.$form->EncodeJavascriptString($this->odd_row_class).';' : '').(strlen($this->odd_row_color) ? 'this.style.backgroundColor='.$form->EncodeJavascriptString($this->odd_row_color).';' : '')).'"' : ''); $odd_rows = (strlen($this->odd_row_class) ? ' class="'.$this->odd_row_class.'"' : '').(strlen($this->odd_row_color) ? ' style="background-color: '.$this->odd_row_color.'"' : '').$highlight.$lowlight; $lowlight = ((strlen($this->even_row_color) || strlen($this->even_row_class)) ? ' onmouseout="'.HtmlSpecialChars((strlen($this->even_row_class) ? 'this.className='.$form->EncodeJavascriptString($this->even_row_class).';' : '').(strlen($this->even_row_color) ? 'this.style.backgroundColor='.$form->EncodeJavascriptString($this->even_row_color).';' : '')).'"' : ''); $even_rows = (strlen($this->even_row_class) ? ' class="'.$this->even_row_class.'"' : '').(strlen($this->even_row_color) ? ' style="background-color: '.$this->even_row_color.'"' : '').$highlight.$lowlight; $tr = count($ro); for($r = 0; $r < $tr; ++$r) { $listing .= '\n"; for($c = 0; $c < $tc; ++$c) { $listing .= ''; if(IsSet($co[$c]['Update'])) { $id = $co[$c]['Update']; $data = ''.$this->update_label.''; } else { $d = (IsSet($co[$c]['Column']) ? $co[$c]['Column'] : $c); if(IsSet($ro[$r][$d])) $data = $ro[$r][$d]; else $data = (IsSet($co[$c]['MapNull']) ? $co[$c]['MapNull'] : ''); if(IsSet($co[$c]['Map'][$data])) $data = $co[$c]['Map'][$data]; if(IsSet($co[$c]['HTML'])) $data = HtmlSpecialChars($data); } $listing .= $data."\n"; } $listing .= "\n"; } $listing .= "\n"; return(''); } Function SetColumns($columns) { if($this->update) { $has_update = 0; Unset($id); $tc = count($this->columns); for($c = 0; $c < $tc; ++$c) { if(IsSet($columns[$c]['Update'])) $has_update = 0; if(IsSet($columns[$c]['ID'])) $id = $c; } if(!IsSet($id)) { if(!IsSet($this->id_column)) return('it was not specified the column from where the ID value would be taken to update entries'); $id = $this->id_column; } if($this->update) { $columns[] = array( 'Update'=>$id ); } } $this->columns = $columns; return(''); } Function SetIDColumn($column) { if(GetType($column) != 'integer' || $column < 0) return('it was not specified a valid id column'); $this->id_column = $column; return(''); } Function AddInput(&$form, $arguments) { if(IsSet($arguments['Create'])) $this->create = intval($arguments['Create']); if(IsSet($arguments['Read'])) $this->read = intval($arguments['Read']); if(IsSet($arguments['Update'])) $this->update = intval($arguments['Update']); if(IsSet($arguments['Delete'])) $this->delete = intval($arguments['Delete']); if(IsSet($arguments['Preview'])) $this->preview = intval($arguments['Preview']); if($this->create) { if(IsSet($arguments['CreateMessage'])) $this->create_message = $arguments['CreateMessage']; if(IsSet($arguments['CreateCanceledMessage'])) $this->create_canceled_message = $arguments['CreateCanceledMessage']; if(IsSet($arguments['CreatedMessage'])) $this->created_message = $arguments['CreatedMessage']; } if($this->read) { if(IsSet($arguments['NoEntriesMessage'])) $this->no_entries_message = $arguments['NoEntriesMessage']; if(IsSet($arguments['ListingClass'])) $this->listing_class = $arguments['ListingClass']; if(IsSet($arguments['ListingStyle'])) $this->listing_style = $arguments['ListingStyle']; if(IsSet($arguments['HighlightRowListingClass'])) $this->highlight_row_class = $arguments['HighlightRowListingClass']; if(IsSet($arguments['HighlightRowListingColor'])) $this->highlight_row_color = $arguments['HighlightRowListingColor']; if(IsSet($arguments['OddRowListingClass'])) $this->odd_row_class = $arguments['OddRowListingClass']; if(IsSet($arguments['OddRowListingColor'])) $this->odd_row_color = $arguments['OddRowListingColor']; if(IsSet($arguments['EvenRowListingClass'])) $this->even_row_class = $arguments['EvenRowListingClass']; if(IsSet($arguments['EvenRowListingColor'])) $this->even_row_color = $arguments['EvenRowListingColor']; if(IsSet($arguments['Rows'])) $this->rows = $arguments['Rows']; if(IsSet($arguments['IDColumn']) && strlen($error = $this->SetIDColumn($arguments['IDColumn']))) return($error); if(IsSet($arguments['Columns']) && strlen($error = $this->SetColumns($arguments['Columns']))) return($error); } if($this->create) { if(IsSet($arguments['InvalidMark'])) { if(strlen($arguments['InvalidMark']) == 0) return('it was not specified an invalid mark'); $this->invalid_mark = $arguments['InvalidMark']; } if(!IsSet($arguments['EntryFields']) || ($tf = count($fields = $arguments['EntryFields'])) == 0) return('it were not specified any entry fields'); for($f = 0; $f < $tf; ++$f) { $field_arguments = $fields[$f]; if(!IsSet($field_arguments[$key = 'ID']) && !IsSet($field_arguments[$key = 'NAME'])) return('it was not specified the identifier of the field '.$f); $id = $field_arguments[$key]; if(!strcmp($id, $this->cancel) && !IsSet($field_arguments['SubForm'])) $field_arguments['SubForm'] = $this->cancel; $field_arguments['NoParent'] = 1; if(strlen($error = $form->AddInput($field_arguments))) return($error); $this->fields[$id] = $field_arguments; } $this->create_parameter = $this->GenerateInputID($form, $this->input, 'create'); if(strlen($error = $form->AddInput(array( 'TYPE'=>'hidden', 'NAME'=>$this->create_parameter, 'ID'=>$this->create_parameter, 'VALUE'=>'1')))) return($error); } if($this->update) { if(IsSet($arguments['UpdateMessage'])) $this->update_message = $arguments['UpdateMessage']; if(IsSet($arguments['UpdateCanceledMessage'])) $this->update_canceled_message = $arguments['UpdateCanceledMessage']; if(IsSet($arguments['UpdatedMessage'])) $this->updated_message = $arguments['UpdatedMessage']; $this->update_parameter = $this->GenerateInputID($form, $this->input, 'update'); if(strlen($error = $form->AddInput(array( 'TYPE'=>'hidden', 'NAME'=>$this->update_parameter, 'ID'=>$this->update_parameter, 'VALUE'=>'1')))) return($error); } if($this->create || $this->update) { if(!IsSet($this->fields[$this->save]) && strlen($error = $form->AddInput(array( 'TYPE'=>'submit', 'NAME'=>$this->save, 'ID'=>$this->save, 'VALUE'=>$this->save_label)))) return($error); if(!IsSet($this->fields[$this->cancel]) && strlen($error = $form->AddInput(array( 'TYPE'=>'submit', 'NAME'=>$this->cancel, 'ID'=>$this->cancel, 'VALUE'=>$this->cancel_label, 'SubForm'=>$this->cancel)))) return($error); } return(''); } Function AddInputPart(&$form) { if(($this->create && ($creating = !strcmp($this->state, 'creating'))) || ($this->update && !strcmp($this->state, 'updating'))) { $this->valid_marks['data']['listing'] = ''; $inputs = $properties = array(); $tf = count($this->fields); for($f = 0, Reset($this->fields); $f < $tf; Next($this->fields), ++$f) { switch($input = Key($this->fields)) { case $this->save: case $this->cancel: continue 2; } $inputs[] = $input; switch($this->fields[$input]['TYPE']) { case 'checkbox': case 'radio': $properties[$input] = array( 'SwitchedPosition'=>1 ); break; } } $inputs[] = $this->save; $properties[$this->save] = array( 'CenteredGroup'=>'left', ); $inputs[] = $this->cancel; $properties[$this->cancel] = array( 'CenteredGroup'=>'right', ); $layout = $this->GenerateInputID($form, $this->input, 'layout'); $form->AddInput(array( 'ID'=>$layout, 'TYPE'=>'custom', "CustomClass"=>"form_layout_vertical_class", 'Inputs'=>$inputs, 'Properties'=>$properties, 'InvalidMark'=>$this->invalid_mark, )); $this->valid_marks['data']['result'] = ''; $this->valid_marks['data']['message'] = ($creating ? $this->create_message : $this->update_message); $this->valid_marks['data']['formheader'] = $this->form_header; $this->valid_marks['data']['formfooter'] = $this->form_footer; $this->valid_marks['input']['form'] = $layout; if($creating) { if(strlen($error = $form->AddInputPart($this->create_parameter))) return($error); } else { if(strlen($error = $form->SetInputValue($this->update_parameter, $_REQUEST[$this->update_parameter])) || strlen($error = $form->AddInputPart($this->update_parameter))) return($error); } } elseif($this->read && strlen($error = $this->HasEntries($has_entries))) return($error); else { switch($this->state) { case 'created': $message = $this->created_message; break; case 'updated': $message = $this->updated_message; break; case 'create_canceled': $message = $this->create_canceled_message; break; case 'update_canceled': $message = $this->update_canceled_message; break; default: $message = ''; break; } $this->valid_marks['data']['result'] = $message; if(!$this->read || !$has_entries) { $this->valid_marks['data']['listing'] = ''; $this->valid_marks['data']['message'] = ($this->read ? $this->no_entries_message : ''); } else { if(strlen($error = $this->GetListing($form, $this->valid_marks['data']['listing']))) return($error); $this->valid_marks['data']['message'] = ''; } $this->valid_marks['data']['formheader'] = $this->valid_marks['data']['formfooter'] = ''; $this->valid_marks['data']['form'] = ($this->create ? '
'.$this->create_message.'
' : ''); } return(parent::AddInputPart($form)); } Function LoadInputValues(&$form, $submitted) { if(IsSet($_REQUEST[$this->create_parameter])) { if(strlen($form->WasSubmitted($this->cancel))) $this->state = 'create_canceled'; elseif(strlen($form->WasSubmitted($this->save))) $this->state = 'created'; else $this->state = 'creating'; } elseif(IsSet($_REQUEST[$this->update_parameter])) { $this->entry = $_REQUEST[$this->update_parameter]; if(strlen($form->WasSubmitted($this->cancel))) $this->state = 'update_canceled'; elseif(strlen($form->WasSubmitted($this->save))) $this->state = 'updated'; else $this->state = 'updating'; } } Function SetInputProperty(&$form, $property, $value) { switch($property) { case 'FormHeader': $this->form_header = $value; break; case 'FormFooter': $this->form_footer = $value; break; case 'State': switch($value) { case '': case 'created': case 'create_canceled': case 'creating': case 'updated': case 'update_canceled': case 'updating': $this->state = $value; break; default: return($value.' is not a valid scaffolding state'); } break; case 'Rows': $this->rows = $value; break; case 'IDColumn': return($this->SetIDColumn($value)); case 'Columns': return($this->SetColumns($value)); break; default: return($this->DefaultSetInputProperty($form, $property, $value)); } return(''); } Function GetInputProperty(&$form, $property, &$value) { switch($property) { case "State": $value = $this->state; break; case "Entry": $value = $this->entry; break; default: return($this->DefaultGetInputProperty($form, $property, $value)); } } }; ?>