107 if ( $session->AllowedTo(
"Admin") ) {
109 dbg_error_log(
"User",
":AllowedTo: Admin is always allowed to %s", $whatever );
113 switch( strtolower($whatever) ) {
116 $rc = ( $this->user_no > 0 && $session->user_no == $this->user_no );
120 $rc = ( $this->user_no > 0 && $session->user_no == $this->user_no );
123 case 'changepassword':
124 $rc = ( ($this->user_no > 0 && $session->user_no == $this->user_no)
125 || (
"insert" == $this->WriteType) );
128 case 'changeusername':
139 $rc = ( isset($session->roles[$whatever]) && $session->roles[$whatever] );
141 dbg_error_log(
"User",
":AllowedTo: %s is%s allowed to %s", (isset($this->username)?$this->username:
null), ($rc?
"":
" not"), $whatever );
166 dbg_error_log(
"User",
":Render: type=$this->WriteType, edit_mode=$this->EditMode" );
168 $ef =
new EntryForm( $REQUEST_URI, $this->Values, $this->EditMode );
171 if ( $ef->EditMode ) {
172 $html .= $ef->StartForm( array(
"autocomplete" =>
"off" ) );
173 if ( $this->user_no > 0 ) $html .= $ef->HiddenField(
"user_no", $this->user_no );
176 $html .=
"<table width=\"100%\" class=\"data\" cellspacing=\"0\" cellpadding=\"0\">\n";
181 $html .=
"</table>\n";
182 if ( $ef->EditMode ) {
183 $html .=
'<div id="footer">';
184 $html .= $ef->SubmitButton(
"submit", ((
"insert" == $this->WriteType) ? translate(
"Create") : translate(
"Update")) );
186 $html .= $ef->EndForm();
201 if ( $title ==
null ) $title = i18n(
"User Details");
202 $html = ( $title ==
"" ?
"" : $ef->BreakLine(translate($title)) );
204 if ( $this->
AllowedTo(
'ChangeUsername') ) {
205 $html .= $ef->DataEntryLine( translate(
"User Name"),
"%s",
"text",
"username",
206 array(
"size" => 20,
"title" => translate(
"The name this user can log into the system with.")), $this->prefix );
209 $html .= $ef->DataEntryLine( translate(
"User Name"), $this->
Get(
'username') );
211 if ( $ef->EditMode && $this->AllowedTo(
'ChangePassword') ) {
212 $this->
Set(
'new_password',
'******');
213 unset($_POST[
'new_password']);
214 $html .= $ef->DataEntryLine( translate(
"New Password"),
"%s",
"password",
"new_password",
215 array(
"size" => 20,
"title" => translate(
"The user's password for logging in.")), $this->prefix );
216 $this->
Set(
'confirm_password',
'******');
217 unset($_POST[
'confirm_password']);
218 $html .= $ef->DataEntryLine( translate(
"Confirm"),
"%s",
"password",
"confirm_password",
219 array(
"size" => 20,
"title" => translate(
"Confirm the new password.")), $this->prefix );
222 $html .= $ef->DataEntryLine( translate(
"Full Name"),
"%s",
"text",
"fullname",
223 array(
"size" => 50,
"title" => translate(
"The user's full name.")), $this->prefix );
225 $html .= $ef->DataEntryLine( translate(
"EMail"),
"%s",
"text",
"email",
226 array(
"size" => 50,
"title" => translate(
"The user's e-mail address.")), $this->prefix );
228 if ( $this->
AllowedTo(
'ChangeActive') ) {
229 $html .= $ef->DataEntryLine( translate(
"Active"), ($this->
Get(
'active') ==
't'? translate(
'Yes') : translate(
'No')),
"checkbox",
"active",
230 array(
"_label" => translate(
"User is active"),
231 "title" => translate(
"Is this user active?")), $this->prefix );
234 $html .= $ef->DataEntryLine( translate(
"Active"), ($this->
Get(
'active') ==
't'? translate(
'Yes') : translate(
'No')) );
237 $html .= $ef->DataEntryLine( translate(
"Date Style"), ($this->
Get(
'date_format_type') ==
'E' ?
'European' : ($this->
Get(
'date_format_type') ==
'U' ?
'US of A' :
'ISO 8861')),
238 "select",
"date_format_type",
239 array(
"title" => translate(
"The style of dates used for this person."),
240 "_E" => translate(
"European (d/m/y)"),
"_U" => translate(
"United States of America (m/d/y)"),
"_I" => translate(
"ISO Format (YYYY-MM-DD)") ),
243 if ( isset($c->default_locale) ) {
244 if ( $this->
Get(
'locale') ==
'' ) {
245 $this->
Set(
'locale',$c->default_locale);
247 $html .= $ef->DataEntryLine( translate(
"Language"),
"%s",
"lookup",
"locale",
248 array(
"title" => translate(
"The preferred language for this person."),
249 "_sql" =>
"SELECT locale, locale_name_locale FROM supported_locales ORDER BY locale ASC;" ),
253 $html .= $ef->DataEntryLine( translate(
"EMail OK"), $session->FormattedDate($this->Get(
'email_ok'),
'timestamp'),
"timestamp",
"email_ok",
254 array(
"title" => translate(
"When the user's e-mail account was validated.")), $this->prefix );
256 $html .= $ef->DataEntryLine( translate(
"Joined"), $session->FormattedDate($this->Get(
'joined'),
'timestamp') );
257 $html .= $ef->DataEntryLine( translate(
"Updated"), $session->FormattedDate($this->Get(
'updated'),
'timestamp') );
258 $html .= $ef->DataEntryLine( translate(
"Last used"), $session->FormattedDate($this->Get(
'last_used'),
'timestamp') );
273 if ( $title ==
null ) $title = i18n(
"User Roles");
274 $html = ( $title ==
"" ?
"" : $ef->BreakLine(translate($title)) );
276 $html .=
'<tr><th class="prompt">'.translate(
"User Roles").
'</th><td class="entry">';
277 if ( $ef->EditMode ) {
278 $sql =
"SELECT role_name FROM roles ";
279 if ( ! ($session->AllowedTo(
'Admin') ) ) {
280 $sql .=
"NATURAL JOIN role_member WHERE user_no=$session->user_no ";
282 $sql .=
"ORDER BY roles.role_no";
284 $ef->record->roles = array();
288 if ( $q && $q->Exec(
"User") && $q->rows() ) {
290 while( $row = $q->Fetch() ) {
291 @dbg_error_log(
"User",
":RenderRoles: Is a member of '%s': %s", $row->role_name, $this->roles[$row->role_name] );
292 $ef->record->roles[$row->role_name] = ( isset($this->roles[$row->role_name]) ? $this->roles[$row->role_name] :
'f');
293 $html .= $ef->DataEntryField(
"",
"checkbox",
"roles[$row->role_name]",
294 array(
"title" => translate(
"Does the user have the right to perform this role?"),
295 "_label" => translate($row->role_name) ) );
301 foreach( $this->roles AS $k => $v ) {
302 if ( $i++ > 0 ) $html .=
", ";
306 $html .=
'</td></tr>'.
"\n";
351 if ( parent::Write() ) {
352 $c->messages[] = i18n(
'User record written.');
353 if ( $this->WriteType ==
'insert' ) {
354 $qry =
new AwlQuery(
"SELECT currval('usr_user_no_seq');" );
355 $qry->Exec(
"User::Write");
356 $sequence_value = $qry->Fetch(
true);
357 $this->user_no = $sequence_value[0];
360 if ( $this->user_no == $session->user_no && $this->Get(
"date_format_type") != $session->date_format_type ) {
362 $session->date_format_type = $this->
Get(
"date_format_type");
363 unset($_POST[
'email_ok']);
364 $qry =
new AwlQuery(
"SET DATESTYLE TO ?;", ($this->
Get(
"date_format_type") ==
'E' ?
'European,ISO' : ($this->
Get(
"date_format_type") ==
'U' ?
'US,ISO' :
'ISO')) );