/** * @param $row may be array(address) or array(title, address) */ function process_csv_upload_row($row) { global $messages; global $errors; global $addresses, $account_data, $user; global $invalid_addresses, $updated_titles, $existing_addresses, $new_addresses, $limited_addresses; if (count($row) >= 2) { $title = trim($row[0]); $address = trim($row[1]); } else { $title = false; $address = trim($row[0]); } if ($address == 'Address') { // skip the first header line of CSV file, if present return; } if (!trim($address)) { // ignore empty addresses return; } // otherwise, row[0] should be a label, and row[1] should be an address if (!$account_data['callback']($address)) { $invalid_addresses++; } else { // do we already have this address? if (isset($addresses[$address])) { $existing_addresses++; // do we need to update the title? if ($title !== false && $addresses[$address]['title'] != $title) { $q = db()->prepare("UPDATE " . $account_data['table'] . " SET title=? WHERE user_id=? AND id=?"); $q->execute(array($row[0], user_id(), $addresses[$address]['id'])); $addresses[$address]['title'] = $title; $updated_titles++; } } else { // we need to insert in a new address if (!can_user_add($user, $account_data['premium_group'], $new_addresses + 1)) { $limited_addresses++; } else { if ($title) { $q = db()->prepare("INSERT INTO " . $account_data['table'] . " SET user_id=?, address=?, currency=?, title=?"); $q->execute(array(user_id(), $address, $account_data['currency'], $title)); } else { $q = db()->prepare("INSERT INTO " . $account_data['table'] . " SET user_id=?, address=?, currency=?"); $q->execute(array(user_id(), $address, $account_data['currency'])); } $addresses[$address] = array('id' => db()->lastInsertId(), 'title' => false); $new_addresses++; } } } }
$errors[] = t("Cannot create a :title test, because you already have a :type test pending.", array(':title' => htmlspecialchars($account_data['title']), ':type' => get_exchange_name($job['job_type']))); } else { if ($account_data['disabled']) { $errors[] = t("Cannot test that job; that account type is disabled."); } else { $q = db()->prepare("INSERT INTO jobs SET\n job_type=:job_type,\n job_prefix=:job_prefix,\n user_id=:user_id,\n arg_id=:arg_id,\n priority=:priority,\n is_test_job=1"); $q->execute(array('job_type' => $account_data['job_type'], 'job_prefix' => \Openclerk\Jobs\JobQueuer::getJobPrefix($account_data['exchange']), 'user_id' => user_id(), 'arg_id' => require_post('id'), 'priority' => get_site_config('job_test_priority'))); $messages[] = t("Queued up a new :title test; results should be available shortly.", array(':title' => htmlspecialchars($account_data['title']))); set_temporary_messages($messages); redirect(url_for(require_post("callback"))); } } } // process 'enable' if (require_post('enable', false) && require_post('id', false)) { if (!can_user_add($user, $account_data['exchange'])) { $errors[] = t("Cannot enable :title: too many existing accounts.", array(':title' => $account_data['title'])) . ($user['is_premium'] ? "" : " " . t("To add more accounts, upgrade to a :premium_account.", array(':premium_account' => link_to(url_for('premium'), t('premium account'))))); } else { if ($account_data['disabled']) { $errors[] = t("Cannot enable that account; that account type is disabled."); } else { // reset all failure fields $q = db()->prepare("UPDATE " . $account_data['table'] . " SET is_disabled=0,is_disabled_manually=0,first_failure=NULL,failures=0 WHERE id=? AND user_id=?"); $q->execute(array(require_post("id"), user_id())); $messages[] = t("Enabled :title.", array(':title' => htmlspecialchars($account_data['title']))); set_temporary_messages($messages); redirect(url_for(require_post("callback"))); } } } // process enable_creator, disable_creator, reset_creator
case "ticker": $q = db()->prepare("DELETE FROM notifications_ticker WHERE id=?"); $q->execute(array($instance['type_id'])); case "summary_instance": $q = db()->prepare("DELETE FROM notifications_summary_instances WHERE id=?"); $q->execute(array($instance['type_id'])); default: throw new Exception("Unknown old notification type '" . htmlspecialchars($instance['notification_type']) . "'"); } $type_id = false; } else { // update the existing instance $type_id = $instance['type_id']; } } else { if (!can_user_add($user, 'notifications')) { $errors[] = t("Cannot add notification: too many existing notifications.") . ($user['is_premium'] ? "" : " " . t("To add more notifications, upgrade to a :premium_account.", array(':premium_account' => link_to(url_for('premium'), t('premium account'))))); set_temporary_errors($errors); redirect(url_for('wizard_notifications')); } } if (require_post('period') == 'hour' && !$user['is_premium']) { $errors[] = t("Only :premium_accounts can add hourly notifications.", array(':premium_accounts' => link_to(url_for('premium'), t("premium accounts")))); set_temporary_errors($errors); redirect(url_for('wizard_notifications')); } // create or edit a new instance (both edit and create) switch ($notification_type) { case "ticker": $currency1 = substr(require_post('currencies'), 0, 3); $currency2 = substr(require_post('currencies'), 3, 3);
$q->execute(array(user_id(), $id)); $q = db()->prepare("UPDATE transactions SET account_id=null WHERE user_id=? AND exchange=? AND account_id=?"); $q->execute(array(user_id(), 'account', $id)); $messages[] = t("Deleted finance account."); } if (require_post("title", false)) { $title = (string) require_post("title"); $description = (string) require_post("description", ""); $gst = (string) require_post("gst", ""); // make sure no existing title exists $q = db()->prepare("SELECT * FROM finance_accounts WHERE user_id=? AND title=?"); $q->execute(array(user_id(), $title)); if ($q->fetch()) { $errors[] = t("An account with the title ':title' already exists.", array(":title" => $title)); } if (!can_user_add($user, "finance_accounts")) { $errors[] = "Cannot add finance account: too many existing finance accounts." . ($user['is_premium'] ? "" : " To add more finance accounts, upgrade to a <a href=\"" . htmlspecialchars(url_for('premium')) . "\">premium account</a>."); } if (!$errors) { $q = db()->prepare("INSERT INTO finance_accounts SET title=:title, description=:description, gst=:gst, user_id=:user_id"); $q->execute(array('title' => $title, 'description' => $description, 'gst' => $gst, 'user_id' => user_id())); $messages[] = t("Added new finance account."); } } page_header(t("Your Finance Accounts"), "page_finance_accounts", array('js' => array('accounts', 'transactions'), 'class' => 'report_page page_finance')); $q = db()->prepare("SELECT * FROM finance_accounts WHERE user_id=?"); $q->execute(array(user_id())); $accounts = $q->fetchAll(); ?> <!-- page list -->
require __DIR__ . "/../layout/graphs.php"; require_login(); $user = get_user(user_id()); require_user($user); // adding a new page? $title = require_post("title"); $title = substr($title, 0, 64); // limit to 64 characters if (!$title) { $title = t("Untitled"); } $errors = array(); $messages = array(); // check premium account limits if (!can_user_add($user, 'graph_pages')) { $errors[] = t("Cannot add graph page: too many existing graph pages.") . ($user['is_premium'] ? "" : " " . t("To add more graph pages, upgrade to a :premium_account.", array(':premium_account' => link_to(url_for('premium'), t('premium account'))))); set_temporary_errors($errors); redirect(url_for('profile', array('page' => require_post("page", "")))); } // it's OK - let's add a new one // first get the highest page order so far on this page $q = db()->prepare("SELECT * FROM graph_pages WHERE user_id=? ORDER BY page_order DESC LIMIT 1"); // including is_removed (in case of restore) $q->execute(array(user_id())); $highest = $q->fetch(); $new_order = $highest ? $highest['page_order'] + 1 : 1; // now insert it $q = db()->prepare("INSERT INTO graph_pages SET user_id=:user_id, title=:title, page_order=:page_order"); $q->execute(array('user_id' => user_id(), 'title' => $title, 'page_order' => $new_order)); $new_page_id = db()->lastInsertId();
$q->execute(array(user_id(), $id)); $q = db()->prepare("UPDATE transactions SET category_id=null WHERE user_id=? AND exchange=? AND category_id=?"); $q->execute(array(user_id(), 'account', $id)); $messages[] = t("Deleted finance category."); } if (require_post("title", false)) { $title = (string) require_post("title"); $description = (string) require_post("description", ""); $gst = (string) require_post("gst", ""); // make sure no existing title exists $q = db()->prepare("SELECT * FROM finance_categories WHERE user_id=? AND title=?"); $q->execute(array(user_id(), $title)); if ($q->fetch()) { $errors[] = t("A category with the title ':title' already exists.", array(":title" => $title)); } if (!can_user_add($user, "finance_categories")) { $errors[] = t("Cannot add finance category: too many existing finance categories.") . ($user['is_premium'] ? "" : " " . t("To add more finance categories, upgrade to a :premium_account.", array(':premium_account' => link_to(url_for('premium'), t('premium account'))))); } if (!$errors) { $q = db()->prepare("INSERT INTO finance_categories SET title=:title, description=:description, user_id=:user_id"); $q->execute(array('title' => $title, 'description' => $description, 'user_id' => user_id())); $messages[] = t("Added new finance category."); } } page_header(t("Your Finance Categories"), "page_finance_categories", array('js' => array('accounts', 'transactions'), 'class' => 'report_page page_finance')); $q = db()->prepare("SELECT * FROM finance_categories WHERE user_id=?"); $q->execute(array(user_id())); $categories = $q->fetchAll(); ?> <!-- page list -->