SetLookup( 'date_format_type', "SELECT 'E', 'European' UNION SELECT 'U', 'US Format' UNION SELECT 'I', 'ISO Format'" ); $editor->SetLookup( 'type_id', 'SELECT principal_type_id, principal_type_desc FROM principal_type ORDER BY principal_type_id' ); $editor->SetLookup( 'locale', 'SELECT \'\', \''.translate("*** Default Locale ***").'\' UNION SELECT locale, locale_name_locale FROM supported_locales ORDER BY 1 ASC' ); $editor->AddAttribute( 'locale', 'title', translate("The preferred language for this person.") ); $editor->AddAttribute( 'fullname', 'title', translate("The full name for this person, group or other type of principal.") ); param_to_global('id', 'int', 'old_id', 'principal_id' ); $editor->SetWhere( 'principal_id='.$id ); $editor->AddField('is_admin', 'EXISTS( SELECT 1 FROM role_member WHERE role_no = 1 AND role_member.user_no = dav_principal.user_no )' ); $editor->AddAttribute('is_admin', 'title', translate('An "Administrator" user has full rights to the whole DAViCal System')); $privilege_names = array( 'read', 'write-properties', 'write-content', 'unlock', 'read-acl', 'read-current-user-privilege-set', 'bind', 'unbind', 'write-acl', 'read-free-busy', 'schedule-deliver-invite', 'schedule-deliver-reply', 'schedule-query-freebusy', 'schedule-send-invite', 'schedule-send-reply', 'schedule-send-freebusy' ); $delete_collection_confirmation_required = null; $delete_principal_confirmation_required = null; function handle_subaction( $subaction ) { global $session, $c, $id, $editor, $delete_collection_confirmation_required, $delete_principal_confirmation_required; dbg_error_log('admin-principal-edit',':handle_action: Action %s', $subaction ); switch( $subaction ) { case 'delete_collection': dbg_error_log('admin-principal-edit',':handle_action: Deleting collection %s for principal %d', $_GET['dav_name'], $id ); if ( $session->AllowedTo('Admin') || ($id > 0 && $session->principal_id == $id) ) { if ( $session->CheckConfirmationHash('GET', 'confirm') ) { dbg_error_log('admin-principal-edit',':handle_action: Allowed to delete collection %s for principal %d', $_GET['dav_name'], $id ); $qry = new AwlQuery('DELETE FROM collection WHERE dav_name=?;', $_GET['dav_name'] ); if ( $qry->Exec() ) { $c->messages[] = i18n('Collection deleted'); return true; } else { $c->messages[] = i18n('There was an error writing to the database.'); return false; } } else { $c->messages[] = i18n('Please confirm deletion of collection - see below'); $delete_collection_confirmation_required = $session->BuildConfirmationHash('GET', 'confirm'); return false; } } break; case 'delete_principal': dbg_error_log('admin-principal-edit',':handle_action: Deleting principal %d', $id ); if ( $session->AllowedTo('Admin') ) { if ( $session->CheckConfirmationHash('GET', 'confirm') ) { dbg_error_log('admin-principal-edit',':handle_action: Allowed to delete principal %d -%s', $id, $editor->Value('username') ); $qry = new AwlQuery('DELETE FROM dav_principal WHERE principal_id=?;', $id ); if ( $qry->Exec() ) { $c->messages[] = i18n('Principal deleted'); return true; } else { $c->messages[] = i18n('There was an error writing to the database.'); return false; } } else { $c->messages[] = i18n('Please confirm deletion of the principal'); $delete_principal_confirmation_required = $session->BuildConfirmationHash('GET', 'confirm'); return false; } } break; default: return false; } return false; } if ( isset($_GET['subaction']) ) { handle_subaction($_GET['subaction']); } $can_write_principal = ($session->AllowedTo('Admin') || $session->principal_id == $id ); $post_values = false; if ( isset($_POST['xxxxusername']) ) { $_POST['xxxxusername'] = trim(str_replace('/', '', $_POST['xxxxusername'])); if ( $_POST['xxxxusername'] == '' ) { $c->messages[] = i18n("The username must not be blank, and may not contain a slash"); $can_write_principal = false; } }; if ( isset($_POST['fullname']) && trim($_POST['fullname']) == '' ) { $c->messages[] = i18n("The full name must not be blank."); $can_write_principal = false; }; if ( isset($_POST['email']) && trim($_POST['email']) == '' ) { $c->messages[] = i18n("The email address really should not be blank."); } $pwstars = '@@@@@@@@@@'; if ( $can_write_principal && $editor->IsSubmit() ) { $editor->WhereNewRecord( "principal_id=(SELECT CURRVAL('dav_id_seq'))" ); if ( ! $session->AllowedTo('Admin') ) { unset($_POST['admin_role']); unset($_POST['user_active']); } unset($_POST['password']); if ( $_POST['newpass1'] != '' && $_POST['newpass1'] != $pwstars ) { if ( $_POST['newpass1'] == $_POST['newpass2'] ) { $_POST['password'] = $_POST['newpass1']; } else { $c->messages[] = "Password not updated. The supplied passwords do not match."; } } if ( isset($_POST['fullname']) && !isset($_POST['displayname']) ) { $_POST['displayname'] = $_POST['fullname']; } if ( isset($_POST['default_privileges']) ) { $privilege_bitpos = array_flip($privilege_names); $priv_names = array_keys($_POST['default_privileges']); $privs = privilege_to_bits($priv_names); $_POST['default_privileges'] = sprintf('%024s',decbin($privs)); $editor->Assign('default_privileges', $privs_dec); } if ( $editor->IsCreate() ) { $c->messages[] = i18n("Creating new Principal record."); } else { $c->messages[] = i18n("Updating Principal record."); } $editor->Write(); if ( $_POST['type_id'] != 3 && $editor->IsCreate() ) { /** We only add the default calendar if it isn't a group, and this is a create action */ require_once('auth-functions.php'); CreateHomeCalendar($editor->Value('username')); } if ( $session->AllowedTo('Admin') ) { if ( $_POST['is_admin'] == 'on' ) { $sql = 'INSERT INTO role_member (role_no, user_no) SELECT 1, dav_principal.user_no FROM dav_principal WHERE user_no = :user_no AND NOT EXISTS(SELECT 1 FROM role_member rm WHERE rm.role_no = 1 AND rm.user_no = dav_principal.user_no )'; $editor->Assign('is_admin', 't'); } else { $sql = 'DELETE FROM role_member WHERE role_no = 1 AND user_no = :user_no'; $editor->Assign('is_admin', 'f'); } $params['user_no'] = $editor->Value('user_no'); $qry = new AwlQuery( $sql, $params ); $qry->Exec('admin-principal-edit'); } } else { $editor->GetRecord(); if ( $editor->IsSubmit() ) { $post_values = true; } } if ( $editor->Available() ) { $c->page_title = $editor->Title(translate('Principal').': '.$editor->Value('fullname')); } else { $c->page_title = $editor->Title(translate('Create New Principal')); $privs = decbin(privilege_to_bits($c->default_privileges)); $editor->Assign('default_privileges', $privs); $editor->Assign('user_active', 't'); foreach( $c->template_usr AS $k => $v ) { $editor->Assign($k, $v); } } if ( $post_values ) { $editor->PostToValues(); if ( isset($_POST['default_privileges']) ) { $privilege_bitpos = array_flip($privilege_names); $priv_names = array_keys($_POST['default_privileges']); $privs = privilege_to_bits($priv_names); $_POST['default_privileges'] = sprintf('%024s',decbin($privs)); $editor->Assign('default_privileges', $_POST['default_privileges']); } } $privilege_xlate = array( 'all' => translate('All privileges'), 'read' => translate('Read'), 'write-properties' => translate('Write Metadata'), 'write-content' => translate('Write Data'), 'unlock' => translate('Override a Lock'), 'read-acl' => translate('Read Access Controls'), 'read-current-user-privilege-set' => translate('Read Current User\'s Access'), 'bind' => translate('Create Events/Collections'), 'unbind' => translate('Delete Events/Collections'), 'write-acl' => translate('Write Access Controls'), 'read-free-busy' => translate('Read Free/Busy Information'), 'schedule-deliver-invite' => translate('Scheduling: Deliver an Invitation'), 'schedule-deliver-reply' => translate('Scheduling: Deliver a Reply'), 'schedule-query-freebusy' => translate('Scheduling: Query free/busy'), 'schedule-send-invite' => translate('Scheduling: Send an Invitation'), 'schedule-send-reply' => translate('Scheduling: Send a Reply'), 'schedule-send-freebusy' => translate('Scheduling: Send free/busy'), 'write' => translate('Write'), 'schedule-deliver' => translate('Scheduling: Delivery'), 'schedule-send' => translate('Scheduling: Sending') ); /** * privilege_format_function is for formatting the binary privileges from the * database, including localising them. This is a hook function for a browser * column object, so it takes three parameters: * @param mixed $value The value of the column. * @param BrowserColumn $column The BrowserColumn object we are hooked into. * @param dbrow $row The row object we read from the database. * @return string The formatted privileges. */ function privilege_format_function( $value, $column, $row ) { global $privilege_xlate; $privs = bits_to_privilege($value); $formatted = ''; foreach( $privs AS $k => $v ) { $formatted .= ($formatted == '' ? '' : ' , '); $v = preg_replace( '{^.*:}', '', $v ); $formatted .= (isset($privilege_xlate[$v]) ? $privilege_xlate[$v] : $v ); } return $formatted; } $default_privileges = bindec($editor->Value('default_privileges')); $privileges_set = '
| $prompt_principal_id: |
| ||
|---|---|---|---|
| $prompt_username: | ##xxxxusername.input.50## | ||
| $prompt_password_1: | ##newpass1.password.$pwstars## | ||
| $prompt_password_1: | ##newpass2.password.$pwstars## | ||
| $prompt_fullname: | ##fullname.input.50## | ||
| $prompt_email: | ##email.input.50## | ||
| $prompt_locale: | ##locale.select## | ||
| $prompt_date_format: | ##date_format_type.select## | ||
| $prompt_type: | ##type_id.select## | ||
| $prompt_privileges: |
$privileges_set | ||
| ##submit## | |||
'; $html .= sprintf('%s \'%s\' %s %s', translate('Deleting Principal:'), $editor->Value('displayname'), $_SERVER['REQUEST_URI'], $delete_principal_confirmation_required, translate('Confirm Deletion of the Principal'), translate('All of the principal\'s calendars and events will be unrecoverably deleted.') ); $html .= "
\n"; $page_elements[] = $html; } if ( isset($id) ) { $browser = new Browser(translate('Group Memberships')); $c->stylesheets[] = 'css/browse.css'; $c->scripts[] = 'js/browse.js'; $browser->AddColumn( 'group_id', translate('ID'), 'right', '##principal_link##' ); $rowurl = $c->base_url . '/admin.php?action=edit&t=principal&id='; $browser->AddHidden( 'principal_link', "'' || principal_id || ''" ); $browser->AddColumn( 'displayname', translate('Display Name') ); $browser->AddColumn( 'member_of', translate('Is Member of'), '', '', 'is_member_of_list(principal_id)' ); $browser->AddColumn( 'members', translate('Has Members'), '', '', 'has_members_list(principal_id)' ); $browser->SetOrdering( 'displayname', 'A' ); $browser->SetJoins( "group_member LEFT JOIN dav_principal ON (group_id = principal_id) " ); $browser->SetWhere( 'user_active AND member_id = '.$id ); if ( $c->enable_row_linking ) { $browser->RowFormat( '| '; $html .= sprintf('%s "%s" %s %s', translate('Deleting Collection:'), $_GET['dav_name'], $_SERVER['REQUEST_URI'], $delete_collection_confirmation_required, translate('Confirm Deletion of the Collection'), translate('All collection data will be unrecoverably deleted.') ); $html .= " |