| 1 |
<?php |
<?php |
| 2 |
// $Id: |
// $Id$ |
| 3 |
|
|
| 4 |
function api_page_admin_form() { |
function api_page_admin_form() { |
| 5 |
$branches = api_get_branches(); |
$branches = api_get_branches(); |
| 10 |
'#theme' => 'api_branch_table', |
'#theme' => 'api_branch_table', |
| 11 |
); |
); |
| 12 |
foreach ($branches as $branch) { |
foreach ($branches as $branch) { |
| 13 |
$form['branches'][$branch->branch_name]['default_branch'] = array( |
$form['branches'][$branch->branch_id]['default_branch'] = array( |
| 14 |
'#type' => 'radio', |
'#type' => 'radio', |
| 15 |
'#default_value' => variable_get('api_default_branch', NULL), |
'#default_value' => variable_get('api_default_branch', NULL), |
| 16 |
'#return_value' => $branch->branch_name, |
'#return_value' => $branch->branch_id, |
| 17 |
); |
); |
| 18 |
$form['branches'][$branch->branch_name]['title'] = array( |
$form['branches'][$branch->branch_id]['project'] = array( |
| 19 |
'#value' => l($branch->title, 'admin/settings/api/branches/'. $branch->branch_name), |
'#value' => $branch->project, |
| 20 |
); |
); |
| 21 |
$form['branches'][$branch->branch_name]['branch_name'] = array( |
$form['branches'][$branch->branch_id]['title'] = array( |
| 22 |
|
'#value' => l($branch->title, 'admin/settings/api/branches/'. $branch->branch_id), |
| 23 |
|
); |
| 24 |
|
$form['branches'][$branch->branch_id]['branch_name'] = array( |
| 25 |
'#value' => $branch->branch_name, |
'#value' => $branch->branch_name, |
| 26 |
); |
); |
| 27 |
$form['branches'][$branch->branch_name]['directories'] = array( |
$form['branches'][$branch->branch_id]['directories'] = array( |
| 28 |
'#value' => str_replace("\n", '<br />', check_plain($branch->directories)), |
'#value' => str_replace("\n", '<br />', check_plain($branch->directories)), |
| 29 |
); |
); |
| 30 |
} |
} |
| 46 |
function theme_api_branch_table($element) { |
function theme_api_branch_table($element) { |
| 47 |
$header = array( |
$header = array( |
| 48 |
t('Default'), |
t('Default'), |
| 49 |
|
t('Project'), |
| 50 |
t('Page label'), |
t('Page label'), |
| 51 |
t('URL label'), |
t('URL label'), |
| 52 |
t('Directories'), |
t('Directories'), |
| 73 |
drupal_set_message(t('Changes saved.')); |
drupal_set_message(t('Changes saved.')); |
| 74 |
} |
} |
| 75 |
|
|
| 76 |
function api_branch_edit_form($form_state, $branch_name = NULL) { |
function api_branch_edit_form($form_state, $branch_id = NULL) { |
| 77 |
$branches = api_get_branches(); |
$branches = api_get_branches(); |
| 78 |
if (is_null($branch_name)) { |
if (is_null($branch_id)) { |
| 79 |
|
$branch->project = ''; |
| 80 |
$branch->branch_name = ''; |
$branch->branch_name = ''; |
| 81 |
$branch->title = ''; |
$branch->title = ''; |
| 82 |
$branch->directories = ''; |
$branch->directories = ''; |
| 83 |
$branch->excluded_directories = ''; |
$branch->excluded_directories = ''; |
| 84 |
} |
} |
| 85 |
else { |
else { |
| 86 |
$branch = $branches[$branch_name]; |
$branch = $branches[$branch_id]; |
| 87 |
} |
} |
| 88 |
$form = array(); |
$form = array( |
| 89 |
|
'#branch' => $branch, |
| 90 |
|
); |
| 91 |
|
|
| 92 |
|
$form['project'] = array( |
| 93 |
|
'#title' => t('Project'), |
| 94 |
|
'#type' => 'textfield', |
| 95 |
|
'#default_value' => $branch->project, |
| 96 |
|
'#required' => TRUE, |
| 97 |
|
); |
| 98 |
$form['branch_name'] = array( |
$form['branch_name'] = array( |
| 99 |
'#title' => t('URL label'), |
'#title' => t('URL label'), |
| 100 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 128 |
'#type' => 'submit', |
'#type' => 'submit', |
| 129 |
'#value' => t('Save branch'), |
'#value' => t('Save branch'), |
| 130 |
); |
); |
| 131 |
if (!is_null($branch_name)) { |
if (!is_null($branch_id)) { |
| 132 |
$form[] = array( |
$form[] = array( |
| 133 |
'#value' => l(t('Delete'), 'admin/settings/api/branches/'. $branch->branch_name .'/delete'), |
'#value' => l(t('Delete'), 'admin/settings/api/branches/'. $branch->branch_id .'/delete'), |
| 134 |
); |
); |
| 135 |
} |
} |
| 136 |
|
|
| 144 |
} |
} |
| 145 |
|
|
| 146 |
// Check for duplicate branch names. |
// Check for duplicate branch names. |
| 147 |
$branches = api_get_branches(); |
if (db_result(db_query("SELECT 1 FROM {api_branch} WHERE branch_id <> %d AND project = '%s' AND branch_name = '%s'", $form['#branch']->branch_id, $form_state['values']['project'], $form_state['values']['branch_name']))) { |
| 148 |
if (!empty($form['branch_name']['#default_value'])) { |
form_set_error('branch_name', t('%project and %branch_name is already used by another branch.', array('%project' => $form_state['values']['project'], '%branch_name' => $form_state['values']['branch_name']))); |
|
unset($branches[$form['branch_name']['#default_value']]); |
|
|
} |
|
|
if (isset($branches[$form_state['values']['branch_name']])) { |
|
|
form_set_error('branch_name', t('%branch_name is already used by another branch.', array('%branch_name' => $form_state['values']['branch_name']))); |
|
| 149 |
} |
} |
| 150 |
} |
} |
| 151 |
|
|
| 165 |
} |
} |
| 166 |
|
|
| 167 |
function api_branch_edit_form_submit($form, &$form_state) { |
function api_branch_edit_form_submit($form, &$form_state) { |
| 168 |
|
$branch = $form['#branch']; |
| 169 |
|
$branch->project = $form_state['values']['project']; |
| 170 |
$branch->branch_name = $form_state['values']['branch_name']; |
$branch->branch_name = $form_state['values']['branch_name']; |
| 171 |
$branch->title = $form_state['values']['title']; |
$branch->title = $form_state['values']['title']; |
| 172 |
$branch->directories = api_clean_directory_list($form_state['values']['directories']); |
$branch->directories = api_clean_directory_list($form_state['values']['directories']); |
| 173 |
$branch->excluded_directories = api_clean_directory_list($form_state['values']['excluded_directories']); |
$branch->excluded_directories = api_clean_directory_list($form_state['values']['excluded_directories']); |
| 174 |
|
|
| 175 |
api_save_branch($branch, $form['branch_name']['#default_value']); |
api_save_branch($branch); |
| 176 |
|
|
| 177 |
drupal_set_message(t('Saved %branch_name.', array('%branch_name' => $branch->branch_name))); |
drupal_set_message(t('Saved %branch_name.', array('%branch_name' => $branch->branch_name))); |
| 178 |
$form_state['redirect'] = 'admin/settings/api'; |
$form_state['redirect'] = 'admin/settings/api'; |
| 192 |
return implode("\n", $array); |
return implode("\n", $array); |
| 193 |
} |
} |
| 194 |
|
|
| 195 |
function api_branch_delete_form($form_state, $branch_name) { |
function api_branch_delete_form($form_state, $branch_id) { |
| 196 |
$form = array(); |
$branches = api_get_branches(); |
| 197 |
$form['branch_name'] = array( |
return confirm_form(array('#branch' => $branches[$branch_id]), t('Are you sure you want to delete %branch_name?', array('%branch_name' => $branches[$branch_id]->branch_name)), 'admin/settings/api', NULL, t('Delete')); |
|
'#type' => 'value', |
|
|
'#value' => $branch_name, |
|
|
); |
|
|
return confirm_form($form, t('Are you sure you want to delete %branch_name?', array('%branch_name' => $branch_name)), 'admin/settings/api', NULL, t('Delete')); |
|
| 198 |
} |
} |
| 199 |
|
|
| 200 |
function api_branch_delete_form_submit($form, &$form_state) { |
function api_branch_delete_form_submit($form, &$form_state) { |
| 201 |
$result = db_query("SELECT did FROM {api_documentation} WHERE branch_name = '%s'", $form['branch_name']['#value']); |
$result = db_query("SELECT did FROM {api_documentation} WHERE branch_name = '%s'", $form['#branch']->branch_name); |
| 202 |
$dids = array(); |
$dids = array(); |
| 203 |
while($did = db_fetch_object($result)) { |
while($did = db_fetch_object($result)) { |
| 204 |
$dids[] = $did->did; |
$dids[] = $did->did; |
| 205 |
} |
} |
| 206 |
$placeholders = db_placeholders($dids); |
if (count($dids) > 0) { |
| 207 |
|
$placeholders = db_placeholders($dids); |
| 208 |
db_query("DELETE FROM {api_file} WHERE did IN (". $placeholders .")", $dids); |
db_query("DELETE FROM {api_file} WHERE did IN (". $placeholders .")", $dids); |
| 209 |
db_query("DELETE FROM {api_function} WHERE did IN (". $placeholders .")", $dids); |
db_query("DELETE FROM {api_function} WHERE did IN (". $placeholders .")", $dids); |
| 210 |
db_query("DELETE FROM {api_reference_storage} WHERE from_did IN (". $placeholders .") OR to_did IN (". $placeholders .")", array_merge($dids, $dids)); |
db_query("DELETE FROM {api_reference_storage} WHERE from_did IN (". $placeholders .") OR to_did IN (". $placeholders .")", array_merge($dids, $dids)); |
| 211 |
db_query("DELETE FROM {api_documentation} WHERE did IN (". $placeholders .")", $dids); |
db_query("DELETE FROM {api_documentation} WHERE did IN (". $placeholders .")", $dids); |
| 212 |
db_query("DELETE FROM {api_branch} WHERE branch_name = '%s'", $form['branch_name']['#value']); |
} |
| 213 |
|
db_query("DELETE FROM {api_branch} WHERE branch_id = '%s'", $form['#branch']->branch_id); |
| 214 |
|
|
| 215 |
if (variable_get('api_default_branch', NULL) == $form['branch_name']['#value']) { |
if (variable_get('api_default_branch', NULL) == $form['#branch']->branch_id) { |
| 216 |
variable_set('api_default_branch', NULL); |
variable_set('api_default_branch', NULL); |
| 217 |
} |
} |
| 218 |
|
|