public static function handleRedirectReturn($data = false) { $connections = CASHSystem::getSystemSettings('system_connections'); if (isset($connections['com.amazon'])) { $s3_default_email = $connections['com.amazon']['email']; } else { $s3_default_email = false; } $success = S3Seed::connectAndAuthorize($data['key'], $data['secret'], $data['bucket'], $s3_default_email); if ($success) { // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $connection_name = $data['bucket'] . ' (Amazon S3)'; if (substr($connection_name, 0, 10) == 'cashmusic.') { $connection_name = 'Amazon S3 (created ' . date("M j, Y") . ')'; } $result = $new_connection->setSettings($connection_name, 'com.amazon', array('bucket' => $data['bucket'])); if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.'); } } else { //$return_markup = '<h4>Error</h4>' // . '<p>We couldn\'t connect with your S3 account. Please check the key and secret.</p>'; AdminHelper::formFailure('We couldn\'t connect your S3 account. Please check the key and secret.'); } return $return_markup; }
<?php if (!$request_parameters) { AdminHelper::controllerRedirect('/people/lists/'); } if (isset($_POST['dodelete']) || isset($_REQUEST['modalconfirm'])) { $delete_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'deletelist', 'list_id' => $request_parameters[0])); if ($delete_response['status_uid'] == 'people_deletelist_200') { if (isset($_REQUEST['redirectto'])) { AdminHelper::formSuccess('Success. Deleted.', $_REQUEST['redirectto']); } else { AdminHelper::formSuccess('Success. Deleted.', '/people/lists/'); } } } $cash_admin->page_data['title'] = 'People: Delete list'; $cash_admin->setPageContentTemplate('delete_confirm');
public static function handleRedirectReturn($data = false) { if (!isset($data['state'])) { return "Please start the Dropbox authentication flow from the beginning."; } $connections = CASHSystem::getSystemSettings('system_connections'); if (!isset($connections['com.dropbox'])) { return 'Please add default Dropbox credentials.'; } $auth_client = DropboxSeed::getWebAuthClient($connections['com.dropbox']['redirect_uri']); try { list($token, $user_id) = $auth_client->finish($data); } catch (Exception $e) { $token = false; } if (!$token) { return "The Dropbox authentication flow failed - please try again."; } $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($user_id . ' (Dropbox)', 'com.dropbox', array('access_token' => $token, 'user_id' => $user_id)); if (!$result) { $settings_for_user = $new_connection->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $connection_data) { if ($connection_data['name'] == $user_id . ' (Dropbox)') { $result = $connection_data['id']; break; } } } } if (isset($data['return_result_directly'])) { return $result; } else { if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/settings/connections/'); } } }
$addvenue_address1 = ''; $addvenue_address2 = ''; $addvenue_postalcode = ''; $addvenue_url = ''; $addvenue_phone = ''; if (isset($_POST['venue_address1'])) { $addvenue_address1 = $_POST['venue_address1']; } if (isset($_POST['venue_address2'])) { $addvenue_address2 = $_POST['venue_address2']; } if (isset($_POST['venue_postalcode'])) { $addvenue_postalcode = $_POST['venue_postalcode']; } if (isset($_POST['venue_url'])) { $addvenue_url = $_POST['venue_url']; } if (isset($_POST['venue_phone'])) { $addvenue_phone = $_POST['venue_phone']; } $add_response = $cash_admin->requestAndStore(array('cash_request_type' => 'calendar', 'cash_action' => 'addvenue', 'name' => $_POST['venue_name'], 'city' => $_POST['venue_city'], 'region' => $_POST['venue_region'], 'country' => $_POST['venue_country'], 'address1' => $addvenue_address1, 'address2' => $addvenue_address2, 'postalcode' => $addvenue_postalcode, 'url' => $addvenue_url, 'phone' => $addvenue_phone)); if ($add_response['payload']) { AdminHelper::formSuccess('Success. Venue added.', '/calendar/venues/edit/' . $add_response['payload']); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/calendar/venues/add/'); } } $cash_admin->page_data['form_state_action'] = 'dovenueadd'; $cash_admin->page_data['venue_button_text'] = 'Add the venue'; $cash_admin->page_data['country_options'] = AdminHelper::drawCountryCodeUL(); $cash_admin->setPageContentTemplate('calendar_venues_details');
<?php if (isset($_REQUEST['modalconfirm'])) { $new_template = 0; $requested_campaign_id = $request_parameters[0]; if ($requested_campaign_id != 0) { $current_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'getcampaign', 'id' => $requested_campaign_id)); $campaign = $current_response['payload']; $new_template = $campaign['template_id']; } $settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'setsettings', 'type' => 'public_profile_template', 'value' => $new_template, 'user_id' => $cash_admin->effective_user_id)); if ($settings_response['payload']) { if ($new_template == 0) { AdminHelper::formSuccess('Success. You have unpublished all campaigns.', '/'); } else { AdminHelper::formSuccess('Success. Campaign published.', '/'); } } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/'); } } else { AdminHelper::controllerRedirect('/'); }
<?php // first handle add if (isset($_POST['dotemplateset'])) { // form was submitted. set the template $effective_user = $cash_admin->effective_user_id; if (!isset($_POST['template_id'])) { $template_id = false; } else { $template_id = $_POST['template_id']; } $template_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'settemplate', 'template' => $_POST['template'], 'template_id' => $template_id, 'user_id' => $effective_user)); if ($template_response['payload']) { AdminHelper::formSuccess('Success.', '/elements/templates/' . $template_response['payload']); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/elements/templates/'); } } // get all the templates $template_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'gettemplatesforuser', 'user_id' => $cash_admin->effective_user_id)); if (is_array($template_response['payload'])) { $page_templates = array(); $embed_templates = array(); foreach ($template_response['payload'] as $template) { if ($template['type'] == 'page') { $page_templates[] = $template; } elseif ($template['type'] == 'embed') { $embed_templates[] = $template; } } if (count($page_templates)) {
<?php // parsing posted data: if (isset($_POST['docampaignadd'])) { // do the actual list add stuffs... $effective_user = $cash_admin->effective_user_id; $add_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'addcampaign', 'title' => $_POST['campaign_title'], 'description' => $_POST['campaign_description'], 'user_id' => $effective_user)); if ($add_response['payload']) { // make the new campaign selected $admin_primary_cash_request->sessionSet('current_campaign', $add_response['payload']); $settings_request = new CASHRequest(array('cash_request_type' => 'system', 'cash_action' => 'setsettings', 'type' => 'selected_campaign', 'value' => $add_response['payload'], 'user_id' => $cash_admin->effective_user_id)); AdminHelper::formSuccess('Success. Campaign added.', '/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/campaigns/add/'); } } $cash_admin->page_data['form_state_action'] = 'docampaignadd'; $cash_admin->page_data['button_text'] = 'Save changes'; $cash_admin->setPageContentTemplate('campaign_edit');
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); } }
<?php if (isset($_POST['dodelete']) || isset($_REQUEST['modalconfirm'])) { $delete_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'deletelogin', 'address' => $admin_primary_cash_request->sessionGet('cash_effective_user_email'))); if ($delete_response['status_uid'] == 'system_deletelogin_200') { AdminHelper::formSuccess('Success. Deleted.', '/logout/'); } } $cash_admin->page_data['title'] = 'Account: Delete account'; $cash_admin->setPageContentTemplate('delete_confirm');
***************************************************************************/ // receipt request requested if (isset($_POST['resend_store_url'])) { $resend_response = $cash_admin->requestAndStore(array('cash_request_type' => 'commerce', 'cash_action' => 'sendorderreceipt', 'id' => $request_parameters[0], 'finalize_url' => $_POST['resend_store_url'])); AdminHelper::formSuccess('Receipt sent!', '/commerce/orders/view/' . $request_parameters[0]); } // edit order notes if (isset($_POST['ordernotes'])) { $order_details_response = $cash_admin->requestAndStore(array('cash_request_type' => 'commerce', 'cash_action' => 'editorder', 'id' => $request_parameters[0], 'notes' => $_POST['ordernotes'])); AdminHelper::formSuccess('Changes saved.', '/commerce/orders/view/' . $request_parameters[0]); } // mark order as fulfilled if (isset($request_parameters[1])) { if ($request_parameters[1] == 'fulfilled') { $order_details_response = $cash_admin->requestAndStore(array('cash_request_type' => 'commerce', 'cash_action' => 'editorder', 'id' => $request_parameters[0], 'fulfilled' => 1)); AdminHelper::formSuccess('Order fulfilled.', '/commerce/orders/view/' . $request_parameters[0]); } /* else if ($request_parameters[1] == 'cancel') { $order_cancel_response = $cash_admin->requestAndStore( array( 'cash_request_type' => 'commerce', 'cash_action' => 'cancelorder', 'id' => $request_parameters[0] ) ); if ($order_cancel_response['payload']) { AdminHelper::formSuccess('Order cancelled.','/commerce/orders/view/' . $request_parameters[0]); } else { AdminHelper::formFailure('Try again.','/commerce/orders/view/' . $request_parameters[0]); } } */
<?php $cash_admin->page_data['country_codes'] = AdminHelper::drawCountryCodeUL(); $effective_user = $cash_admin->effective_user_id; if (isset($_POST['docontactadd'])) { $add_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'addcontact', 'user_id' => $effective_user, 'email_address' => $_POST['email_address'], 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'organization' => $_POST['organization'], 'address_line1' => $_POST['address1'], 'address_city' => $_POST['address_city'], 'address_region' => $_POST['address_region'], 'address_postalcode' => $_POST['address_postalcode'], 'address_country' => $_POST['address_country'], 'phone' => $_POST['phone'])); if ($add_response['payload']) { AdminHelper::formSuccess('Success. Contact added.'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.'); } } $initials_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'getcontactinitials', 'user_id' => $effective_user)); if ($initials_response['payload']) { $alphabet = array('A' => array('letter' => 'A', 'contact' => false), 'B' => array('letter' => 'B', 'contact' => false), 'C' => array('letter' => 'C', 'contact' => false), 'D' => array('letter' => 'D', 'contact' => false), 'E' => array('letter' => 'E', 'contact' => false), 'F' => array('letter' => 'F', 'contact' => false), 'G' => array('letter' => 'G', 'contact' => false), 'H' => array('letter' => 'H', 'contact' => false), 'I' => array('letter' => 'I', 'contact' => false), 'J' => array('letter' => 'J', 'contact' => false), 'K' => array('letter' => 'K', 'contact' => false), 'L' => array('letter' => 'L', 'contact' => false), 'M' => array('letter' => 'M', 'contact' => false), 'N' => array('letter' => 'N', 'contact' => false), 'O' => array('letter' => 'O', 'contact' => false), 'P' => array('letter' => 'P', 'contact' => false), 'Q' => array('letter' => 'Q', 'contact' => false), 'R' => array('letter' => 'R', 'contact' => false), 'S' => array('letter' => 'S', 'contact' => false), 'T' => array('letter' => 'T', 'contact' => false), 'U' => array('letter' => 'U', 'contact' => false), 'V' => array('letter' => 'V', 'contact' => false), 'W' => array('letter' => 'W', 'contact' => false), 'X' => array('letter' => 'X', 'contact' => false), 'Y' => array('letter' => 'Y', 'contact' => false), 'Z' => array('letter' => 'Z', 'contact' => false)); if (is_array($initials_response['payload'])) { foreach ($initials_response['payload'] as $value) { if (array_key_exists($value['initial'], $alphabet)) { $alphabet[$value['initial']]['contact'] = true; } } $cash_admin->page_data['alphabet'] = new ArrayIterator($alphabet); } } if (isset($request_parameters[1])) { if ($request_parameters[0] == 'bylastname') { $contacts_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'getcontactsbyinitials', 'user_id' => $effective_user, 'initial' => $request_parameters[1])); if ($contacts_response['payload']) { $cash_admin->page_data['contact_list'] = new ArrayIterator($contacts_response['payload']); } }
<?php $misc_message = false; if (isset($_POST['domisc'])) { CASHSystem::setSystemSetting('timezone', $_POST['timezone']); CASHSystem::setSystemSetting('systememail', $_POST['systememail']); AdminHelper::formSuccess('Success. All changed.'); } $migrate_message = false; if (isset($_POST['domigrate'])) { $new_settings = array('hostname' => $_POST['hostname'], 'username' => $_POST['adminuser'], 'password' => $_POST['adminpassword'], 'database' => $_POST['databasename']); $migrate_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'migratedb', 'todriver' => $_POST['driver'], 'tosettings' => $new_settings)); if ($migrate_response['payload']) { AdminHelper::formSuccess('Success. Database upgraded. Enjoy!'); } else { AdminHelper::formFailure('Error. There was a problem migrating your data.'); } } $platform_settings = CASHSystem::getSystemSettings(); $cash_admin->page_data['system_email'] = $platform_settings['systememail']; $cash_admin->page_data['timezone_options'] = AdminHelper::drawTimeZones($platform_settings['timezone']); $db_types = array('mysql' => 'MySQL', 'sqlite' => 'SQLite'); $db_type = 'unknown'; if (array_key_exists($platform_settings['driver'], $db_types)) { $cash_admin->page_data['db_type'] = $db_types[$platform_settings['driver']]; } if ($cash_admin->page_data['db_type'] == 'MySQL') { $cash_admin->page_data['migrate_from_mysql'] = true; } elseif ($cash_admin->page_data['db_type'] == 'SQLite') { $cash_admin->page_data['migrate_from_sqlite'] = true; }
} else { AdminHelper::formFailure('Error. There was a problem editing.'); } } if (isset($_POST['dobatchcontactsadd'])) { if (!empty($_POST['element_content'])) { $email_array = array_map('trim', explode(",", str_replace(PHP_EOL, ',', $_POST['element_content']))); if (count($email_array) > 0) { $total_added = 0; foreach ($email_array as $address) { $add_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'addaddresstolist', 'do_not_verify' => 1, 'address' => $address, 'list_id' => $request_parameters[0])); if ($add_response['payload']) { $total_added++; } } AdminHelper::formSuccess('Success. Added ' . $total_added . ' new people.', '/people/lists/view/' . $request_parameters[0]); } else { AdminHelper::formFailure('Error. There was a problem adding new people.', '/people/lists/view/' . $request_parameters[0]); } } else { $cash_admin->page_data['error_message'] = 'Error. Please try again.'; } } $current_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'getlist', 'list_id' => $request_parameters[0])); $cash_admin->page_data['ui_title'] = '' . $current_response['payload']['name'] . ''; $current_list = $current_response['payload']; $cash_admin->page_data['no_selected_connection'] = true; if (is_array($current_list)) { $cash_admin->page_data = array_merge($cash_admin->page_data, $current_list); if ($current_list['connection_id'] != 0) { $cash_admin->page_data['no_selected_connection'] = false;
} if (isset($_POST['pagetheme'])) { if ($_POST['pagetheme'] == 'light') { $template_default = str_replace('<body', '<body class="light"', $template_default); } else { if ($_POST['pagetheme'] == 'dark') { $template_default = str_replace('<body', '<body class="dark"', $template_default); } } } $template_default = str_replace('{{{element_n}}}', $replacement, $template_default); $template_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'settemplate', 'name' => '', 'type' => 'page', 'template' => $template_default, 'user_id' => $cash_admin->effective_user_id)); $template_id = $template_response['payload']; $edit_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'editcampaign', 'id' => $requested_campaign_id, 'template_id' => $template_id)); if ($edit_response['payload']) { AdminHelper::formSuccess('Success. Page theme created. You can edit it at any time.', '/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/'); } } } else { // you're a wizard now, harry! $new_template = 0; $requested_campaign_id = $request_parameters[0]; $current_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'getcampaign', 'id' => $requested_campaign_id)); $campaign = $current_response['payload']; if ($campaign['template_id'] != 0) { // no points for gryffindor AdminHelper::controllerRedirect('/elements/templates/edit/' . $campaign['template_id'] . '/page/parent/' . $requested_campaign_id); } $elements_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'getelementsforcampaign', 'id' => $requested_campaign_id));
foreach ($settings_types_data[$settings_type]['dataTypes'][$cash_admin->platform_type] as $key => $data) { $settings_data_array[$key] = $_POST[$key]; } $result = $page_data_object->setSettings($_POST['settings_name'], $_POST['settings_type'], $settings_data_array, $_POST['connection_id']); if ($result) { $cash_admin->page_data['action_message'] = '<strong>Success.</strong> All changed. See connection below.'; } else { $cash_admin->page_data['action_message'] = '<strong>Error.</strong> Something went wrong.'; } } break; case 'delete': $connection_id = $request_parameters[1]; $result = $page_data_object->deleteSettings($connection_id); if ($result) { AdminHelper::formSuccess('Success. Deleted. Sad.', '/'); //$cash_admin->page_data['action_message'] = '<strong>Success.</strong> All gone. Sad.'; } else { AdminHelper::formFailure('Something went wrong.', '/'); //$cash_admin->page_data['action_message'] = '<strong>Error.</strong> Something went wrong.'; } break; } } if (!$settings_action || isset($_POST['dosettingsadd']) || isset($_POST['dosettingsedit']) || $settings_action == 'delete') { $cash_admin->page_data['state_markup'] = '<h4>Current connections:</h4>' . '<p>Here are the settings that have already been added:</p>'; $settings_for_user = $page_data_object->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $data) { $cash_admin->page_data['state_markup'] .= '<div class="callout">' . '<h6>' . $data['name'] . '</h6>'; if (array_key_exists($data['type'], $settings_types_data)) {
$cash_admin->runAtLogin(); AdminHelper::formSuccess('Welcome!', '/'); } else { AdminHelper::formFailure('Please try again.', '/'); } } else { AdminHelper::formFailure('Please try again.', '/'); } } } } // and this for the actual password reset after return folks submit the reset form: if (isset($_POST['finalizepasswordreset'])) { $valid_key = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'validateresetflag', 'address' => $_POST['address'], 'key' => $_POST['key'])); if ($valid_key) { $id_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'getuseridforaddress', 'address' => $_POST['address'])); if ($id_response['payload']) { $change_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'setlogincredentials', 'user_id' => $id_response['payload'], 'address' => $_POST['address'], 'password' => $_POST['new_password'], 'is_admin' => 1)); if ($change_response['payload'] !== false) { AdminHelper::formSuccess('Successfully changed the password. Go ahead and log in.', '/'); } else { AdminHelper::formFailure('There was an error setting your password. Please try again.', '/'); } } else { AdminHelper::formFailure('There was an error setting the password. Please try again.', '/'); } } } $cash_admin->setPageContentTemplate('login'); } }
<?php // parsing posted data: if (isset($_POST['dolistadd'])) { // do the actual list add stuffs... $effective_user = $cash_admin->effective_user_id; $add_response = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'addlist', 'name' => $_POST['list_name'], 'description' => $_POST['list_description'], 'connection_id' => $_POST['connection_id'], 'user_id' => $effective_user)); if ($add_response['payload']) { AdminHelper::formSuccess('Success. List added.', '/people/' . $add_response['payload']); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/people/lists/add/'); } } $cash_admin->page_data['connection_options'] = AdminHelper::echoConnectionsOptions('lists', 0, true); $cash_admin->page_data['form_state_action'] = 'dolistadd'; $cash_admin->page_data['list_button_text'] = 'Add a list'; $cash_admin->setPageContentTemplate('people_lists_add');
<?php if (!$request_parameters) { AdminHelper::controllerRedirect('/elements/templates/'); } if (isset($_POST['dodelete']) || isset($_REQUEST['modalconfirm'])) { $delete_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'deletetemplate', 'template_id' => $request_parameters[0])); if ($delete_response['status_uid'] == 'system_deletetemplate_200') { AdminHelper::formSuccess('Success. Deleted.', '/elements/templates/'); } } $cash_admin->page_data['title'] = 'Elements: Delete template'; $cash_admin->setPageContentTemplate('delete_confirm');
public static function handleRedirectReturn($data = false) { if (isset($data['code'])) { $connections = CASHSystem::getSystemSettings('system_connections'); if (isset($connections['com.google.drive'])) { $credentials = GoogleDriveSeed::exchangeCode($data['code'], $connections['com.google.drive']['client_id'], $connections['com.google.drive']['client_secret'], $connections['com.google.drive']['redirect_uri']); $user_info = GoogleDriveSeed::getUserInfo($credentials, $connections['com.google.drive']['client_id'], $connections['com.google.drive']['client_secret']); if ($user_info) { $email_address = $user_info['email']; $user_id = $user_info['id']; } else { $email_address = false; $user_id = false; } $credentials_array = json_decode($credentials, true); if (isset($credentials_array['refresh_token'])) { // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($email_address . ' (Google Drive)', 'com.google.drive', array('user_id' => $user_id, 'email_address' => $email_address, 'access_token' => $credentials, 'access_expires' => $credentials_array['created'] + $credentials_array['expires_in'], 'refresh_token' => $credentials_array['refresh_token'])); if (!$result) { $settings_for_user = $new_connection->getAllConnectionsforUser(); if (is_array($settings_for_user)) { foreach ($settings_for_user as $key => $connection_data) { if ($connection_data['name'] == $email_address . ' (Google Drive)') { $result = $connection_data['id']; break; } } } } if (isset($data['return_result_directly'])) { return $result; } else { if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/settings/connections/'); } } } else { return 'Could not find a refresh token from google'; } } else { return 'Please add default google drive app credentials.'; } } else { return 'There was an error. (session) Please try again.'; } }
<?php // parsing posted data: if (isset($_POST['doeventadd'])) { // do the actual list add stuffs... $effective_user = $cash_admin->effective_user_id; $eventispublished = 0; $eventiscancelled = 0; if (isset($_POST['event_ispublished'])) { $eventispublished = 1; } if (isset($_POST['event_iscancelled'])) { $eventiscancelled = 1; } $add_response = $cash_admin->requestAndStore(array('cash_request_type' => 'calendar', 'cash_action' => 'addevent', 'date' => strtotime($_POST['event_date']), 'venue_id' => $_POST['event_venue'], 'comment' => $_POST['event_comment'], 'purchase_url' => $_POST['event_purchase_url'], 'published' => $eventispublished, 'cancelled' => $eventiscancelled, 'user_id' => $effective_user)); if ($add_response['payload']) { AdminHelper::formSuccess('Success. Event added.', '/calendar/events/edit/' . $add_response['payload']); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/calendar/events/add/'); } } $cash_admin->page_data['venue_options'] = AdminHelper::echoFormOptions('venues', 0, false, true); $cash_admin->page_data['form_state_action'] = 'doeventadd'; $cash_admin->page_data['event_button_text'] = 'Add the event'; $cash_admin->setPageContentTemplate('calendar_events_details');
public static function handleRedirectReturn($data = false) { if (isset($data['error'])) { return 'There was an error. (general) Please try again.'; } else { $connections = CASHSystem::getSystemSettings('system_connections'); require_once CASH_PLATFORM_ROOT . '/lib/twitter/OAuth.php'; require_once CASH_PLATFORM_ROOT . '/lib/twitter/twitteroauth.php'; $temporary_credentials = AdminHelper::getPersistentData('twitter_temporary_credentials'); $twitter = new TwitterOAuth($connections['com.twitter']['client_id'], $connections['com.teitter']['client_secret'], $temporary_credentials['oauth_token'], $temporary_credentials['oauth_token_secret']); $access_token = $twitter->getAccessToken($_REQUEST['oauth_verifier']); if ($twitter->http_code == 200) { // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings('@' . $access_token['screen_name'] . ' (Twitter)', 'com.twitter', array('token' => $access_token)); if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Could not save connection.', '/settings/connections/'); } } else { AdminHelper::formFailure('Error. Problem communicating with Twitter', '/settings/connections/'); } } }
<?php if (!$request_parameters) { AdminHelper::controllerRedirect('/assets/'); } if (isset($_POST['dodelete']) || isset($_REQUEST['modalconfirm'])) { $delete_response = $cash_admin->requestAndStore(array('cash_request_type' => 'asset', 'cash_action' => 'deleteasset', 'id' => $request_parameters[0])); if ($delete_response['status_uid'] == 'asset_deleteasset_200') { AdminHelper::formSuccess('Success. Deleted.', '/assets/'); } } $cash_admin->page_data['title'] = 'Assets: Delete asset'; $cash_admin->setPageContentTemplate('delete_confirm');
<?php $effective_user = $cash_admin->effective_user_id; if ($request_parameters) { if (isset($request_parameters[1])) { if ($request_parameters[1] == 'fulfilled') { $order_details_response = $cash_admin->requestAndStore(array('cash_request_type' => 'commerce', 'cash_action' => 'editorder', 'id' => $request_parameters[0], 'fulfilled' => 1)); AdminHelper::formSuccess('Order fulfilled.', '/commerce/orders/view/' . $request_parameters[0]); } } if (isset($_POST['ordernotes'])) { $order_details_response = $cash_admin->requestAndStore(array('cash_request_type' => 'commerce', 'cash_action' => 'editorder', 'id' => $request_parameters[0], 'notes' => $_POST['ordernotes'])); AdminHelper::formSuccess('Changes saved.', '/commerce/orders/view/' . $request_parameters[0]); } $order_details_response = $cash_admin->requestAndStore(array('cash_request_type' => 'commerce', 'cash_action' => 'getorder', 'id' => $request_parameters[0], 'deep' => true)); $order_details = $order_details_response['payload']; if ($order_details['user_id'] == $effective_user) { $order_contents = json_decode($order_details['order_contents'], true); $item_price = 0; foreach ($order_contents as $key => &$item) { if (!isset($item['qty'])) { $item['qty'] = 1; } $item['price'] = $item['qty'] * $item['price']; $item_price += $item['price']; $item['price'] = number_format($item['price'], 2); // TODO: stealing the variant parser from CommercePlant::getOrderTotals // we know this is going to change so no sense streamlining yet // FIX LATER if (isset($item['variant'])) { preg_match_all("/([a-z]+)->/", $item['variant'], $key_parts);
if (is_array($settings_response['payload'])) { $pp_default = $settings_response['payload']['pp_default']; $pp_micro = $settings_response['payload']['pp_micro']; } else { $pp_default = 0; $pp_micro = 0; } $cash_admin->page_data['currency_options'] = AdminHelper::echoCurrencyOptions($current_currency); $pp = array(); foreach ($page_data_object->getConnectionsByType('com.paypal') as $ppq) { $pp[$ppq['id']] = $ppq['name']; } $cash_admin->page_data['paypal_default_options'] = AdminHelper::echoFormOptions($pp, $pp_default, false, true); $cash_admin->page_data['paypal_micro_options'] = AdminHelper::echoFormOptions($pp, $pp_micro, false, true); // handle regions if (isset($_POST['region1'])) { $regions = array('region1' => $_POST['region1'], 'region2' => $_POST['region2']); $settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'setsettings', 'type' => 'regions', 'value' => $regions, 'user_id' => $cash_admin->effective_user_id)); if ($settings_response['payload']) { AdminHelper::formSuccess('Success.', '/commerce/'); } } // now get the current setting $settings_response = $cash_admin->requestAndStore(array('cash_request_type' => 'system', 'cash_action' => 'getsettings', 'type' => 'regions', 'user_id' => $cash_admin->effective_user_id)); if ($settings_response['payload']) { $cash_admin->page_data['region1'] = $settings_response['payload']['region1']; $cash_admin->page_data['region2'] = $settings_response['payload']['region2']; } else { $cash_admin->page_data['noshippingregions'] = true; } $cash_admin->setPageContentTemplate('commerce');
<?php if (!$request_parameters) { AdminHelper::controllerRedirect('/commerce/items/'); } if (isset($_POST['dodelete']) || isset($_REQUEST['modalconfirm'])) { $item_delete_response = $cash_admin->requestAndStore(array('cash_request_type' => 'commerce', 'cash_action' => 'deleteitem', 'id' => $request_parameters[0])); if ($item_delete_response['status_uid'] == 'commerce_deleteitem_200') { AdminHelper::formSuccess('Success. Deleted.', '/commerce/items/'); } } $cash_admin->page_data['title'] = 'Commerce: Delete item'; $cash_admin->setPageContentTemplate('delete_confirm');
if ($_POST['metadata_command'] == 'setmetadata') { $new_metadata[$_POST['metadata_name']] = $add_response['payload']; } else { if ($_POST['metadata_command'] == 'addtometadata') { if (!isset($new_metadata[$_POST['metadata_name']])) { $new_metadata[$_POST['metadata_name']] = array(); } $new_metadata[$_POST['metadata_name']][] = $add_response['payload']; } } // now make the actual edits $effective_user = $cash_admin->effective_user_id; $edit_response = $cash_admin->requestAndStore(array('cash_request_type' => 'asset', 'cash_action' => 'editasset', 'id' => $_POST['parent_id'], 'user_id' => $effective_user, 'metadata' => $new_metadata)); } } AdminHelper::formSuccess('Success. Asset added. Feel free to start adding details.', '/assets/edit/' . $add_response['payload']); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.', '/assets/add/'); } } $cash_admin->page_data['form_state_action'] = 'doassetadd'; $cash_admin->page_data['asset_button_text'] = 'Save changes'; // create type options with current selected: if (isset($request_parameters[0])) { $add_type = $request_parameters[0]; $cash_admin->page_data['type'] = $add_type; $cash_admin->page_data['ui_title'] = 'Assets: Add a ' . $add_type; if ($add_type == 'file') { // connection options markup: $cash_admin->page_data['connection_options'] = '<option value="0" selected="selected">None (Normal http:// link)</option>'; $cash_admin->page_data['connection_options'] .= AdminHelper::echoConnectionsOptions('assets', 0, true);
<?php if (!$request_parameters) { AdminHelper::controllerRedirect('/elements/view/'); } if (isset($_POST['dodelete']) || isset($_REQUEST['modalconfirm'])) { $delete_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'deleteelement', 'id' => $request_parameters[0])); if ($delete_response['status_uid'] == 'element_deleteelement_200') { // look for the element in a campaign. if it's there, remove it. $campaign_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'getcampaignforelement', 'id' => $request_parameters[0])); if ($campaign_response['payload']) { $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'removeelementfromcampaign', 'campaign_id' => $campaign_response['payload']['id'], 'element_id' => $request_parameters[0])); AdminHelper::formSuccess('Success. Deleted.', '/'); } if (isset($_REQUEST['redirectto'])) { AdminHelper::formSuccess('Success. Deleted.', $_REQUEST['redirectto']); } else { AdminHelper::formSuccess('Success. Deleted.', '/elements/view/'); } } } $cash_admin->page_data['title'] = 'Elements: Delete element'; $cash_admin->setPageContentTemplate('delete_confirm');
if ($_POST['new_password']) { if (!defined('MINIMUM_PASSWORD_LENGTH')) { define('MINIMUM_PASSWORD_LENGTH', 10); } if (strlen($_POST['new_password']) < MINIMUM_PASSWORD_LENGTH) { AdminHelper::formFailure('Error. Your password should be at least ' . MINIMUM_PASSWORD_LENGTH . ' characters long. Please try again.'); } $changes['password'] = $_POST['new_password']; } } $change_response = $cash_admin->requestAndStore($changes); if ($change_response['payload'] !== false) { if (isset($changes['address'])) { $admin_primary_cash_request->sessionSet('cash_effective_user_email', $changes['address']); } AdminHelper::formSuccess('Success. All changed.'); } else { AdminHelper::formFailure('Error. We had a problem resetting your login. Please try again. Email addresses and usernames have to be unique.'); } } } $effective_user = $cash_admin->effective_user_id; $user_request = $cash_admin->requestAndStore(array('cash_request_type' => 'people', 'cash_action' => 'getuser', 'user_id' => $effective_user)); if (is_array($user_request['payload'])) { $cash_admin->page_data['email_address'] = $user_request['payload']['email_address']; $cash_admin->page_data['username'] = $user_request['payload']['username']; $cash_admin->page_data['display_name'] = $user_request['payload']['display_name']; $cash_admin->page_data['url'] = $user_request['payload']['url']; $cash_admin->page_data['api_key'] = $user_request['payload']['api_key']; $cash_admin->page_data['api_url'] = CASH_API_URL; if (isset($_REQUEST['reveal'])) {
<?php // parsing posted data: if (isset($_POST['docampaignedit'])) { // do the actual list add stuffs... $edit_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'editcampaign', 'id' => $request_parameters[0], 'title' => $_POST['campaign_title'], 'description' => $_POST['campaign_description'])); if ($edit_response['status_uid'] == 'element_editcampaign_200') { AdminHelper::formSuccess('Success. Edited.', '/'); } else { AdminHelper::formFailure('Error. There was a problem editing your campaign.', '/'); } } $current_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'getcampaign', 'id' => $request_parameters[0])); $cash_admin->page_data['ui_title'] = 'Campaigns: Edit "' . $current_response['payload']['title'] . '"'; $current_campaign = $current_response['payload']; if (is_array($current_campaign)) { $cash_admin->page_data = array_merge($cash_admin->page_data, $current_campaign); } $cash_admin->page_data['form_state_action'] = 'docampaignedit'; $cash_admin->page_data['button_text'] = 'Save changes'; $elements_response = $cash_admin->requestAndStore(array('cash_request_type' => 'element', 'cash_action' => 'getelementsforcampaign', 'id' => $request_parameters[0])); if (is_array($elements_response['payload'])) { foreach ($elements_response['payload'] as &$element) { if ($element['modification_date'] == 0) { $element['formatted_date'] = CASHSystem::formatTimeAgo($element['creation_date']); } else { $element['formatted_date'] = CASHSystem::formatTimeAgo($element['modification_date']); } } $cash_admin->page_data['elements_for_campaign'] = new ArrayIterator($elements_response['payload']); }
public static function handleRedirectReturn($data = false) { if (!isset($data['key'])) { return 'There was an error. (general) Please try again.'; } else { require_once CASH_PLATFORM_ROOT . '/lib/mandrill/Mandrill.php'; $m = new Mandrill($data['key']); $user_info = $m->getUserInfo(); $username = $user_info['username']; // we can safely assume (AdminHelper::getPersistentData('cash_effective_user') as the OAuth // calls would only happen in the admin. If this changes we can f**k around with it later. $new_connection = new CASHConnection(AdminHelper::getPersistentData('cash_effective_user')); $result = $new_connection->setSettings($username . ' (Mandrill)', 'com.mandrillapp', array('key' => $data['key'])); if (!$result) { return 'There was an error. (adding the connection) Please try again.'; } // set up webhooks $api_credentials = CASHSystem::getAPICredentials(); $webhook_api_url = CASH_API_URL . '/verbose/people/processwebhook/origin/com.mandrillapp/api_key/' . $api_credentials['api_key']; //$m->webhooksDelete($webhook_api_url); // remove duplicate webhooks //$m->webhooksAdd($webhook_api_url,array('send','hard_bounce','soft_bounce','open','click','spam','unsub','reject')); // add it, all events $m->call('webhooks/add', array("url" => $webhook_api_url, "events" => array('hard_bounce', 'soft_bounce', 'open', 'click', 'spam', 'unsub', 'reject'))); if (isset($data['return_result_directly'])) { return $result; } else { if ($result) { AdminHelper::formSuccess('Success. Connection added. You\'ll see it in your list of connections.', '/settings/connections/'); } else { AdminHelper::formFailure('Error. Something just didn\'t work right.'); } } } }