| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
@require_once("../../includes.php"); |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
define("context","form"); |
|---|
| 17 |
|
|---|
| 18 |
$title = __gettext('Fields'); |
|---|
| 19 |
|
|---|
| 20 |
if (isloggedin() && run("users:flags:get", array("admin", $_SESSION['userid']))) { |
|---|
| 21 |
|
|---|
| 22 |
$type = optional_param('type',''); |
|---|
| 23 |
|
|---|
| 24 |
if ($type == 'delete_orphans') { |
|---|
| 25 |
delete_records_select('form_fields', $select='ident NOT IN (SELECT field_id FROM '.$CFG->prefix.'form_fields_map)'); |
|---|
| 26 |
$type = 'orphan'; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
$edit_msg = __gettext('Edit'); |
|---|
| 30 |
$delete_msg = __gettext('Delete'); |
|---|
| 31 |
$delete_orphans_confirm_msg = __gettext("Are you sure that you want to delete all the orphan field definitions?"); |
|---|
| 32 |
if ($type == 'orphan') { |
|---|
| 33 |
$delete_confirm_msg = __gettext("Are you sure that you want to delete this field definition?"); |
|---|
| 34 |
} else { |
|---|
| 35 |
$delete_confirm_msg = __gettext("Are you sure that you want to delete this field definition and erase it from all forms?"); |
|---|
| 36 |
} |
|---|
| 37 |
|
|---|
| 38 |
$img_template = '<img border="0" width="16" height="16" alt="%s" title="%s" src="'.$CFG->wwwroot.'mod/widget/images/%s" />'; |
|---|
| 39 |
$edit_img = sprintf($img_template,$edit_msg,$edit_msg,"16-em-pencil.png"); |
|---|
| 40 |
$delete_img = sprintf($img_template,$delete_msg,$delete_msg,"16-em-cross.png"); |
|---|
| 41 |
|
|---|
| 42 |
$field_template = <<<END |
|---|
| 43 |
<a href="{$CFG->wwwroot}mod/form/manage_field.php?action=edit_with_field_id&id=%s&type=%s">$edit_img</a> | |
|---|
| 44 |
<a onclick="return confirm('$delete_confirm_msg')" href="{$CFG->wwwroot}mod/form/manage_field.php?action=delete&id=%s&type=%s">$delete_img</a> |
|---|
| 45 |
%s |
|---|
| 46 |
<br /> |
|---|
| 47 |
END; |
|---|
| 48 |
if ($type == 'orphan') { |
|---|
| 49 |
$body = '<p><a href="'.$CFG->wwwroot.'mod/form/list_fields.php?type=all">'.__gettext("List all fields").'</a> | '."\n"; |
|---|
| 50 |
$body .= '<a onclick="return confirm(\''.$delete_orphans_confirm_msg.'\')" href="'.$CFG->wwwroot.'mod/form/list_fields.php?type=delete_orphans">'.__gettext("Delete all orphan fields").'</a> | '."\n"; |
|---|
| 51 |
$body .= '<a href="'.$CFG->wwwroot.'mod/form/index.php">'.__gettext("List all forms").'</a></p>'."\n"; |
|---|
| 52 |
$body .= '<p>'.__gettext("This page lists all the fields not currently associated with a form.").'</p>'."\n"; |
|---|
| 53 |
$fields = get_records_sql("SELECT * FROM {$CFG->prefix}form_fields " |
|---|
| 54 |
."WHERE ident NOT IN (SELECT field_id FROM {$CFG->prefix}form_fields_map) ORDER BY internal_name ASC"); |
|---|
| 55 |
} else { |
|---|
| 56 |
$body = '<p><a href="'.$CFG->wwwroot.'mod/form/list_fields.php?type=orphan">'.__gettext("List orphan fields").'</a> | '."\n"; |
|---|
| 57 |
$body .= '<a href="'.$CFG->wwwroot.'mod/form/index.php">'.__gettext("List all forms").'</a></p>'."\n"; |
|---|
| 58 |
$body .= '<p>'.__gettext("This page lists all the currently defined fields.").'</p>'."\n"; |
|---|
| 59 |
$fields = get_records_sql("SELECT * FROM {$CFG->prefix}form_fields ORDER BY internal_name ASC"); |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
if ($fields) { |
|---|
| 63 |
foreach ($fields as $field) { |
|---|
| 64 |
$body .= sprintf( |
|---|
| 65 |
$field_template, |
|---|
| 66 |
$field->ident, |
|---|
| 67 |
$type, |
|---|
| 68 |
$field->ident, |
|---|
| 69 |
$type, |
|---|
| 70 |
$field->title . ' ('.$field->internal_name.': '.$field->field_type.')'); |
|---|
| 71 |
} |
|---|
| 72 |
} else { |
|---|
| 73 |
$body .= '<p>'.__gettext("There are no fields.").'</p>'; |
|---|
| 74 |
} |
|---|
| 75 |
} else { |
|---|
| 76 |
$body = __gettext("You must be logged in as a site administrator to view this page."); |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
$body = templates_draw(array( |
|---|
| 81 |
'context' => 'contentholder', |
|---|
| 82 |
'title' => $title, |
|---|
| 83 |
'body' => $body |
|---|
| 84 |
) |
|---|
| 85 |
); |
|---|
| 86 |
|
|---|
| 87 |
echo templates_page_draw( array( |
|---|
| 88 |
$title, $body |
|---|
| 89 |
) |
|---|
| 90 |
); |
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
?> |
|---|