Created
April 6, 2015 21:05
-
-
Save alooze/bb77e5c08e99b0090c18 to your computer and use it in GitHub Desktop.
Плагин добавления полей веб-юзерам http://alooze.com.ua/zametki/manager-webuser-plugin.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//<?php | |
/** | |
* wuManager plugin | |
* | |
* @properties &wuFormReplace=Заменить поля пользователей;textarea;country~hide||mobilephone~rename~Номер клиента||street~rename~Наименование организации||street~rename~Адрес||fax~rename~Скидка||city~rename~ОГРН||state~rename~ИНН||zip~rename~КПП||dob~hide||gender~hide | |
&jqPath=Путь к jQuery;text;http://code.jquery.com/jquery-latest.js | |
&addSumAfter=Показать сумму покупок после поля;text;fax | |
* @internal @events OnWebPageInit,OnWebLogout,OnWUsrFormRender | |
*/ | |
$e = $modx->event; | |
$debug = 0; | |
switch ($e->name) { | |
case 'OnWUsrFormRender': | |
// вносим изменения в форму редактирования веб-юзера | |
if (isset($wuFormReplace) && $wuFormReplace != '') { | |
$fldAr = explode('||', $wuFormReplace); | |
$output = "\n<!-- cartBackend plugin -->\n"; | |
$output.= '<script src="'.$jqPath.'" type="text/javascript"></script>'."\n"; | |
$output.= '<script> | |
window.$j = jQuery.noConflict();'."\n"; | |
$output.= ' var additObj = {}; | |
var cval = $j("[name=comment]").val(); | |
if (undefined != cval && cval != "") { | |
additObj = JSON.parse(cval); | |
} | |
'."\n"; | |
foreach ($fldAr as $str) { | |
list($fld, $act, $newName) = explode('~', $str); | |
if ($act == 'hide') { | |
$output.= "\$j('[name=".trim($fld)."]').parents('tr').hide();"."\n"; | |
} | |
if ($act == 'rename') { | |
if ($fld == $addSumAfter) { | |
$sum = 1000; | |
$output.= "\$j('[name=".trim($fld)."]').parents('tr').children(':first').html('".trim($newName)." (".trim($fld).")<br> (<b>Сумма покупок</b>: ".$sum." руб)');"."\n"; | |
} else { | |
$output.= "\$j('[name=".trim($fld)."]').parents('tr').children(':first').text('".trim($newName)." (".trim($fld).")');"."\n"; | |
} | |
} | |
if ($act == 'add') { | |
$newFld = '<tr><td>'.$newName.' ('.$fld.')</td><td> </td><td><input type="text" name="'.$fld.'" id="'.$fld.'" class="inputBox savetocomment" value="" onchange="documentDirty=true;"></td></tr>'; | |
$output.= "\$j('[name=comment]').parents('tr').before('".$newFld."');"."\n"; | |
$output.= "if (undefined !== additObj.".$fld.") {\$j('#".$fld."').val(additObj.".$fld.");}"; | |
$output.= "\$j('#".$fld."').on('change', function(){additObj.".$fld."=\$j(this).val(); \$j('[name=comment]').val(JSON.stringify(additObj));});"."\n"; | |
} | |
} | |
$output.= '</script>'."\n"; | |
$output.= "\n<!-- END cartBackend plugin -->\n"; | |
} | |
break; | |
case 'OnWebPageInit': | |
$user = $modx->getLoginUserID('web'); | |
if (!$user) { | |
$ph['userid'] = '00'; | |
$ph['internalKey'] = '00'; | |
$ph['email'] = ''; | |
} else { | |
$ph = $modx->getWebUserInfo($user); | |
$ph['dob'] = date('d.m.Y', $ph['dob']); | |
$ph2 = json_decode($ph['comment']); | |
foreach ($ph2 as $key => $value) { | |
$ph[$key] = str_replace('"', '\'', $value); | |
} | |
$ph['comment'] = ''; | |
} | |
$modx->toPlaceholders($ph, 'user.'); | |
break; | |
case 'OnWebLogout': | |
// сбрасываем плейсхолдеры пользователя | |
$ph['userid'] = '00'; | |
$ph['internalKey'] = '00'; | |
$ph['email'] = ''; | |
$modx->toPlaceholders($ph, 'user.'); | |
break; | |
} | |
$e->output($output); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment