18 return CMap::mergeArray(parent::filters(), array(
33 'actions' => array(
'*'),
34 'users' => array(
'*'),
37 'actions' => array(
'create',
'update',
'view',
'admin',
'delete'),
41 'users' => array(
'*'),
51 $this->render(
'view', array(
61 $basePath = Yii::getPathOfAlias(
'application.modules.user.views.asset');
62 $baseUrl = Yii::app()->getAssetManager()->publish($basePath);
63 $cs = Yii::app()->getClientScript();
64 $cs->registerCoreScript(
'jquery');
65 $cs->registerCssFile(
$baseUrl.
'/css/redmond/jquery-ui.css');
67 $cs->registerScriptFile(
$baseUrl.
'/js/jquery-ui.min.js');
69 $cs->registerScriptFile(
$baseUrl.
'/js/jquery.json.js');
74 foreach ($wgByTypes as $k => $v) {
75 $wgByTypes[$k] = array();
78 foreach ($widgets[1] as $widget) {
79 if (isset($widget[
'fieldType']) && count($widget[
'fieldType'])) {
80 foreach ($widget[
'fieldType'] as $type) {
81 array_push($wgByTypes[$type], $widget[
'name']);
88 var name = $('#name'),
90 allFields = $([]).add(name).add(value),
91 tips = $('.validateTips');
93 var listWidgets = jQuery.parseJSON('".str_replace(
"'",
"\'", CJavaScript::jsonEncode($widgets[0])).
"');
94 var widgets = jQuery.parseJSON('".str_replace(
"'",
"\'", CJavaScript::jsonEncode($widgets[1])).
"');
95 var wgByType = jQuery.parseJSON('".str_replace(
"'",
"\'", CJavaScript::jsonEncode($wgByTypes)).
"');
99 'hide':['match','other_validator','widgetparams'],
108 'hide':['widgetparams'],
117 'hide':['field_size','range','widgetparams'],
126 'hide':['field_size','field_size_min','match','range','widgetparams'],
129 'default':'0000-00-00',
135 'hide':['match','other_validator','widgetparams'],
144 'hide':['match','other_validator','widgetparams'],
153 'hide':['field_size','field_size_min','match','widgetparams'],
162 'hide':['field_size','field_size_min','match','widgetparams'],
171 'hide':['field_size','field_size_min','match','widgetparams'],
181 function showWidgetList(type) {
182 $('div.widget select').empty();
183 $('div.widget select').append('<option value=\"\">".
UserModule::t(
'No').
"</option>');
184 if (wgByType[type]) {
185 for (var k in wgByType[type]) {
186 $('div.widget select').append('<option value=\"'+wgByType[type][k]+'\">'+widgets[wgByType[type][k]]['label']+'</option>');
191 function setFields(type) {
192 if (fieldType[type]) {
193 if (".((isset($_GET[
'id'])) ? 0 : 1).
") {
194 showWidgetList(type);
195 $('#widgetlist option:first').attr('selected', 'selected');
198 $('div.row').addClass('toshow').removeClass('tohide');
199 if (fieldType[type].hide.length) $('div.'+fieldType[type].hide.join(', div.')).addClass('tohide').removeClass('toshow');
200 if ($('div.widget select').val()) {
201 $('div.widgetparams').removeClass('tohide');
203 $('div.toshow').show(500);
204 $('div.tohide').hide(500);
205 ".((!isset($_GET[
'id'])) ?
"
206 for (var k in fieldType[type].val) {
207 $('div.'+k+' input').val(fieldType[type].val[k]);
212 function isArray(obj) {
213 if (obj.constructor.toString().indexOf('Array') == -1)
219 $('#dialog-form').dialog({
228 $('#dialog-form fieldset .wparam').each(function(){
229 if ($(this).val()) wparam[$(this).attr('name')] = $(this).val();
232 var tab = $('#tabs ul li.ui-tabs-selected').text();
234 $('#dialog-form fieldset .tab-'+tab).each(function(){
235 if ($(this).val()) fparam[tab][$(this).attr('name')] = $(this).val();
238 if ($.JSON.encode(wparam)!='{}') $('div.widgetparams input').val($.JSON.encode(wparam));
239 if ($.JSON.encode(fparam[tab])!='{}') $('div.other_validator input').val($.JSON.encode(fparam));
241 $(this).dialog('close');
244 $(this).dialog('close');
252 $('#widgetparams').focus(function() {
253 var widget = widgets[$('#widgetlist').val()];
255 var wparam = ($('div.widgetparams input').val())?$.JSON.decode($('div.widgetparams input').val()):{};
256 var fparam = ($('div.other_validator input').val())?$.JSON.decode($('div.other_validator input').val()):{};
259 for (var k in widget.params) {
260 html += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';
261 html += '<input type=\"text\" name=\"'+k+'\" id=\"widget_'+k+'\" class=\"text wparam ui-widget-content ui-corner-all\" value=\"'+((wparam[k])?wparam[k]:widget.params[k])+'\" />';
264 if (widget.other_validator) {
267 for (var t in widget.other_validator) {
268 tabs += '<div id=\"tab-'+t+'\" class=\"tab\">';
269 li += '<li'+((fparam[t])?' class=\"ui-tabs-selected\"':'')+'><a href=\"#tab-'+t+'\">'+t+'</a></li>';
271 for (var k in widget.other_validator[t]) {
272 tabs += '<label for=\"name\">'+((widget.paramsLabels[k])?widget.paramsLabels[k]:k)+'</label>';
273 if (isArray(widget.other_validator[t][k])) {
274 tabs += '<select type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\">';
275 for (var i in widget.other_validator[t][k]) {
276 tabs += '<option value=\"'+widget.other_validator[t][k][i]+'\"'+((fparam[t]&&fparam[t][k])?' selected=\"selected\"':'')+'>'+widget.other_validator[t][k][i]+'</option>';
280 tabs += '<input type=\"text\" name=\"'+k+'\" id=\"filter_'+k+'\" class=\"text fparam ui-widget-content ui-corner-all tab-'+t+'\" value=\"'+((fparam[t]&&fparam[t][k])?fparam[t][k]:widget.other_validator[t][k])+'\" />';
285 html += '<div id=\"tabs\"><ul>'+li+'</ul>'+tabs+'</div>';
288 $('#dialog-form fieldset').html(html);
293 $('#dialog-form').dialog('open');
296 $('#field_type').change(function() {
297 setFields($(this).val());
300 $('#widgetlist').change(function() {
302 $('div.widgetparams').show(500);
304 $('div.widgetparams').hide(500);
310 $('div.form p.note').append('<br/><a href=\"#\" id=\"showAll\">".
UserModule::t(
'Show all').
"</a>');
311 $('#showAll').click(function(){
312 $('div.row').show(500);
317 setFields($('#field_type').val());
320 $cs->registerScript(__CLASS__.
'#dialog', $js);
330 $scheme = get_class(Yii::app()->db->schema);
331 if (isset($_POST[
'ProfileField'])) {
332 $model->attributes = $_POST[
'ProfileField'];
334 if ($model->validate()) {
335 $sql =
'ALTER TABLE '.Profile::model()->tableName().
' ADD `'.$model->varname.
'` ';
336 $sql .= $this->
fieldType($model->field_type);
338 $model->field_type !=
'TEXT'
339 && $model->field_type !=
'DATE'
340 && $model->field_type !=
'BOOL'
341 && $model->field_type !=
'BLOB'
342 && $model->field_type !=
'BINARY'
344 $sql .=
'('.$model->field_size.
')';
346 $sql .=
' NOT NULL ';
348 if ($model->field_type !=
'TEXT' && $model->field_type !=
'BLOB' || $scheme !=
'CMysqlSchema') {
349 if ($model->default) {
350 $sql .=
" DEFAULT '".$model->default.
"'";
353 $model->field_type ==
'TEXT'
354 || $model->field_type ==
'VARCHAR'
355 || $model->field_type ==
'BLOB'
356 || $model->field_type ==
'BINARY'
357 ) ?
" DEFAULT ''" : (($model->field_type ==
'DATE') ?
" DEFAULT '0000-00-00'" :
" DEFAULT 0"));
360 $model->dbConnection->createCommand($sql)->execute();
362 $this->redirect(array(
'view',
'id' => $model->id));
367 $this->render(
'create', array(
379 if (isset($_POST[
'ProfileField'])) {
380 $model->attributes = $_POST[
'ProfileField'];
381 if ($model->save()) {
382 $this->redirect(array(
'view',
'id' => $model->id));
387 $this->render(
'update', array(
398 if (Yii::app()->request->isPostRequest) {
400 $scheme = get_class(Yii::app()->db->schema);
402 if ($scheme ==
'CSqliteSchema') {
404 unset($attr[$model->varname]);
405 $attr = array_keys($attr);
406 $connection = Yii::app()->db;
407 $transaction = $connection->beginTransaction();
411 $connection->createCommand(
412 "CREATE TEMPORARY TABLE ".
Profile::model()->tableName().
"_backup (".implode(
',', $attr).
")"
415 $connection->createCommand(
419 $connection->createCommand(
423 $connection->createCommand(
424 "CREATE TABLE ".
Profile::model()->tableName().
" (".implode(
',', $attr).
")"
427 $connection->createCommand(
431 $connection->createCommand(
435 $transaction->commit();
436 }
catch (Exception $e) {
437 $transaction->rollBack();
444 $sql =
'ALTER TABLE '.Profile::model()->tableName().
' DROP `'.$model->varname.
'`';
445 if ($model->dbConnection->createCommand($sql)->execute()) {
451 if (!isset($_POST[
'ajax'])) {
452 $this->redirect(array(
'admin'));
455 throw new CHttpException(400,
'Invalid request. Please do not repeat this request again.');
465 $model->unsetAttributes();
466 if (isset($_GET[
'ProfileField'])) {
467 $model->attributes = $_GET[
'ProfileField'];
470 $this->render(
'admin', array(
494 if ($this->_model === null) {
495 if (isset($_GET[
'id'])) {
498 if ($this->_model === null) {
499 throw new CHttpException(404,
'The requested page does not exist.');
515 $type = str_replace(
'UNIX-DATE',
'INTEGER', $type);
522 $basePath = Yii::getPathOfAlias(
'application.modules.user.components');
525 if (self::$_widgets) {
529 while (
false !== ($file = $d->read())) {
530 if (strpos($file,
'UW') === 0) {
531 list($className) = explode(
'.', $file);
532 if (class_exists($className)) {
533 $widgetClass =
new $className();
534 if ($widgetClass->init()) {
535 $widgets[$className] = $widgetClass->init();
537 if (in_array($fieldType, $widgets[$className][
'fieldType'])) {
538 $list[$className] = $widgets[$className][
'label'];
541 $list[$className] = $widgets[$className][
'label'];
550 return array($list,$widgets);
560 if (isset($_POST[
'ajax']) && $_POST[
'ajax'] ===
'profile-field-form') {
561 echo CActiveForm::validate($model);