Parent Directory
|
Revision Log
|
Revision Graph
Fixed minor issue.
| 1 | <?php |
| 2 | // $Id: multiforms.module,v 1.44 2008/12/04 22:47:53 mcantelon Exp $ |
| 3 | |
| 4 | /** |
| 5 | * Implementation of hook_help(). |
| 6 | */ |
| 7 | function multiforms_help($section = '') { |
| 8 | |
| 9 | $output= ''; |
| 10 | |
| 11 | switch ($section) { |
| 12 | |
| 13 | case "admin/modules#description": |
| 14 | $output = t("Provides multi-page form functionality."); |
| 15 | break; |
| 16 | |
| 17 | case "admin/help": |
| 18 | $output = t("Provides multi-page form functionality."); |
| 19 | break; |
| 20 | |
| 21 | case 'node/add#multiform': |
| 22 | $output = t("A multiform collects private user data through one or more forms."); |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | return $output; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Implementation of hook_perm(). |
| 31 | */ |
| 32 | function multiforms_perm() { |
| 33 | |
| 34 | return array('access multiform administration'); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Implementation of hook_menu(). |
| 39 | */ |
| 40 | function multiforms_menu($may_cache) { |
| 41 | $items = array(); |
| 42 | |
| 43 | if ($may_cache) { |
| 44 | } |
| 45 | else { |
| 46 | |
| 47 | if (arg(0) == 'node' && is_numeric(arg(1))) { |
| 48 | |
| 49 | $node = node_load(arg(1)); |
| 50 | |
| 51 | if ($node->nid && $node->type == 'multiforms') { |
| 52 | |
| 53 | $items[] = array('path' => 'node/'. arg(1) .'/setup', |
| 54 | 'title' => t('Setup'), |
| 55 | 'weight' => '1', |
| 56 | 'callback' => 'multiforms_admin_edit_page', |
| 57 | 'callback arguments' => array(_multiforms_get_multiform_id_from_nid(arg(1))), |
| 58 | 'type' => MENU_LOCAL_TASK, |
| 59 | 'access' => user_access('access multiform administration') |
| 60 | ); |
| 61 | |
| 62 | $items[] = array('path' => 'node/'. arg(1) .'/sections', |
| 63 | 'title' => t('Forms'), |
| 64 | 'weight' => '3', |
| 65 | 'callback' => 'multiforms_admin_section_page', |
| 66 | 'callback arguments' => array(_multiforms_get_multiform_id_from_nid(arg(1)), arg(3)), |
| 67 | 'type' => MENU_LOCAL_TASK, |
| 68 | 'access' => user_access('access multiform administration') |
| 69 | ); |
| 70 | |
| 71 | $items[] = array('path' => 'node/'. arg(1) .'/sections/add', |
| 72 | 'title' => t('Add Section'), |
| 73 | 'callback' => 'multiforms_admin_section_add_page', |
| 74 | 'callback arguments' => array(_multiforms_get_multiform_id_from_nid(arg(1))), |
| 75 | 'type' => MENU_LOCAL_TASK, |
| 76 | 'access' => user_access('access multiform administration') |
| 77 | ); |
| 78 | |
| 79 | $items[] = array('path' => 'node/'. arg(1) .'/sections/promote', |
| 80 | 'title' => t('Promote Section'), |
| 81 | 'callback' => 'multiforms_admin_section_promote', |
| 82 | 'callback arguments' => array(arg(4)), |
| 83 | 'type' => MENU_CALLBACK_CUSTOM, |
| 84 | 'access' => user_access('access multiform administration') |
| 85 | ); |
| 86 | |
| 87 | $items[] = array('path' => 'node/'. arg(1) .'/sections/demote', |
| 88 | 'title' => t('Demote Section'), |
| 89 | 'callback' => 'multiforms_admin_section_demote', |
| 90 | 'callback arguments' => array(arg(4)), |
| 91 | 'type' => MENU_CALLBACK_CUSTOM, |
| 92 | 'access' => user_access('access multiform administration') |
| 93 | ); |
| 94 | |
| 95 | $items[] = array('path' => 'node/'. arg(1) .'/sections/delete', |
| 96 | 'callback' => 'multiforms_admin_section_delete_page', |
| 97 | 'callback arguments' => array(arg(4)), |
| 98 | 'type' => MENU_CALLBACK_CUSTOM, |
| 99 | 'access' => user_access('access multiform administration') |
| 100 | ); |
| 101 | |
| 102 | $items[] = array('path' => 'node/'. arg(1) .'/sections/fields/add', |
| 103 | 'title' => t('Add Field'), |
| 104 | 'callback' => 'multiforms_admin_field_add_page', |
| 105 | 'callback arguments' => array(arg(5)), |
| 106 | 'type' => MENU_CALLBACK_CUSTOM, |
| 107 | 'access' => user_access('access multiform administration') |
| 108 | ); |
| 109 | |
| 110 | $items[] = array('path' => 'node/'. arg(1) .'/sections/fields/edit', |
| 111 | 'title' => t('Edit Field'), |
| 112 | 'callback' => 'multiforms_admin_field_edit_page', |
| 113 | 'callback arguments' => array(arg(5)), |
| 114 | 'type' => MENU_CALLBACK_CUSTOM, |
| 115 | 'access' => user_access('access multiform administration') |
| 116 | ); |
| 117 | |
| 118 | $items[] = array('path' => 'node/'. arg(1) .'/sections/fields/promote', |
| 119 | 'title' => t('Promote Field'), |
| 120 | 'callback' => 'multiforms_admin_field_promote', |
| 121 | 'callback arguments' => array(arg(5)), |
| 122 | 'type' => MENU_CALLBACK_CUSTOM, |
| 123 | 'access' => user_access('access multiform administration') |
| 124 | ); |
| 125 | |
| 126 | $items[] = array('path' => 'node/'. arg(1) .'/sections/fields/demote', |
| 127 | 'callback' => 'multiforms_admin_field_demote', |
| 128 | 'callback arguments' => array(arg(5)), |
| 129 | 'type' => MENU_CALLBACK_CUSTOM, |
| 130 | 'access' => user_access('access multiform administration') |
| 131 | ); |
| 132 | |
| 133 | $items[] = array('path' => 'node/'. arg(1) .'/sections/fields/delete', |
| 134 | 'callback' => 'multiforms_admin_field_delete_page', |
| 135 | 'callback arguments' => array(arg(5)), |
| 136 | 'type' => MENU_CALLBACK_CUSTOM, |
| 137 | 'access' => user_access('access multiform administration') |
| 138 | ); |
| 139 | |
| 140 | $items[] = array('path' => 'node/'. arg(1) .'/submissions/draw', |
| 141 | 'title' => t('Draw'), |
| 142 | 'weight' => '1', |
| 143 | 'callback' => 'multiforms_admin_draw_page', |
| 144 | 'type' => MENU_LOCAL_TASK, |
| 145 | 'access' => user_access('access multiform administration') |
| 146 | ); |
| 147 | |
| 148 | $items[] = array('path' => 'node/'. arg(1) .'/submissions/export', |
| 149 | 'title' => t('Export'), |
| 150 | 'weight' => '2', |
| 151 | 'callback' => 'multiforms_admin_export_page', |
| 152 | 'type' => MENU_LOCAL_TASK, |
| 153 | 'access' => user_access('access multiform administration') |
| 154 | ); |
| 155 | |
| 156 | $items[] = array('path' => 'node/'. arg(1) .'/submissions/purge', |
| 157 | 'title' => t('Purge'), |
| 158 | 'weight' => '3', |
| 159 | 'callback' => 'multiforms_admin_purge_page', |
| 160 | 'type' => MENU_LOCAL_TASK, |
| 161 | 'access' => user_access('access multiform administration') |
| 162 | ); |
| 163 | |
| 164 | $items[] = array('path' => 'node/'. arg(1) .'/submissions', |
| 165 | 'title' => t('Submissions'), |
| 166 | 'weight' => '4', |
| 167 | 'callback' => 'multiforms_admin_submission_dispatch', |
| 168 | 'callback arguments' => array(arg(3), arg(4)), |
| 169 | 'type' => MENU_LOCAL_TASK, |
| 170 | 'access' => user_access('access multiform administration') |
| 171 | ); |
| 172 | |
| 173 | $items[] = array('path' => 'node/'. arg(1) .'/snippet/save', |
| 174 | 'title' => t('Save Snippet'), |
| 175 | 'callback' => 'multiforms_admin_snippet_save_page', |
| 176 | 'callback arguments' => array(arg(4)), |
| 177 | 'type' => MENU_CALLBACK_CUSTOM, |
| 178 | 'access' => user_access('access multiform administration') |
| 179 | ); |
| 180 | |
| 181 | $items[] = array('path' => 'node/'. arg(1) .'/snippet', |
| 182 | 'title' => t('Load Snippet'), |
| 183 | 'callback' => 'multiforms_admin_snippet_page', |
| 184 | 'callback arguments' => array(arg(3)), |
| 185 | 'type' => MENU_CALLBACK_CUSTOM, |
| 186 | 'access' => user_access('access multiform administration') |
| 187 | ); |
| 188 | |
| 189 | $items[] = array('path' => 'node/' . arg(1) . '/snippet/delete', |
| 190 | 'title' => t('Delete Snippet'), |
| 191 | 'callback' => 'multiforms_admin_snippet_delete_submit', |
| 192 | 'callback arguments' => array(arg(4)), |
| 193 | 'type' => MENU_CALLBACK_CUSTOM, |
| 194 | 'access' => user_access('access multiform administration') |
| 195 | ); |
| 196 | |
| 197 | $items[] = array('path' => 'node/' . arg(1) . '/multiforms/action', |
| 198 | 'title' => t('add action'), |
| 199 | 'callback' => 'multiforms_admin_action_page', |
| 200 | 'callback arguments' => array(arg(4)), |
| 201 | 'type' => MENU_CALLBACK_CUSTOM, |
| 202 | 'access' => user_access('access multiform administration') |
| 203 | ); |
| 204 | |
| 205 | $items[] = array('path' => 'node/' . arg(1) . '/multiforms/action/delete', |
| 206 | 'title' => t('delete action'), |
| 207 | 'callback' => 'multiforms_admin_action_delete_page', |
| 208 | 'callback arguments' => array(arg(5)), |
| 209 | 'type' => MENU_CALLBACK_CUSTOM, |
| 210 | 'access' => user_access('access multiform administration') |
| 211 | ); |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return $items; |
| 217 | } |
| 218 | |
| 219 | function _multiforms_return_form_array($form_name, $form_title, $submit_label, $multiform_id = '', $row = '') { |
| 220 | |
| 221 | $form = array(); |
| 222 | |
| 223 | $form[$form_name] = array( |
| 224 | '#type' => 'fieldset', |
| 225 | '#title' => t($form_title), |
| 226 | '#tree' => TRUE |
| 227 | ); |
| 228 | |
| 229 | // Including title and body only in add form |
| 230 | if ($form_name == 'multiforms_admin_add') { |
| 231 | |
| 232 | $form[$form_name]['title'] = array( |
| 233 | '#title' => t('Title'), |
| 234 | '#type' => 'textfield', |
| 235 | '#required' => TRUE |
| 236 | ); |
| 237 | |
| 238 | $form[$form_name]['body'] = array( |
| 239 | '#title' => t('Body'), |
| 240 | '#type' => 'textarea', |
| 241 | '#description' => t('What text should be shown above the submission form?') |
| 242 | ); |
| 243 | } |
| 244 | |
| 245 | $form[$form_name]['footer'] = array( |
| 246 | '#title' => t('Footer Text'), |
| 247 | '#type' => 'textarea', |
| 248 | '#description' => t('What text should be shown under the submission form?') |
| 249 | ); |
| 250 | |
| 251 | $form[$form_name]['end_text'] = array( |
| 252 | '#title' => t('Completion Text'), |
| 253 | '#type' => 'textarea', |
| 254 | '#description' => t('What text should be shown to the user upon multiform completion?') |
| 255 | ); |
| 256 | |
| 257 | $form[$form_name]['submit_button_text'] = array( |
| 258 | '#title' => t('Submit Button Text'), |
| 259 | '#type' => 'textfield', |
| 260 | '#description' => t('Defaults to "Submit".') |
| 261 | ); |
| 262 | |
| 263 | $form[$form_name]['end_redirect'] = array( |
| 264 | '#title' => t('Completion Redirection Path/URL'), |
| 265 | '#type' => 'textfield', |
| 266 | '#description' => t('Where should the user be redirected to upon multiform completion?') |
| 267 | ); |
| 268 | |
| 269 | $form[$form_name]['completion_submit_button_text'] = array( |
| 270 | '#title' => t('Completion Submit Button Text'), |
| 271 | '#type' => 'textfield', |
| 272 | '#description' => t('Defaults to "Finish".') |
| 273 | ); |
| 274 | |
| 275 | $flow_options = array( |
| 276 | MULTIFORMS_FLOW_TYPE_NORMAL => 'Normal', |
| 277 | MULTIFORMS_FLOW_TYPE_LINEAR => 'Linear' |
| 278 | ); |
| 279 | |
| 280 | $form[$form_name]['flow_type'] = array( |
| 281 | '#title' => t('Flow Type'), |
| 282 | '#type' => 'select', |
| 283 | '#options' => $flow_options, |
| 284 | '#description' => t('If using sections, should there be a list of sections, allowing user to fill in select sections (normal flow), \r |
| 285 | or should user be shown the next section immediately after one has been completed (linear flow)?') |
| 286 | ); |
| 287 | |
| 288 | $form[$form_name]['closing'] = array( |
| 289 | '#type' => 'fieldset', |
| 290 | '#title' => t('Closing Date'), |
| 291 | '#collapsible' => TRUE, |
| 292 | '#collapsed' => TRUE, |
| 293 | '#tree' => TRUE, |
| 294 | ); |
| 295 | |
| 296 | $form[$form_name]['closing']['closing_date_enable'] = array( |
| 297 | '#title' => t('Enable Closing Date'), |
| 298 | '#type' => 'checkbox', |
| 299 | '#description' => t('Should the multiform be closed for submissions at a certain date?') |
| 300 | ); |
| 301 | |
| 302 | $form[$form_name]['closing']['closing_date'] = array( |
| 303 | '#title' => t('Closing Date'), |
| 304 | '#type' => 'date', |
| 305 | '#description' => t('At what date should the multiform be closed for submissions?') |
| 306 | ); |
| 307 | |
| 308 | $form[$form_name]['closing']['closing_time'] = array( |
| 309 | '#title' => 'Closing Time', |
| 310 | '#type' => 'textfield', |
| 311 | '#description' => t('At what time should the multiform be closed for submissions (HH:MM:SS)?') |
| 312 | ); |
| 313 | |
| 314 | $form[$form_name]['closing']['closing_text'] = array( |
| 315 | '#title' => 'Closing Text', |
| 316 | '#type' => 'textarea', |
| 317 | '#description' => t('What text should be shown when the multiform is closed for submissions?') |
| 318 | ); |
| 319 | |
| 320 | $form[$form_name]['completion'] = array( |
| 321 | '#type' => 'fieldset', |
| 322 | '#title' => t('Completion Criteria'), |
| 323 | '#collapsible' => TRUE, |
| 324 | '#collapsed' => TRUE, |
| 325 | '#tree' => TRUE, |
| 326 | ); |
| 327 | |
| 328 | $form[$form_name]['completion']['threshold'] = array( |
| 329 | '#title' => t('Completion Threshold'), |
| 330 | '#type' => 'textfield', |
| 331 | '#description' => t('How many section fields must be filled in before the multiform can be considered complete?') |
| 332 | ); |
| 333 | |
| 334 | $form[$form_name]['completion']['end_notification'] = array( |
| 335 | '#title' => t('Notification Message'), |
| 336 | '#type' => 'textarea', |
| 337 | '#description' => t('What message should be shown to notify the user that they can complete their submission?') |
| 338 | ); |
| 339 | |
| 340 | $form[$form_name]['email'] = array( |
| 341 | '#type' => 'fieldset', |
| 342 | '#title' => t('Email Referrals'), |
| 343 | '#collapsible' => TRUE, |
| 344 | '#collapsed' => TRUE, |
| 345 | '#tree' => TRUE, |
| 346 | ); |
| 347 | |
| 348 | $form[$form_name]['email']['allow'] = array( |
| 349 | '#title' => t('Display Email Form'), |
| 350 | '#type' => 'checkbox', |
| 351 | '#description' => t('Would you like a form shown upon completion that allows the submitter to refer friends to the multiform?') |
| 352 | ); |
| 353 | |
| 354 | $form[$form_name]['email']['subject'] = array( |
| 355 | '#title' => t('Email Subject'), |
| 356 | '#type' => 'textfield', |
| 357 | '#description' => t('What would you like the subject of any emails sent to be?') |
| 358 | ); |
| 359 | |
| 360 | $form[$form_name]['email']['body'] = array( |
| 361 | '#title' => t('Email Body'), |
| 362 | '#type' => 'textarea', |
| 363 | '#description' => t('What would you like the body text of any emails sent to be?') |
| 364 | ); |
| 365 | |
| 366 | $form[$form_name]['email']['thank_you'] = array( |
| 367 | '#title' => t('Thank-You Text'), |
| 368 | '#type' => 'textarea', |
| 369 | '#description' => t('After emails are sent, what text should be displayed?') |
| 370 | ); |
| 371 | |
| 372 | $form[$form_name]['draw'] = array( |
| 373 | '#type' => 'fieldset', |
| 374 | '#title' => t('Draw Entries'), |
| 375 | '#collapsible' => TRUE, |
| 376 | '#collapsed' => TRUE, |
| 377 | '#tree' => TRUE, |
| 378 | ); |
| 379 | |
| 380 | $form[$form_name]['draw']['create_on_submission'] = array( |
| 381 | '#title' => t('Create Draw Entries When Submitting?'), |
| 382 | '#type' => 'checkbox', |
| 383 | '#description' => t('Would you like a draw entry created for each submission?') |
| 384 | ); |
| 385 | |
| 386 | $form[$form_name]['draw']['create_on_referral'] = array( |
| 387 | '#title' => t('Create Draw Entries When Referring?'), |
| 388 | '#type' => 'checkbox', |
| 389 | '#description' => t('Would you like a draw entry created for each email referral?') |
| 390 | ); |
| 391 | |
| 392 | $form[$form_name]['submit'] = array( |
| 393 | '#type' => 'submit', |
| 394 | '#value' => t($submit_label) |
| 395 | ); |
| 396 | |
| 397 | if ($row) { |
| 398 | |
| 399 | $date_raw_array = explode('-', $row->multiform_closing_date); |
| 400 | |
| 401 | $date_array = array( |
| 402 | 'year' => $date_raw_array[0], |
| 403 | 'month' => $date_raw_array[1], |
| 404 | 'day' => $date_raw_array[2] |
| 405 | ); |
| 406 | |
| 407 | $form[$form_name]['name']['#default_value'] = |
| 408 | $row->multiform_name; |
| 409 | $form[$form_name]['friendly_name']['#default_value'] = |
| 410 | $row->multiform_friendly_name; |
| 411 | $form[$form_name]['body']['#default_value'] = |
| 412 | 'bodytext'. $row->multiform_description; |
| 413 | $form[$form_name]['footer']['#default_value'] = |
| 414 | $row->multiform_footer; |
| 415 | $form[$form_name]['flow_type']['#default_value'] = |
| 416 | $row->multiform_flow_type; |
| 417 | |
| 418 | $form[$form_name]['closing']['closing_date_enable']['#default_value'] = |
| 419 | $row->multiform_closing_enabled; |
| 420 | $form[$form_name]['closing']['closing_date']['#default_value'] = |
| 421 | $date_array; |
| 422 | $form[$form_name]['closing']['closing_time']['#default_value'] = |
| 423 | $row->multiform_closing_time; |
| 424 | $form[$form_name]['closing']['closing_text']['#default_value'] = |
| 425 | $row->multiform_closing_text; |
| 426 | $form[$form_name]['completion']['end_notification']['#default_value'] = |
| 427 | $row->multiform_end_notification; |
| 428 | $form[$form_name]['end_text']['#default_value'] = |
| 429 | $row->multiform_end_text; |
| 430 | $form[$form_name]['end_redirect']['#default_value'] = |
| 431 | $row->multiform_completion_redirect; |
| 432 | $form[$form_name]['submit_button_text']['#default_value'] = |
| 433 | $row->multiform_submit_button_text; |
| 434 | $form[$form_name]['completion_submit_button_text']['#default_value'] = |
| 435 | $row->multiform_completion_submit_button_text; |
| 436 | $form[$form_name]['completion']['threshold']['#default_value'] = |
| 437 | $row->multiform_completion_threshold; |
| 438 | $form[$form_name]['email']['allow']['#default_value'] = |
| 439 | $row->multiform_email_allow; |
| 440 | $form[$form_name]['email']['subject']['#default_value'] = |
| 441 | $row->multiform_email_subject; |
| 442 | $form[$form_name]['email']['thank_you']['#default_value'] = |
| 443 | $row->multiform_email_thanks; |
| 444 | $form[$form_name]['email']['body']['#default_value'] = |
| 445 | $row->multiform_email_body; |
| 446 | $form[$form_name]['draw']['create_on_submission']['#default_value'] = |
| 447 | $row->multiform_draw_entry_on_submission; |
| 448 | $form[$form_name]['draw']['create_on_referral']['#default_value'] = |
| 449 | $row->multiform_draw_entry_on_rererral; |
| 450 | |
| 451 | $form[$form_name]['email']['allow']['#title'] .= |
| 452 | ' ('. l('View', 'node/'. arg(1) .'/multiform/share/'. $multiform_id) .')'; |
| 453 | } |
| 454 | |
| 455 | return $form; |
| 456 | } |
| 457 | |
| 458 | function multiforms_nodeapi(&$node, $op) { |
| 459 | |
| 460 | if ($op == 'insert' && $node->type == 'multiforms') { |
| 461 | |
| 462 | $query = "INSERT INTO {". MULTIFORM_TABLE ."} \r |
| 463 | (nid, multiform_draw_entry_on_submission, multiform_draw_entry_on_rererral) VALUES ('%d', 1, 1)"; |
| 464 | |
| 465 | $params = array($node->nid); |
| 466 | |
| 467 | $result = db_query($query, $params); |
| 468 | |
| 469 | if (!$result) { |
| 470 | |
| 471 | drupal_set_message('error', t('There was an error creating your multiform.')); |
| 472 | } |
| 473 | else { |
| 474 | |
| 475 | drupal_set_message(l(t('Edit setup here.'), 'node/'. $node->nid .'/setup')); |
| 476 | |
| 477 | $query = "SELECT multiform_id FROM {". MULTIFORM_TABLE ."} WHERE nid='%d'"; |
| 478 | |
| 479 | $params = array($node->nid); |
| 480 | |
| 481 | $result = db_query($query, $params); |
| 482 | |
| 483 | if ($result) { |
| 484 | |
| 485 | if ($multiform = db_fetch_object($result)) { |
| 486 | |
| 487 | drupal_set_message(l( |
| 488 | t('Edit submission form here.'), |
| 489 | 'node/'. $node->nid .'/sections/'. (0 - $multiform->multiform_id) |
| 490 | )); |
| 491 | } |
| 492 | } |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | } |
| 497 | |
| 498 | function _multiforms_section_list($multiform_id) { |
| 499 | |
| 500 | $output = ''; |
| 501 | |
| 502 | $query = "SELECT * FROM {". MULTIFORM_SECTION_TABLE ."} \r |
| 503 | WHERE multiform_section_multiform_id='%d' \r |
| 504 | ORDER BY multiform_section_sortorder ASC"; |
| 505 | |
| 506 | $result = db_query($query, $multiform_id); |
| 507 | |
| 508 | $rows = array(); |
| 509 | |
| 510 | if ($result) { |
| 511 | |
| 512 | $row_count = db_num_rows($result); |
| 513 | $count = 0; |
| 514 | |
| 515 | while ($row = db_fetch_object($result)) { |
| 516 | |
| 517 | $field_count = 0; |
| 518 | |
| 519 | $query = "SELECT count(multiform_field_id) AS field_count FROM \r |
| 520 | {". MULTIFORM_FIELD_TABLE ."} \r |
| 521 | WHERE multiform_field_section_id='%d'"; |
| 522 | |
| 523 | $result2 = db_query($query, $row->multiform_section_id); |
| 524 | |
| 525 | if ($result2) { |
| 526 | |
| 527 | if ($row2 = db_fetch_object($result2)) { |
| 528 | |
| 529 | $field_count = $row2->field_count; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if (!$field_count) { |
| 534 | |
| 535 | $field_count = t('None'); |
| 536 | } |
| 537 | |
| 538 | if ($count) { |
| 539 | |
| 540 | $promote_link = l(t('Promote'), 'node/'. arg(1) .'/sections/promote/'. $row->multiform_section_id); |
| 541 | } |
| 542 | else { |
| 543 | |
| 544 | $promote_link = ''; |
| 545 | } |
| 546 | |
| 547 | if ($count < ($row_count - 1)) { |
| 548 | $demote_link = l(t('Demote'), 'node/'. arg(1) .'/sections/demote/'. $row->multiform_section_id); |
| 549 | } |
| 550 | else { |
| 551 | |
| 552 | $demote_link = ''; |
| 553 | } |
| 554 | |
| 555 | $rows[] = array( |
| 556 | $row->multiform_section_name .' ', |
| 557 | $field_count .' ', |
| 558 | l(t('Edit'), 'node/'. arg(1) .'/sections/'. $row->multiform_section_id) .' ', |
| 559 | l(t('Delete'), 'node/'. arg(1) .'/sections/delete/'. $row->multiform_section_id) .' ', |
| 560 | l(t('View'), 'node/'. arg(1) .'/multiform/section/'. $row->multiform_section_id) .' ', |
| 561 | $promote_link .' ', |
| 562 | $demote_link .' ' |
| 563 | ); |
| 564 | |
| 565 | $count++; |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | if ($row_count) { |
| 570 | |
| 571 | $headers = array(t('Name'), t('Fields'), '', '', '', '', ''); |
| 572 | |
| 573 | $output .= theme_table($headers, $rows); |
| 574 | } |
| 575 | else { |
| 576 | |
| 577 | $output .= t('No sections yet created.') .'<p />'; |
| 578 | } |
| 579 | |
| 580 | $output .= '» '. l(t('Add New Section'), 'node/'. arg(1) .'/sections/add/'. $multiform_id); |
| 581 | |
| 582 | return $output; |
| 583 | } |
| 584 | |
| 585 | function multiforms_admin_edit_page($multiform_id) { |
| 586 | |
| 587 | $output = ''; |
| 588 | |
| 589 | $form_name = 'multiforms_admin_edit'; |
| 590 | |
| 591 | $query = "SELECT * FROM {". MULTIFORM_TABLE ."} WHERE multiform_id='%d'"; |
| 592 | |
| 593 | $result = db_query($query, $multiform_id); |
| 594 | |
| 595 | if ($result) { |
| 596 | |
| 597 | if ($row = db_fetch_object($result)) { |
| 598 | |
| 599 | $output .= drupal_get_form('multiforms_admin_edit', $multiform_id, $row); |
| 600 | |
| 601 | if (module_exists('actions')) { |
| 602 | |
| 603 | $output .= multiforms_admin_actions('multiform', $multiform_id, t('These actions will occur upon multiform completion.')); |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | print theme('page', $output); |
| 609 | } |
| 610 | |
| 611 | function multiforms_admin_edit($multiform_id, $row) { |
| 612 | |
| 613 | return _multiforms_return_form_array('multiforms_admin_edit', 'Edit Multiform', 'Update', $multiform_id, $row); |
| 614 | } |
| 615 | |
| 616 | function multiforms_admin_edit_submit($form_id, $form_data) { |
| 617 | |
| 618 | $field_values = $form_data[$form_id]; |
| 619 | |
| 620 | $multiform_id = _multiforms_get_multiform_id_from_nid(arg(1)); |
| 621 | |
| 622 | if ($multiform_id) { |
| 623 | |
| 624 | $query = "UPDATE {". MULTIFORM_TABLE ."} SET \r |
| 625 | multiform_footer='%s', \r |
| 626 | multiform_end_notification='%s', \r |
| 627 | multiform_end_text='%s', \r |
| 628 | multiform_completion_redirect='%s', \r |
| 629 | multiform_submit_button_text='%s', \r |
| 630 | multiform_completion_submit_button_text='%s', \r |
| 631 | multiform_completion_threshold='%s', \r |
| 632 | multiform_email_allow='%s', \r |
| 633 | multiform_email_subject='%s', \r |
| 634 | multiform_email_body='%s', \r |
| 635 | multiform_email_thanks='%s', \r |
| 636 | multiform_draw_entry_on_submission='%s', \r |
| 637 | multiform_draw_entry_on_rererral='%s', \r |
| 638 | multiform_closing_enabled='%d', \r |
| 639 | multiform_closing_date='%s', \r |
| 640 | multiform_closing_time='%s', \r |
| 641 | multiform_closing_text='%s', \r |
| 642 | multiform_flow_type='%d' \r |
| 643 | WHERE multiform_id='%d'"; |
| 644 | |
| 645 | $result = db_query( |
| 646 | $query, |
| 647 | $field_values['footer'], |
| 648 | $field_values['completion']['end_notification'], |
| 649 | $field_values['end_text'], |
| 650 | $field_values['end_redirect'], |
| 651 | $field_values['submit_button_text'], |
| 652 | $field_values['completion_submit_button_text'], |
| 653 | $field_values['completion']['threshold'], |
| 654 | $field_values['email']['allow'], |
| 655 | $field_values['email']['subject'], |
| 656 | $field_values['email']['body'], |
| 657 | $field_values['email']['thank_you'], |
| 658 | $field_values['draw']['create_on_submission'], |
| 659 | $field_values['draw']['create_on_referral'], |
| 660 | $field_values['closing']['closing_date_enable'], |
| 661 | _multiforms_implode_date($field_values['closing']['closing_date']), |
| 662 | $field_values['closing']['closing_time'], |
| 663 | $field_values['closing']['closing_text'], |
| 664 | $field_values['flow_type'], |
| 665 | $multiform_id |
| 666 | ); |
| 667 | |
| 668 | if ($result) { |
| 669 | |
| 670 | drupal_set_message(t('Multiform updated.')); |
| 671 | } |
| 672 | else { |
| 673 | |
| 674 | drupal_set_message(t('Error updating multiform!'), 'error'); |
| 675 | } |
| 676 | } |
| 677 | else { |
| 678 | |
| 679 | drupal_set_message(t('Could not find multiform associated with this node.'), 'error'); |
| 680 | } |
| 681 | |
| 682 | drupal_goto('node/'. arg(1) .'/view'); |
| 683 | } |
| 684 | |
| 685 | function multiforms_admin_delete($multiform_id) { |
| 686 | |
| 687 | $error_message = ''; |
| 688 | $multiform_deletion_error = 0; |
| 689 | $multiform_section_deletion_error = 0; |
| 690 | $multiform_field_deletion_error = 0; |
| 691 | |
| 692 | // purge data |
| 693 | $purge_error_message = _multiforms_admin_do_purge($multiform_id); |
| 694 | |
| 695 | // delete multiform |
| 696 | _multiforms_admin_delete('multiform', MULTIFORM_TABLE, 'multiform_id', $multiform_id); |
| 697 | |
| 698 | // delete multiform fields |
| 699 | $query = "SELECT multiform_section_id \r |
| 700 | FROM {". MULTIFORM_SECTION_TABLE ."} \r |
| 701 | WHERE multiform_section_multiform_id='%d'"; |
| 702 | |
| 703 | $result = db_query($query, $multiform_id); |
| 704 | |
| 705 | if ($result) { |
| 706 | |
| 707 | while ($row = db_fetch_object($result)) { |
| 708 | |
| 709 | _multiforms_admin_delete('field', MULTIFORM_FIELD_TABLE, 'multiform_field_section_id', $row->multiform_section_id); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | // delete multiform sections |
| 714 | if (!_multiforms_admin_delete('sections', MULTIFORM_SECTION_TABLE, 'multiform_section_multiform_id', $multiform_id)) { |
| 715 | |
| 716 | $multiform_section_deletion_error = 1; |
| 717 | } |
| 718 | |
| 719 | drupal_goto('admin'); |
| 720 | } |
| 721 | |
| 722 | function _multiforms_return_section_overview_form_array($form_name) { |
| 723 | |
| 724 | $form = array(); |
| 725 | |
| 726 | $form[$form_name]['submission'] = array( |
| 727 | '#type' => 'fieldset', |
| 728 | '#title' => t('Submission Form'), |
| 729 | '#tree' => TRUE |
| 730 | ); |
| 731 | |
| 732 | $form[$form_name]['submission']['link'] = array( |
| 733 | '#type' => 'markup', |
| 734 | ); |
| 735 | |
| 736 | $form[$form_name]['section']['list'] = array( |
| 737 | '#type' => 'markup', |
| 738 | ); |
| 739 | |
| 740 | $form[$form_name]['section'] = array( |
| 741 | '#type' => 'fieldset', |
| 742 | '#title' => t('Section Forms'), |
| 743 | '#tree' => TRUE |
| 744 | ); |
| 745 | |
| 746 | $form[$form_name]['section']['list'] = array( |
| 747 | '#title' => t('Section List'), |
| 748 | '#type' => 'markup', |
| 749 | ); |
| 750 | |
| 751 | $form[$form_name]['section']['intro'] = array( |
| 752 | '#title' => t('Section List Introduction/Header Text'), |
| 753 | '#type' => 'textarea', |
| 754 | '#description' => t('What text should be shown above the list of sections?') |
| 755 | ); |
| 756 | |
| 757 | $form[$form_name]['section']['footer'] = array( |
| 758 | '#title' => t('Section List Footer Text'), |
| 759 | '#type' => 'textarea', |
| 760 | '#description' => t('What text should be shown below the list of sections?') |
| 761 | ); |
| 762 | |
| 763 | $form[$form_name]['section']['submit'] = array( |
| 764 | '#type' => 'submit', |
| 765 | '#value' => t('Update') |
| 766 | ); |
| 767 | |
| 768 | return $form; |
| 769 | } |
| 770 | |
| 771 | function multiforms_admin_section_page($multiform_id, $section_to_edit = '') { |
| 772 | |
| 773 | if (is_numeric($section_to_edit)) { |
| 774 | |
| 775 | multiforms_admin_section_edit_page($section_to_edit); |
| 776 | |
| 777 | } |
| 778 | else { |
| 779 | |
| 780 | $section_list_html = _multiforms_section_list($multiform_id); |
| 781 | |
| 782 | $query = "SELECT * FROM {". MULTIFORM_TABLE ."} WHERE multiform_id='%d'"; |
| 783 | |
| 784 | $result = db_query($query, $multiform_id); |
| 785 | |
| 786 | if ($result) { |
| 787 | |
| 788 | if ($row = db_fetch_object($result)) { |
| 789 | |
| 790 | $output .= drupal_get_form('multiforms_admin_section', $multiform_id, $section_list_html); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | print theme('page', $output); |
| 795 | exit(); |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | function multiforms_admin_section($multiform_id, $section_list_html) { |
| 800 | |
| 801 | $form = _multiforms_return_section_overview_form_array('multiforms_admin_section'); |
| 802 | $form_name = 'multiforms_admin_section'; |
| 803 | |
| 804 | $form[$form_name]['submission']['link']['#value'] = |
| 805 | '» '. l(t('Edit Submission Form'), 'node/'. arg(1) .'/sections/-'. $multiform_id); |
| 806 | |
| 807 | $form[$form_name]['section']['list']['#value'] = $section_list_html; |
| 808 | |
| 809 | $query = "SELECT multiform_section_text, multiform_section_footer \r |
| 810 | FROM {". MULTIFORM_TABLE ."} \r |
| 811 | WHERE multiform_id='%d'"; |
| 812 | |
| 813 | $result = db_query($query, $multiform_id); |
| 814 | |
| 815 | if ($result) { |
| 816 | |
| 817 | if ($row = db_fetch_object($result)) { |
| 818 | |
| 819 | $form[$form_name]['section']['intro']['#default_value'] = |
| 820 | $row->multiform_section_text; |
| 821 | $form[$form_name]['section']['footer']['#default_value'] = |
| 822 | $row->multiform_section_footer; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | return $form; |
| 827 | } |
| 828 | |
| 829 | function multiforms_admin_section_submit($form_id, $form_values) { |
| 830 | |
| 831 | $multiform_id = _multiforms_get_multiform_id_from_nid(arg(1)); |
| 832 | |
| 833 | if ($multiform_id > 0) { |
| 834 | |
| 835 | $field_values = $form_values['section']; |
| 836 | |
| 837 | $query = "UPDATE {". MULTIFORM_TABLE ."} SET \r |
| 838 | multiform_section_text='%s', \r |
| 839 | multiform_section_footer='%s' \r |
| 840 | WHERE multiform_id='%d'"; |
| 841 | |
| 842 | $result = db_query($query, |
| 843 | $field_values['intro'], |
| 844 | $field_values['footer'], |
| 845 | $multiform_id |
| 846 | ); |
| 847 | |
| 848 | if ($result) { |
| 849 | |
| 850 | drupal_set_message(t('Multiform section setup updated.')); |
| 851 | } |
| 852 | else { |
| 853 | |
| 854 | drupal_set_message(t('Error updating multiform section setup.'), 'error'); |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | $_POST = ''; |
| 859 | multiforms_admin_section_page($multiform_id); |
| 860 | } |
| 861 | |
| 862 | function _multiforms_return_section_form_array($multiform_id, $form_name, $form_title, $submit_label) { |
| 863 | |
| 864 | $form = array(); |
| 865 | |
| 866 | $form[$form_name] = array( |
| 867 | '#type' => 'fieldset', |
| 868 | '#title' => t($form_title), |
| 869 | '#tree' => TRUE |
| 870 | ); |
| 871 | |
| 872 | $form[$form_name]['multiform_id'] = array( |
| 873 | '#type' => 'hidden', |
| 874 | '#value' => $multiform_id |
| 875 | ); |
| 876 | |
| 877 | $form[$form_name]['name'] = array( |
| 878 | '#title' => t('Name'), |
| 879 | '#type' => 'textfield', |
| 880 | '#required' => TRUE |
| 881 | ); |
| 882 | |
| 883 | $form[$form_name]['description'] = array( |
| 884 | '#title' => t('Description'), |
| 885 | '#type' => 'textarea' |
| 886 | ); |
| 887 | |
| 888 | $form[$form_name]['submit_button_text'] = array( |
| 889 | '#title' => t('Submit Button Text'), |
| 890 | '#type' => 'textfield', |
| 891 | '#description' => t('Defaults to "submit".') |
| 892 | ); |
| 893 | |
| 894 | $form[$form_name]['submit'] = array( |
| 895 | '#type' => 'submit', |
| 896 | '#value' => t($submit_label) |
| 897 | ); |
| 898 | |
| 899 | return $form; |
| 900 | } |
| 901 | |
| 902 | function multiforms_admin_section_add_page($multiform_id) { |
| 903 | |
| 904 | $output = ''; |
| 905 | |
| 906 | $output .= drupal_get_form('multiforms_admin_section_add', $multiform_id); |
| 907 | |
| 908 | print theme('page', $output); |
| 909 | } |
| 910 | |
| 911 | function multiforms_admin_section_add($multiform_id) { |
| 912 | |
| 913 | return _multiforms_return_section_form_array($multiform_id, 'multiforms_admin_section_add', 'Add Section', 'Add'); |
| 914 | } |
| 915 | |
| 916 | function multiforms_admin_section_add_submit($form_id, $form_values) { |
| 917 | |
| 918 | $field_values = $form_values['multiforms_admin_section_add']; |
| 919 | |
| 920 | $next_sortorder = _multiforms_admin_get_new_sortorder('multiform_sections', 'multiform_section_sortorder', 'multiform_section_multiform_id', $field_values['multiform_id']); |
| 921 | |
| 922 | if ($next_sortorder) { |
| 923 | |
| 924 | $query = "INSERT INTO {". MULTIFORM_SECTION_TABLE ."} \r |
| 925 | (multiform_section_multiform_id, multiform_section_name, multiform_section_description, \r |
| 926 | multiform_section_submit_button_text, multiform_section_sortorder) \r |
| 927 | VALUES ('%d', '%s', '%s', '%s', '%s')"; |
| 928 | |
| 929 | $result = db_query( |
| 930 | $query, |
| 931 | $field_values['multiform_id'], |
| 932 | $field_values['name'], |
| 933 | $field_values['description'], |
| 934 | $field_values['submit_button_text'], |
| 935 | $next_sortorder |
| 936 | ); |
| 937 | } |
| 938 | else { |
| 939 | |
| 940 | drupal_set_message(t("Error: Couldn't generate next sortorder."), 'error'); |
| 941 | } |
| 942 | |
| 943 | multiforms_admin_section_page($field_values['multiform_id']); |
| 944 | } |
| 945 | |
| 946 | function multiforms_admin_section_edit_page($section_id) { |
| 947 | |
| 948 | $output = ""; |
| 949 | |
| 950 | $form_name = 'multiforms_admin_section_edit'; |
| 951 | |
| 952 | // show name and description if not editing the submission form |
| 953 | if ($section_id > 0) { |
| 954 | |
| 955 | $output .= drupal_get_form($form_name, $form); |
| 956 | |
| 957 | $output .= '<h3>'. t('Section Fields') .'</h3>'; |
| 958 | |
| 959 | } |
| 960 | else { |
| 961 | |
| 962 | $output .= '<h3>'. t('Submission Form Fields') .'</h3>'; |
| 963 | } |
| 964 | |
| 965 | $output .= _multiforms_admin_section_field_list($section_id); |
| 966 | |
| 967 | $output .= '» '. l(t('Add New Field'), 'node/'. arg(1) .'/sections/fields/add/'. $section_id); |
| 968 | |
| 969 | $output .= '<p />'; |
| 970 | |
| 971 | $output .= drupal_get_form('multiforms_admin_snippet'); |
| 972 | |
| 973 | if (module_exists('actions')) { |
| 974 | |
| 975 | $output .= multiforms_admin_actions('section', $section_id, t('These actions will occur upon form submission.')); |
| 976 | } |
| 977 | |
| 978 | print theme('page', $output); |
| 979 | } |
| 980 | |
| 981 | function multiforms_admin_section_edit() { |
| 982 | |
| 983 | $form_name = 'multiforms_admin_section_edit'; |
| 984 | |
| 985 | $query = "SELECT * FROM {". MULTIFORM_SECTION_TABLE ."} WHERE multiform_section_id='%d'"; |
| 986 | |
| 987 | $result = db_query($query, arg(3)); |
| 988 | |
| 989 | if ($result) { |
| 990 | |
| 991 | if ($row = db_fetch_object($result)) { |
| 992 | |
| 993 | $form = _multiforms_return_section_form_array($row->multiform_section_multiform_id, $form_name, 'Edit Section', 'Update'); |
| 994 | |
| 995 | $form[$form_name]['name']['#default_value'] = $row->multiform_section_name; |
| 996 | $form[$form_name]['description']['#default_value'] = $row->multiform_section_description; |
| 997 | $form[$form_name]['submit_button_text']['#default_value'] = $row->multiform_section_submit_button_text; |
| 998 | |
| 999 | return $form; |
| 1000 | } |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | function multiforms_admin_section_edit_submit($form_id, $form_values) { |
| 1005 | |
| 1006 | $field_values = $form_values['multiforms_admin_section_edit']; |
| 1007 | |
| 1008 | $query = "UPDATE {". MULTIFORM_SECTION_TABLE ."} SET \r |
| 1009 | multiform_section_name='%s', \r |
| 1010 | multiform_section_description='%s', \r |
| 1011 | multiform_section_submit_button_text='%s', \r |
| 1012 | multiform_section_multiform_id='%d' \r |
| 1013 | WHERE multiform_section_id='%d'"; |
| 1014 | |
| 1015 | $result = db_query( |
| 1016 | $query, |
| 1017 | $field_values['name'], |
| 1018 | $field_values['description'], |
| 1019 | $field_values['submit_button_text'], |
| 1020 | $field_values['multiform_id'], |
| 1021 | arg(3) |
| 1022 | ); |
| 1023 | |
| 1024 | if ($result) { |
| 1025 | |
| 1026 | drupal_set_message(t('Section updated.')); |
| 1027 | } |
| 1028 | else { |
| 1029 | |
| 1030 | drupal_set_message(t('Error updating section!'), 'error'); |
| 1031 | |
| 1032 | } |
| 1033 | |
| 1034 | multiforms_admin_section_page($field_values['multiform_id']); |
| 1035 | } |
| 1036 | |
| 1037 | function _multiforms_admin_section_field_list($section_id) { |
| 1038 | |
| 1039 | $query = "SELECT * FROM {". MULTIFORM_FIELD_TABLE ."} \r |
| 1040 | WHERE multiform_field_section_id='%d' \r |
| 1041 | ORDER BY multiform_field_sortorder ASC"; |
| 1042 | |
| 1043 | $result = db_query($query, $section_id); |
| 1044 | |
| 1045 | $rows = array(); |
| 1046 | |
| 1047 | if ($result) { |
| 1048 | |
| 1049 | $row_count = db_num_rows($result); |
| 1050 | $count = 0; |
| 1051 | |
| 1052 | while ($row = db_fetch_object($result)) { |
| 1053 | |
| 1054 | if ($count) { |
| 1055 | |
| 1056 | $promote_link = l(t('Promote'), 'node/'. arg(1) .'/sections/fields/promote/'. $row->multiform_field_id); |
| 1057 | } |
| 1058 | else { |
| 1059 | |
| 1060 | $promote_link = ''; |
| 1061 | } |
| 1062 | |
| 1063 | if ($count < ($row_count - 1)) { |
| 1064 | |
| 1065 | $demote_link = l(t('Demote'), 'node/'. arg(1) .'/sections/fields/demote/'. $row->multiform_field_id); |
| 1066 | } |
| 1067 | else { |
| 1068 | |
| 1069 | $demote_link = ''; |
| 1070 | } |
| 1071 | |
| 1072 | $rows[] = array( |
| 1073 | $row->multiform_field_name .' ', |
| 1074 | $row->multiform_field_type .' ', |
| 1075 | $row->multiform_field_validation_type .' ', |
| 1076 | l(t('Edit'), 'node/'. arg(1) .'/sections/fields/edit/'. $row->multiform_field_id) .' ', |
| 1077 | l(t('Delete'), 'node/'. arg(1) .'/sections/fields/delete/'. $row->multiform_field_id), |
| 1078 | $promote_link .' ', |
| 1079 | $demote_link .' ' |
| 1080 | ); |
| 1081 | |
| 1082 | $count++; |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | if ($row_count) { |
| 1087 | |
| 1088 | $headers = array('Name', 'Type', 'Validation', '', '', '', ''); |
| 1089 | |
| 1090 | $output .= theme_table($headers, $rows); |
| 1091 | } |
| 1092 | else { |
| 1093 | |
| 1094 | $output .= t('No fields yet created. You should create one.') .'<p />'; |
| 1095 | } |
| 1096 | |
| 1097 | return $output; |
| 1098 | } |
| 1099 | |
| 1100 | function _multiforms_implode_date($date_array) { |
| 1101 | |
| 1102 | return implode('-', $date_array); |
| 1103 | } |
| 1104 | |
| 1105 | function _multiforms_admin_change_sortorder($database_table, $primary_key_column, $primary_key_value, $sortcolumn, $sortaction, $parent_column, $parent_id) { |
| 1106 | |
| 1107 | if ($sortaction == "promote") { |
| 1108 | |
| 1109 | $sortorder = "ASC"; |
| 1110 | } |
| 1111 | else { |
| 1112 | |
| 1113 | $sortorder = "DESC"; |
| 1114 | } |
| 1115 | |
| 1116 | $query = "SELECT %s, %s FROM {%s} WHERE %s='%d' ORDER BY %s %s"; |
| 1117 | |
| 1118 | $result = db_query($query, $sortcolumn, $primary_key_column, $database_table, $parent_column, $parent_id, $sortcolumn, $sortorder); |
| 1119 | |
| 1120 | $current_sortorder = 0; |
| 1121 | |
| 1122 | while ($row = db_fetch_object($result)) { |
| 1123 | |
| 1124 | // check if we've reached target row |
| 1125 | if ($row->$primary_key_column == $primary_key_value) { |
| 1126 | |
| 1127 | $query = "UPDATE {%s} SET %s=%s WHERE %s='%d'"; |
| 1128 | |
| 1129 | $result2 = db_query($query, $database_table, $sortcolumn, $previous_sortorder, $primary_key_column, $primary_key_value); |
| 1130 | $result2 = db_query($query, $database_table, $sortcolumn, $row->$sortcolumn, $primary_key_column, $previous_primary_key_value); |
| 1131 | } |
| 1132 | |
| 1133 | $previous_primary_key_value = $row->$primary_key_column; |
| 1134 | $previous_sortorder = $row->$sortcolumn; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | function _multiforms_admin_get_new_sortorder($database_table, $sortcolumn, $parent_column, $parent_id) { |
| 1139 | |
| 1140 | $query = "SELECT %s FROM {%s} WHERE %s='%d' ORDER BY %s DESC"; |
| 1141 | |
| 1142 | $result = db_query($query, $sortcolumn, $database_table, $parent_column, $parent_id, $sortcolumn); |
| 1143 | |
| 1144 | if ($row = db_fetch_object($result)) { |
| 1145 | |
| 1146 | $new_sortorder = $row->$sortcolumn + 1; |
| 1147 | } |
| 1148 | else { |
| 1149 | |
| 1150 | $new_sortorder = 1; |
| 1151 | } |
| 1152 | |
| 1153 | return $new_sortorder; |
| 1154 | } |
| 1155 | |
| 1156 | function multiforms_admin_section_promote($section_id) { |
| 1157 | |
| 1158 | $multiform_id = _multiforms_get_multiform_id_from_nid (arg(1)); |
| 1159 | |
| 1160 | _multiforms_admin_change_sortorder( |
| 1161 | 'multiform_sections', |
| 1162 | 'multiform_section_id', |
| 1163 | $section_id, |
| 1164 | 'multiform_section_sortorder', |
| 1165 | 'promote', |
| 1166 | 'multiform_section_multiform_id', |
| 1167 | $multiform_id |
| 1168 | ); |
| 1169 | |
| 1170 | drupal_set_message(t('Section promoted.')); |
| 1171 | |
| 1172 | drupal_goto('node/' . arg(1) . '/sections'); |
| 1173 | } |
| 1174 | |
| 1175 | function multiforms_admin_section_demote($section_id) { |
| 1176 | |
| 1177 | $multiform_id = _multiforms_get_multiform_id_from_nid (arg(1)); |
| 1178 | |
| 1179 | _multiforms_admin_change_sortorder( |
| 1180 | 'multiform_sections', |
| 1181 | 'multiform_section_id', |
| 1182 | $section_id, |
| 1183 | 'multiform_section_sortorder', |
| 1184 | 'demote', |
| 1185 | 'multiform_section_multiform_id', |
| 1186 | $multiform_id |
| 1187 | ); |
| 1188 | |
| 1189 | drupal_set_message(t('Section demoted.')); |
| 1190 | |
| 1191 | drupal_goto('node/' . arg(1) . '/sections'); |
| 1192 |