static function renderUpdateFormBackend(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 = ''; $active = isset($_POST['active']) ? strip_tags($_POST['active']) : (isset($user) ? $user->getActive() : false); $company_id = isset($_POST['company_id']) ? strip_tags($_POST['company_id']) : (isset($user) ? $user->getCompanyId() : ''); $company_options = ""; foreach (Company::findAll() as $company) { $id = $company->getId(); $name = $company->getName(); $company_options .= "<option value='{$id}' " . ($id == $company_id ? 'selected' : '') . ">{$name}</option>"; } $mandatory_label = ' <span style="color: rgb(185,2,0); font-weight: bold;">*</span>'; $roles_form_markup = '<div id="form-field-roles"><label>Roles</label><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>'; $rtn = ' <form action="' . $action . '" method="POST" id="adduser" 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-company"> <label for="company">' . i18n(array('en' => 'Company', 'zh' => '公司')) . $mandatory_label . '</label> <select class="form-control" name="company_id"> ' . $company_options . ' </select> </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) : '') . ' <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> <input type="hidden" value=1 name="noemailnotification" /> ' . (is_backend() ? $roles_form_markup : '') . ' <div class="form-group" id="form-field-notice"><small><i> ' . $mandatory_label . i18n(array('en' => ' indicates mandatory fields', 'zh' => ' 标记为必填项')) . ' </i></small></div> <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> </form> '; return $rtn; }