static function renderUpdateForm(SiteUser $user = null, $exclude_fields = array()) { $settings = Vars::getSettings(); $profile = $user ? $user->getProfile() : null; // get vars from form submission $nickname = isset($_POST['nickname']) ? strip_tags($_POST['nickname']) : (isset($profile) ? $profile->getNickname() : ''); $mandatory_label = ' <span style="color: rgb(185,2,0); font-weight: bold;">*</span>'; $avatar_field = ' <div class="form-group" id="form-field-avatar" > <label for="avatar">' . i18n(array('en' => 'Avatar', 'zh' => '头像')) . ' <small style="font-weight: normal;"><i>(' . i18n(array('en' => 'optional', 'zh' => '可选')) . ')</i></small></label> ' . ($profile ? "<div><img src='" . $profile->getThumbnailUrl() . "' alt='" . $user->getUsername() . "' style='cursor: pointer;' /></div>" : '') . ' <input type="file" id="avatar" name="avatar"' . ($profile ? ' style="display: none;"' : '') . ' /> <small>' . i18n(array('en' => 'Max image file size: ' . round($settings['profile']['avatar_max_size'] / 1000000, 1) . 'MB', 'zh' => '最大图片上传尺寸: ' . round($settings['profile']['avatar_max_size'] / 1000000, 1) . 'MB')) . '</small> </div> '; $rtn = ' <div class="form-group" id="form-field-nickname"> <label for="nickname">' . i18n(array('en' => 'Nick name', 'zh' => '昵称')) . $mandatory_label . ' <small style="font-weight: normal;"><i>(' . i18n(array('en' => 'what others see you as', 'zh' => '其他用户看到的您的称呼')) . ')</i></small></label> <input type="text" class="form-control" id="nickname" name="nickname" value="' . $nickname . '" required placeholder="" /> </div>' . (in_array('avatar', $exclude_fields) ? '' : $avatar_field) . ' <script type="text/javascript"> $("#form-field-avatar img").click(function(){ $("#avatar").trigger("click"); }); $("#avatar").change(function(){ //$("#form-field-avatar img").fadeOut(); $(this).fadeIn(); }); </script> '; return $rtn; }
static function renderSignupForm(SiteUser $user = null, $action = '', $exclude_fields = array()) { // set default action value if ($action != '') { $action = uri($action); } // get vars from form submission $username = isset($_POST['username']) ? strip_tags($_POST['username']) : (isset($user) ? $user->getUsername() : ''); $email = isset($_POST['email']) ? strip_tags($_POST['email']) : (isset($user) ? $user->getEmail() : ''); $password = ''; $password_confirm = ''; $active = isset($_POST['active']) ? strip_tags($_POST['active']) : (isset($user) ? $user->getActive() : false); $mandatory_label = ' <span style="color: rgb(185,2,0); font-weight: bold;">*</span>'; $active_field = ' <div class="checkbox" id="form-field-active"> <label> <input type="checkbox" id="active" name="active" value="1" ' . ($active == false ? '' : 'checked="checked"') . '> ' . i18n(array('en' => 'Active?', 'zh' => '有效用户')) . ' </label> </div> '; $rtn = Message::renderMessages() . ' <form action="' . $action . '" method="POST" id="signup" enctype="multipart/form-data"> <div class="form-group" id="form-field-username"> <label for="username">' . i18n(array('en' => 'Username', 'zh' => '用户名')) . $mandatory_label . ' <small style="font-weight: normal;"><i>(' . i18n(array('en' => 'alphabetical letters, number or underscore', 'zh' => '英文字母,数字或下划线')) . ')</i></small></label> <input type="text" class="form-control" id="username" name="username" value="' . $username . '" required placeholder="" /> </div> <div class="form-group" id="form-field-email" > <label for="email">' . i18n(array('en' => 'Email', 'zh' => '电子邮箱')) . $mandatory_label . '</label> <input type="email" class="form-control" id="email" name="email" value="' . $email . '" required /> </div> <div class="form-group" id="form-field-password"> <label for="password">' . i18n(array('en' => 'Password', 'zh' => '密码')) . $mandatory_label . ' <small style="font-weight: normal;"><i>(' . i18n(array('en' => 'at least 6 letters', 'zh' => '至少6位')) . ')</i></small></label> <input type="password" class="form-control" id="password" name="password" value="' . $password . '" required /> </div> <div class="form-group" id="form-field-password_confirm"> <label for="password_confirm">' . i18n(array('en' => 'Password again', 'zh' => '再次确认密码')) . $mandatory_label . '</label> <input type="password" class="form-control" id="password_confirm" name="password_confirm" value="' . $password_confirm . '" required /> </div> ' . (class_exists('SiteProfile') ? SiteProfile::renderUpdateForm($user, $exclude_fields) : '') . (in_array('active', $exclude_fields) ? '' : $active_field) . ' <div class="form-group" id="form-field-notice"><small><i> ' . $mandatory_label . i18n(array('en' => ' indicates mandatory fields', 'zh' => ' 标记为必填项')) . ' </i></small></div> <input type="submit" name="submit" class="btn btn-primary btn-block disabled" value="' . i18n(array('en' => 'Signup', 'zh' => '注册')) . '" /> ' . (module_enabled('form') ? Form::loadSpamToken('#signup', SITEUSER_FORM_SPAM_TOKEN) : '') . ' </form> '; return $rtn; }
static function renderUpdateFormFrontend(SiteUser $user = null, $action = '') { // set default action value if ($action != '') { $action = uri($action); } // get vars from form submission $username = isset($_POST['username']) ? strip_tags($_POST['username']) : (isset($user) ? $user->getUsername() : ''); $email = isset($_POST['email']) ? strip_tags($_POST['email']) : (isset($user) ? $user->getEmail() : ''); $password = ''; $password_confirm = ''; if ($user && $user->getId() == MySiteUser::getCurrentUser()->getId()) { // when updating self profile, we don't include 'active' $active_field = ''; } else { $active = isset($_POST['active']) ? strip_tags($_POST['active']) : (isset($user) ? $user->getActive() . "" : false); $active_field = ' <div class="form-group" id="form-field-active"> <label class="col-sm-2 control-label" for="active">' . i18n(array('en' => 'Active', 'zh' => '是否在职')) . '</label> <div class="col-sm-10"> <select class="form-control" name="active" id="active"> <option value="1" ' . ($active == "1" ? 'selected=selected' : '') . '>在职</option> <option value="0" ' . ($active == "0" ? 'selected=selected' : '') . '>离职</option> </select> </div> </div> <div class="hr-line-dashed"></div>'; } $mandatory_label = ' <span style="color: rgb(185,2,0); font-weight: bold;">*</span>'; $roles_form_markup = '<div id="form-field-roles"><label class="col-sm-2 control-label">Roles</label><div class="col-sm-10"><ul class="checkbox">'; foreach (SiteRole::findAll() as $role) { $roles_form_markup .= '<li><label><input type="checkbox" name="roles[' . $role->getid() . ']" value=1 ' . (isset($_POST['roles']) ? isset($_POST['roles'][$role->getId()]) ? 'checked="checked"' : '' : ($user && $user->hasRole($role->getName()) ? 'checked="checked"' : '')) . ' />' . $role->getName() . '</label></li>'; } $roles_form_markup .= '</ul></div></div>'; $rtn = ' <form class="form-horizontal" action="' . $action . '" method="POST" enctype="multipart/form-data"> <div class="form-group" id="form-field-email" > <label class="col-sm-2 control-label" for="email">' . i18n(array('en' => 'Email', 'zh' => '电子邮箱')) . $mandatory_label . '</label> <div class="col-sm-10"> <input type="email" class="form-control" id="email" name="email" value="' . $email . '" required /> </div> </div> <div class="hr-line-dashed"></div> <div class="form-group" id="form-field-password"> <label class="col-sm-2 control-label" for="password">' . i18n(array('en' => 'Password', 'zh' => '密码')) . $mandatory_label . ' </label> <div class="col-sm-10"> <input type="password" class="form-control" id="password" name="password" value="' . $password . '" required /> <span class="help-block m-b-none"><small>(' . i18n(array('en' => 'at least 6 letters', 'zh' => '至少6位')) . ')</small></span> </div> </div> <div class="form-group" id="form-field-password_confirm"> <label class="col-sm-2 control-label" for="password_confirm">' . i18n(array('en' => 'Password again', 'zh' => '再次确认密码')) . $mandatory_label . '</label> <div class="col-sm-10"> <input type="password" class="form-control" id="password_confirm" name="password_confirm" value="' . $password_confirm . '" required /> </div> </div> <div class="hr-line-dashed"></div> ' . (class_exists('SiteProfile') ? SiteProfile::renderUpdateForm($user) : '') . ' <div class="hr-line-dashed"></div> ' . $active_field . ' <input type="hidden" value=1 name="noemailnotification" /> ' . (is_backend() ? $roles_form_markup : '') . ' <div class="form-group" id="form-field-notice"> <div class="col-sm-10 col-sm-push-2"> <small><i> ' . $mandatory_label . i18n(array('en' => ' indicates mandatory fields', 'zh' => ' 标记为必填项')) . ' </i></small> </div> </div> <div class="col-sm-10 col-sm-push-2"> <button type="submit" name="submit" class="btn btn-primary">' . (is_null($user) ? i18n(array('en' => 'Add new user', 'zh' => '添加新用户')) : i18n(array('en' => 'Update user', 'zh' => '更新用户'))) . '</button> </div> </form> '; return $rtn; }