function ticket_row_editor() { global $c, $id, $editor, $can_write_principal, $privilege_names; $ticketrow = new Editor("Tickets", "access_ticket"); $ticketrow->SetSubmitName('ticketrow'); if ($can_write_principal && $ticketrow->IsSubmit()) { $username = $editor->Value('username'); $ugly_path = $_POST['target']; if ($ugly_path == '/' . $username || $ugly_path == '/' . $username . '/') { $target_collection = $id; } else { $username_len = strlen($username) + 2; $sql = "SELECT collection_id FROM collection WHERE dav_name = :exact_name"; $sql .= " AND substring(dav_name FROM 1 FOR {$username_len}) = '/{$username}/'"; $params = array(':exact_name' => $ugly_path); if (!preg_match('#/$#', $ugly_path)) { $sql .= " OR dav_name = :truncated_name OR dav_name = :trailing_slash_name"; $params[':truncated_name'] = preg_replace('#[^/]*$#', '', $ugly_path); $params[':trailing_slash_name'] = $ugly_path . "/"; } $sql .= " ORDER BY LENGTH(dav_name) DESC LIMIT 1"; $qry = new AwlQuery($sql, $params); if ($qry->Exec() && $qry->rows() > 0) { $row = $qry->Fetch(); $target_collection = $row->collection_id; } else { $c->messages[] = translate('Can only add tickets for existing collection paths which you own'); return $ticketrow; } } $_POST['dav_owner_id'] = $id; $_POST['target_collection_id'] = $target_collection; $ticket_id = check_by_regex($_POST['ticket_id'], '/[A-Za-z0-9]+/'); $ticketrow->SetWhere('dav_owner_id=' . $id . ' AND ticket_id=' . AwlQuery::quote($ticket_id)); if (isset($_POST['ticket_privileges'])) { $privilege_bitpos = array_flip($privilege_names); $priv_names = array_keys($_POST['ticket_privileges']); $privs_dec = privilege_to_bits($priv_names); $_POST['privileges'] = sprintf('%024s', decbin($privs_dec)); $ticketrow->Assign('privileges', $privs_dec); } $c->messages[] = translate('Creating new ticket granting privileges to this Principal'); $ticketrow->Write(); } return $ticketrow; }
$grantrow->SetSubmitName('savegrantrow'); $grantrow->SetLookup('to_principal', 'SELECT principal_id, displayname FROM dav_principal WHERE principal_id NOT IN (SELECT member_id FROM group_member WHERE group_id = ' . $id . ') ORDER BY displayname'); if ($can_write_collection) { if ($grantrow->IsSubmit()) { $_POST['by_collection'] = $id; $to_principal = intval($_POST['to_principal']); $orig_to_id = intval($_POST['orig_to_id']); $grantrow->SetWhere("by_collection=" . $id . " AND to_principal={$orig_to_id}"); if (isset($_POST['grant_privileges'])) { $privilege_bitpos = array_flip($privilege_names); $priv_names = array_keys($_POST['grant_privileges']); $privs = privilege_to_bits($priv_names); $_POST['privileges'] = sprintf('%024s', decbin($privs)); $grantrow->Assign('privileges', $privs_dec); } $grantrow->Write(); unset($_GET['to_principal']); } elseif (isset($_GET['delete_grant'])) { $qry = new AwlQuery("DELETE FROM grants WHERE by_collection=:grantor_id AND to_principal = :to_principal", array(':grantor_id' => $id, ':to_principal' => intval($_GET['delete_grant']))); $qry->Exec('collection-edit'); } } function edit_grant_row($row_data) { global $grantrow, $id, $privilege_xlate, $privilege_names; global $btn_all, $btn_all_title, $btn_rw, $btn_rw_title, $btn_read, $btn_read_title; global $btn_fb, $btn_fb_title, $btn_sd, $btn_sd_title, $btn_ss, $btn_ss_title; $submit_label = translate('Grant'); if ($row_data->to_principal > -1) { $grantrow->SetRecord($row_data); $submit_label = translate('Apply Changes');