public static function handleElementFormPOST($post_data, &$cash_admin) { global $admin_primary_cash_request; if (AdminHelper::elementFormSubmitted($post_data)) { // first create the options array $options_array = array(); // now populate it from the POST data, fixing booleans $app_json = AdminHelper::getElementAppJSON($post_data['element_type']); if ($app_json) { foreach ($app_json['options'] as $section_name => $details) { foreach ($details['data'] as $data => $values) { if ($values['type'] == 'boolean') { if (isset($post_data[$data])) { $options_array[$data] = 1; } else { $options_array[$data] = 0; } } elseif ($values['type'] == 'options') { if (is_array($values['values'])) { foreach ($values['values'] as $subname => $subvalues) { $options_array[$data][$subname] = $post_data[$data . '-' . $subname]; } } } else { if ($values['type'] != 'scalar') { $options_array[$data] = $post_data[$data]; } } } } $scalars = AdminHelper::processScalarData($post_data, $app_json); $options_array = array_merge($options_array, $scalars); } if (isset($post_data['doelementadd'])) { // Adding a new element: $cash_admin->setCurrentElementState('add'); $admin_primary_cash_request->processRequest(array('cash_request_type' => 'element', 'cash_action' => 'addelement', 'name' => $post_data['element_name'], 'type' => $post_data['element_type'], 'options_data' => $options_array, 'user_id' => AdminHelper::getPersistentData('cash_effective_user'))); if ($admin_primary_cash_request->response['status_uid'] == 'element_addelement_200') { $current_campaign = false; if ($post_data['in_campaign']) { $current_campaign = $post_data['in_campaign']; } else { $current_campaign = AdminHelper::getPersistentData('current_campaign'); } if ($current_campaign) { $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'addelementtocampaign', 'campaign_id' => $current_campaign, 'element_id' => $admin_primary_cash_request->response['payload'])); // handle differently for AJAX and non-AJAX if ($cash_admin->page_data['data_only']) { AdminHelper::formSuccess('Success. New element added.', '/'); } else { $cash_admin->setCurrentElement($admin_primary_cash_request->response['payload']); } } else { // handle differently for AJAX and non-AJAX if ($cash_admin->page_data['data_only']) { AdminHelper::formSuccess('Success. New element added.', '/elements/edit/' . $admin_primary_cash_request->response['payload']); } else { $cash_admin->setCurrentElement($admin_primary_cash_request->response['payload']); } } } else { // handle differently for AJAX and non-AJAX if ($cash_admin->page_data['data_only']) { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/elements/add/' . $post_data['element_type']); } else { $cash_admin->setErrorState('element_add_failure'); } } } elseif (isset($post_data['doelementedit'])) { // Editing an existing element: $cash_admin->setCurrentElementState('edit'); $admin_primary_cash_request->processRequest(array('cash_request_type' => 'element', 'cash_action' => 'editelement', 'id' => $post_data['element_id'], 'name' => $post_data['element_name'], 'options_data' => $options_array)); if ($admin_primary_cash_request->response['status_uid'] == 'element_editelement_200') { // handle differently for AJAX and non-AJAX if ($cash_admin->page_data['data_only']) { // AJAX AdminHelper::formSuccess('Success. Edited.', '/elements/edit/' . $post_data['element_id']); } else { // non-AJAX $cash_admin->setCurrentElement($post_data['element_id']); } } else { // handle differently for AJAX and non-AJAX if ($cash_admin->page_data['data_only']) { // AJAX AdminHelper::formFailure('Error. Something just didn\'t work right.', '/elements/edit/' . $post_data['element_id']); } else { // non-AJAX $cash_admin->setErrorState('element_edit_failure'); } } } AdminHelper::setBasicElementFormData($cash_admin); } }
$cash_admin->page_data['needed_requirements'] .= '<a href="' . $cash_admin->page_data['www_path'] . $requirements_links[$requirement] . '">'; } $cash_admin->page_data['needed_requirements'] .= $cash_admin->page_data['copy_requirement_' . $requirement]; if (isset($requirements_links[$requirement])) { $cash_admin->page_data['needed_requirements'] .= '</a>'; } $cash_admin->page_data['needed_requirements'] .= '</li>'; } } $cash_admin->page_data['needed_requirements'] .= '</ul>'; //$cash_admin->page_data['ui_title'] = 'Add ' . $app_json['details']['en']['name'] . ' Element'; $cash_admin->page_data['ui_title'] = ''; $cash_admin->page_data['copy_longdescription'] = $app_json['details']['en']['longdescription']; } } } else { $cash_admin->page_data['element_rendered_content'] = "You're trying to add an unsupported element. That's lame."; } $cash_admin->setPageContentTemplate('elements_add_selected'); } else { $elementcollection = array(); $colcount = 1; foreach ($supported_elements as $element) { $app_json = AdminHelper::getElementAppJSON($element); $formatted_element = array('element_type' => $element, 'element_type_name' => $app_json['details']['en']['name'], 'element_type_description' => $app_json['details']['en']['description'], 'element_type_longdescription' => $app_json['details']['en']['longdescription'], 'element_type_author' => $app_json['author'], 'element_type_authorurl' => $app_json['url'], 'element_type_updated' => $app_json['lastupdated'], 'element_type_version' => $app_json['version']); $elementcollection[] = $formatted_element; } $cash_admin->page_data['elements_output'] = new ArrayIterator($elementcollection); $cash_admin->page_data['ui_title'] = 'Add an element'; $cash_admin->setPageContentTemplate('elements_add_select'); }