http://dumpz.org/9259/

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
//////////////////////////////////////////////////////////////////////////////////////////////////
require_once('mvcinput.php');
define ( 'ADD' , true );
define ( 'REWRITE' , false );
class FormController {
/**
* Required Values
*
* @var string $name
* @var string $title
*/
public $name;
public $header;
/**
* Optional Values
*
* @var string $info
*/
private $info;
/**
* System Values
*
* @var string $errors
*/
private $errors;
/**
* $items - array with form items
*
* @var unknown_type
*/
private $items = array();
/**
* Model and View for the input
*
* @var object $model
* @var object $view
*/
private $model;
private $view;
function __construct( $name = 'form' , $header = '' ) {
/********************************/
$this->name = $name;
$this->header = $header;
/********************************/
$this->error = false;
$this->result = false;
/********************************/
$name = 'form';
$model_name = $name . 'Model';
$view_name = $name . 'View';
/********************************/
$this->model = new $model_name();
$this->view = new $view_name();
}
private function GetData(){
/***********************************************/
$data['name'] = $this->name;
$data['header'] = $this->header;
$data['info'] = $this->info;
$data['errors'] = $this->errors;
$data['items'] = $this->items;
return $data;
}
function Make() {
$data = $this->GetData();
// данные отправлены
if ( $_POST['do'] == 'register_go' ) {
$this->model->Validate( $this->GetData() );
}
return $this->view->Make( $this->GetData() );
}
function AddItem( $input ){
$this->items[$input->name] = &$input;
}
/**
* Set info for the form
*
* add values:
* ADD - add the info
* REWRITE - rewrite form info
*
* @param string $info
* @param mixed $add
*/
function SetInfo( $info , $add = false ){
$info = nl2br( $info );
if ( $add ){
$this->info = $this->info . $info;
}
else {
$this->info = $info;
}
}
/**
* Echo input returned by make function
*
*/
function Display(){
echo $this->Make();
}
} // class Controller
//////////////////////////////////////////////////////////////////////////////////////////////////
class FormView {
/**
* Makes the the form
*
* @param string header
* @param string body
* @param string info
* @param string errors
*/
static function Make( $data ) {
/****************************
data array
****************************/
$name = $data['name'];
$header = $data['header'];
/***************************/
$info = $data['info'];
$items = $data['items'];
$validated = $data['validated'];
/***************************/
$errors = '';
$body = '';
/***************************/
foreach ( $items as $item ){
$body .= '
<li>
' . $item->Make() .'
</li>
';
if ( $error = $item->GetErrorMessage() ){
$errors .= $error . "<br/>\n";
}
}
/****************************
<p>aragraphs with info
****************************/
if ( $header ){
$header = '<h3>' . $header . '</h3>' . "\n";
}
if ( $info ){
$info = '<p class="info">' . "\n\t" . $info . '</p>' . "\n";
}
if ( $errors ){
$errors = '<p class="errors">' . "\n\t" . $errors . '</p>' . "\n";
}
if ( $body ){
$body = '<ul id="fieldlist">' . "\n\t" . $body . "\n" . '</ul>' . "\n";
}
return '
<fieldset id="' . $name . '">
' . $header . '
<form action="" method="post" enctype="multipart/form-data">
<input type="hidden" name="do" value="register_go" />
' . $info
. $errors
. $body . '
<span class="hide">Поля отмеченные звездочкой( * ) обязательны для заполнения.</span>
<div class="button"><input type="submit" name="submit" value="Зарегистрироваться" /></div>
</form>
</fieldset>
';
}
} // class View
//////////////////////////////////////////////////////////////////////////////////////////////////
class FormModel {
public $data;
function __construct() {
$this->data = false;
}
function Validate( $data ) {
$items = $data['items'];
foreach ( $items as $item ){
$item->Validate();
}
}
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru" lang="ru">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="style.css" title="base" />
<script type="text/javascript" src="../jQuery/jquery.js"></script>
<script type="text/javascript" src="../jQuery/roundCorners.jQuery.js"></script>
<style>
label {
color: #66f;
margin: 0px 0px 6px 0px;
width:30%;
border: 2px ridge #669;
background-color: #ffc;
clear: none;
margin: 0px 10% 0px 20%;
}
label.normal{
border-color: yellow;
}
label.warn{
border-color: red;
}
label.good{
border-color: green;
}
input{
border: 2px ridge #669;
background: #69f;
color: #ffc;
font-weight: bold;
margin: 0px 20% 0px 10%;
width: 30%;
clear: none;
}
.button input {
background-color: #99f;
border: 2px ridge black;
width: 40%;
margin: 0px 30% 0px 30%;
}
</style>
<?
/****************************
Creating form and its elements
****************************/
$form = new FormController( 'register_msg' , 'Регистрация' );
$form->SetInfo(
'Логин и пароль должны содержать только латинские буквы и цифры.
Длина логина - до 15 символов, пароля - до 20 символов.
Поля логин, пароль и капча обязательны к заполнению, E-Mail опционально.' );
$login = new InputController('login','Логин');
$login->SetRegExpPattern('/\d/i');
$login->SetRequired ( REQUIRED );
$password = new InputController('password','Пароль','password');
$password->SetRequired ( REQUIRED );
$email = new InputController('email','EMail');
$email->SetRegExpPattern('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i');
$form->AddItem( $login );
$form->AddItem( $password );
$form->AddItem( $email );
$form->Display();
echo '<script type="text/javascript">$(\'.normal\').roundCorners();</script>';
function CapitalsToUnderscore( $string ){
$string = (string)$string;
$string = preg_replace( '/([A-Z])/e' , '_.strtolower($1)' , $string);
if ( $string[0] == '_' ){
$string = substr( $string , 1 );
}
return $string;
}
echo CapitalsToUnderscore( 'RandOmlYCapitaliZEDstringOo' );