<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[2392] sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments: WordCamp Budgets: Add Reimbursement Requests post type.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/2392">2392</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/2392","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>iandunn</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2016-01-28 00:29:10 +0000 (Thu, 28 Jan 2016)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>WordCamp Budgets: Add Reimbursement Requests post type.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsbootstrapphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/bootstrap.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentscsswordcampbudgetscss">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-budgets.css</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsincludesreimbursementrequestphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/reimbursement-request.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsjavascriptreimbursementrequestsjs">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/reimbursement-requests.js</a></li>
<li>sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/</li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequestmetaboxexpensesphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-expenses.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequestmetaboxgeneralinformationphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-general-information.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequestmetaboxnotesphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-notes.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequestmetaboxstatusphp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-status.php</a></li>
<li><a href="#sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequesttemplateexpensephp">sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/template-expense.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsbootstrapphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/bootstrap.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/bootstrap.php 2016-01-27 22:28:17 UTC (rev 2391)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/bootstrap.php 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -18,6 +18,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( defined( 'WPORG_PROXIED_REQUEST' ) && WPORG_PROXIED_REQUEST ) {
</span><span class="cx" style="display: block; padding: 0 10px"> require_once( __DIR__ . '/includes/sponsor-invoice.php' );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ require_once( __DIR__ . '/includes/reimbursement-request.php' );
</ins><span class="cx" style="display: block; padding: 0 10px"> require_once( __DIR__ . '/includes/encryption.php' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $GLOBALS['wordcamp_budgets'] = new WordCamp_Budgets();
</span></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentscsswordcampbudgetscss"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-budgets.css</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-budgets.css 2016-01-27 22:28:17 UTC (rev 2391)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/css/wordcamp-budgets.css 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -14,6 +14,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> display: table-row;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ .wcb-form li.hidden {
+ display: none;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> .wcb-form li > label {
</span><span class="cx" style="display: block; padding: 0 10px"> display: table-cell;
</span><span class="cx" style="display: block; padding: 0 10px"> margin-bottom: 1em;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -119,3 +123,25 @@
</span><span class="cx" style="display: block; padding: 0 10px"> border-right: 1px solid rgba( 0, 0, 0, 0.1 );
</span><span class="cx" style="display: block; padding: 0 10px"> border-bottom: 1px solid rgba( 0, 0, 0, 0.1 );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+
+/*
+ * Reimbursement Requests
+ */
+
+#normal-sortables #wcbrr_expenses.postbox .submit {
+ float: none;
+}
+
+#submitpost.wcbrr .misc-pub-section span {
+ font-weight: bold;
+}
+
+.wcbrr-note {
+ margin-bottom: 1em;
+}
+
+ .wcbrr-note-meta {
+ font-weight: bold;
+ }
+
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsincludesreimbursementrequestphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/reimbursement-request.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/reimbursement-request.php (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/includes/reimbursement-request.php 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,702 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+/*
+ * Create Reimbursement Request Post type
+ */
+
+namespace WordCamp\Budgets\Reimbursement_Requests;
+
+defined( 'WPINC' ) or die();
+
+const POST_TYPE = 'wcb_reimbursement';
+
+// Initialization
+add_action( 'init', __NAMESPACE__ . '\register_post_type' );
+add_action( 'init', __NAMESPACE__ . '\register_post_statuses' );
+add_action( 'add_meta_boxes', __NAMESPACE__ . '\init_meta_boxes' );
+add_action( 'admin_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets', 11 );
+
+// Saving posts
+add_filter( 'wp_insert_post_data', __NAMESPACE__ . '\set_request_status', 10, 2 );
+add_action( 'save_post', __NAMESPACE__ . '\save_request', 10, 2 );
+add_action( 'transition_post_status', __NAMESPACE__ . '\notify_organizer_request_updated', 10, 3 );
+
+// Miscellaneous
+add_filter( 'map_meta_cap', __NAMESPACE__ . '\modify_capabilities', 10, 4 );
+add_filter( 'display_post_states', __NAMESPACE__ . '\display_post_states' );
+
+/**
+ * Register the custom post type
+ *
+ * @return object | \WP_Error
+ */
+function register_post_type() {
+ $labels = array(
+ 'name' => _x( 'Reimbursement Requests', 'general reimbursement requests', 'wordcamporg' ),
+ 'singular_name' => _x( 'Reimbursement Request', 'post type singular name', 'wordcamporg' ),
+ 'menu_name' => _x( 'Reimbursement Requests', 'admin menu', 'wordcamporg' ),
+ 'name_admin_bar' => _x( 'Reimbursement Requests', 'add new on admin bar', 'wordcamporg' ),
+ 'add_new' => _x( 'Add New', 'reimbursement request', 'wordcamporg' ),
+
+ 'add_new_item' => __( 'Add New Reimbursement Request', 'wordcamporg' ),
+ 'new_item' => __( 'New Reimbursement Request', 'wordcamporg' ),
+ 'edit_item' => __( 'Edit Reimbursement Request', 'wordcamporg' ),
+ 'view_item' => __( 'View Reimbursement Request', 'wordcamporg' ),
+ 'all_items' => __( 'Reimbursements', 'wordcamporg' ),
+ 'search_items' => __( 'Search Reimbursement Requests', 'wordcamporg' ),
+ 'not_found' => __( 'No Reimbursement Requests found.', 'wordcamporg' ),
+ 'not_found_in_trash' => __( 'No Reimbursement Requests found in Trash.', 'wordcamporg' ),
+ );
+
+ $args = array(
+ 'labels' => $labels,
+ 'description' => 'WordCamp Reimbursement Requests',
+ 'public' => false,
+ 'show_ui' => true,
+ 'show_in_menu' => 'wordcamp-budget',
+ 'show_in_nav_menus' => true,
+ 'supports' => array( 'title' ),
+ 'has_archive' => true,
+ );
+
+ return \register_post_type( POST_TYPE, $args );
+}
+
+/**
+ * Get the slugs and names for our custom post statuses
+ *
+ * @return array
+ */
+function get_custom_statuses() {
+ return array(
+ 'wcbrr_submitted' => __( 'Submitted', 'wordcamporg' ),
+ 'wcbrr_info_requested' => __( 'Information Requested', 'wordcamporg' ),
+ 'wcbrr_rejected' => __( 'Rejected', 'wordcamporg' ),
+ 'wcbrr_in_process' => __( 'Payment in Process', 'wordcamporg' ),
+ 'wcbrr_paid' => __( 'Paid', 'wordcamporg' ),
+ );
+}
+
+/**
+ * Register our custom post statuses
+ */
+function register_post_statuses() {
+ // todo use get_custom_statuses() for DRYness, but need to handle label_count
+
+ register_post_status(
+ 'wcbrr_submitted',
+ array(
+ 'label' => _x( 'Submitted', 'post', 'wordcamporg' ),
+ 'label_count' => _nx_noop( 'Submitted <span class="count">(%s)</span>', 'Submitted <span class="count">(%s)</span>', 'wordcamporg' ),
+ 'public' => true,
+ 'publicly_queryable' => false,
+ )
+ );
+
+ register_post_status(
+ 'wcbrr_info_requested',
+ array(
+ 'label' => _x( 'Information Requested', 'post', 'wordcamporg' ),
+ 'label_count' => _nx_noop( 'Information Requested <span class="count">(%s)</span>', 'Information Requested <span class="count">(%s)</span>', 'wordcamporg' ),
+ 'public' => true,
+ 'publicly_queryable' => false,
+ )
+ );
+
+ register_post_status(
+ 'wcbrr_rejected',
+ array(
+ 'label' => _x( 'Rejected', 'post', 'wordcamporg' ),
+ 'label_count' => _nx_noop( 'Rejected <span class="count">(%s)</span>', 'Rejected <span class="count">(%s)</span>', 'wordcamporg' ),
+ 'public' => true,
+ 'publicly_queryable' => false,
+ )
+ );
+
+ register_post_status(
+ 'wcbrr_in_process',
+ array(
+ 'label' => _x( 'Payment in Process', 'post', 'wordcamporg' ),
+ 'label_count' => _nx_noop( 'Payment in Process <span class="count">(%s)</span>', 'Payment in Process <span class="count">(%s)</span>', 'wordcamporg' ),
+ 'public' => true,
+ 'publicly_queryable' => false,
+ )
+ );
+
+ register_post_status(
+ 'wcbrr_paid',
+ array(
+ 'label' => _x( 'Paid', 'post', 'wordcamporg' ),
+ 'label_count' => _nx_noop( 'Paid <span class="count">(%s)</span>', 'Paid <span class="count">(%s)</span>', 'wordcamporg' ),
+ 'public' => true,
+ 'publicly_queryable' => false,
+ )
+ );
+}
+
+/**
+ * Register meta boxes
+ */
+function init_meta_boxes() {
+ global $wcp_payment_request, $post;
+
+ // Replace Core's status box with a custom one
+ remove_meta_box( 'submitdiv', POST_TYPE, 'side' );
+
+ add_meta_box(
+ 'submitdiv',
+ __( 'Status', 'wordcamporg' ),
+ __NAMESPACE__ . '\render_status_metabox',
+ POST_TYPE,
+ 'side',
+ 'high'
+ );
+
+ add_meta_box(
+ 'wcbrr_notes',
+ __( 'Notes', 'wordcamporg' ),
+ __NAMESPACE__ . '\render_notes_metabox',
+ POST_TYPE,
+ 'side',
+ 'high'
+ );
+
+ add_meta_box(
+ 'wcbrr_general_information',
+ __( 'General Information', 'wordcamporg' ),
+ __NAMESPACE__ . '\render_general_information_metabox',
+ POST_TYPE,
+ 'normal',
+ 'high'
+ );
+
+ add_meta_box(
+ 'wcbrr_payment_information',
+ __( 'Payment Information', 'wordcamporg' ),
+ array( $wcp_payment_request, 'render_payment_metabox' ), // todo centralize this instead of using directly from another module
+ POST_TYPE,
+ 'normal',
+ 'high',
+ array(
+ 'meta_key_prefix' => 'wcbrr',
+ 'fields_enabled' => user_can_edit_request( $post ),
+ )
+ );
+
+ add_meta_box(
+ 'wcbrr_expenses',
+ __( 'Expenses', 'wordcamporg' ),
+ __NAMESPACE__ . '\render_expenses_metabox',
+ POST_TYPE,
+ 'normal',
+ 'high'
+ );
+}
+
+/**
+ * Enqueue scripts and stylesheets
+ */
+function enqueue_assets() {
+ global $post;
+
+ wp_register_script(
+ 'wordcamp-reimbursement-requests',
+ plugins_url( 'javascript/reimbursement-requests.js', __DIR__ ),
+ array( 'wordcamp-budgets', 'wcb-attached-files', 'jquery', 'underscore', 'wp-util' ),
+ \WordCamp_Budgets::VERSION,
+ true
+ );
+
+ $current_screen = get_current_screen();
+
+ if ( POST_TYPE !== $current_screen->id ) {
+ return;
+ }
+
+ wp_enqueue_script( 'wordcamp-reimbursement-requests' );
+
+ if ( is_a( $post, 'WP_Post' ) ) {
+ wp_enqueue_media( array( 'post' => $post->ID ) );
+ wp_enqueue_script( 'wcb-attached-files' );
+ }
+}
+
+/**
+ * Get the name of the requester
+ *
+ * @param int $post_author_id
+ *
+ * @return string
+ */
+function get_requester_name( $post_author_id ) {
+ $requester_name = '';
+
+ $author = get_user_by( 'id', $post_author_id );
+
+ if ( is_a( $author, 'WP_User' ) ) {
+ $requester_name = $author->get( 'display_name' );
+ }
+
+ return $requester_name;
+}
+
+/**
+ * Determine if the current user can submit changes to the given Reimbursement Request
+ *
+ * This is used instead of current_user_can( 'edit_post', N ), because Core uses 'edit_post' both for accessing
+ * the Edit screen, and for submitting changes to the post. We always want organizers to be able to view their
+ * requests and to submit notes, but they should only be able to change the form fields if the post hasn't been
+ * submitted yet, or if we've asked for more information.
+ *
+ * @param \WP_Post $post
+ *
+ * @return bool
+ */
+function user_can_edit_request( $post ) {
+ $editable_status = in_array( $post->post_status, array( 'auto-draft', 'draft', 'wcbrr_info_requested' ), true );
+ return current_user_can( 'manage_network' ) || $editable_status;
+}
+
+/**
+ * Render the Status metabox
+ *
+ * @param \WP_Post $post
+ */
+function render_status_metabox( $post ) {
+ wp_nonce_field( 'status', 'status_nonce' );
+
+ $show_draft_button = current_user_can( 'draft_post', $post->ID ) && ! current_user_can( 'manage_network' ); // Network admins can save as draft via the status dropdown, so the button is unnecessary UI clutter
+ $show_submit_button = user_can_edit_request( $post );
+ $available_statuses = array_merge( array( 'draft' => __( 'Draft' ) ), get_custom_statuses() );
+ $status_name = get_status_name( $post->post_status );
+ $request_id = get_current_blog_id() . '-' . $post->ID;
+ $requested_by = get_requester_name( $post->post_author );
+ $delete_text = EMPTY_TRASH_DAYS ? __( 'Move to Trash' ) : __( 'Delete Permanently' );
+ $update_text = current_user_can( 'manage_network' ) ? __( 'Update Request', 'wordcamporg' ) : __( 'Send Request', 'wordcamporg' );
+
+ require_once( dirname( __DIR__ ) . '/views/reimbursement-request/metabox-status.php' );
+}
+
+/**
+ * Get the name for the given status slug
+ *
+ * @param string $status_slug
+ *
+ * @return string
+ */
+function get_status_name( $status_slug ) {
+ $status_name = '';
+
+ switch ( $status_slug ) {
+ case 'auto-draft':
+ case 'draft':
+ $status_name = __( 'Draft' );
+ break;
+
+ default:
+ $custom_statuses = get_custom_statuses();
+ foreach ( $custom_statuses as $custom_slug => $custom_name ) {
+ if ( $custom_slug === $status_slug ) {
+ $status_name = $custom_name;
+ }
+ }
+ }
+
+ return $status_name;
+}
+
+/**
+ * Render the Notes metabox
+ *
+ * @param \WP_Post $post
+ */
+function render_notes_metabox( $post ) {
+ wp_nonce_field( 'notes', 'notes_nonce' );
+
+ $existing_notes = get_post_meta( $post->ID, '_wcbrr_notes', true );
+
+ require_once( dirname( __DIR__ ) . '/views/reimbursement-request/metabox-notes.php' );
+}
+
+/**
+ * Render General Information Metabox
+ *
+ * @param \WP_Post $post
+ *
+ */
+function render_general_information_metabox( $post ) {
+ wp_nonce_field( 'general_information', 'general_information_nonce' );
+
+ $available_currencies = \WordCamp_Budgets::get_currencies();
+ $available_reasons = get_reimbursement_reasons();
+ $files = \WordCamp_Budgets::get_attached_files( $post );
+
+ $name_of_payer = get_post_meta( $post->ID, '_wcbrr_name_of_payer', true );
+ $selected_currency = get_post_meta( $post->ID, '_wcbrr_currency', true );
+ $selected_reason = get_post_meta( $post->ID, '_wcbrr_reason', true );
+ $other_reason = get_post_meta( $post->ID, '_wcbrr_reason_other', true );
+
+ if ( empty ( $name_of_payer ) ) {
+ $name_of_payer = get_requester_name( $post->post_author );
+ }
+
+ wp_localize_script( 'wcb-attached-files', 'wcbAttachedFiles', $files );
+
+ require_once( dirname( __DIR__ ) . '/views/reimbursement-request/metabox-general-information.php' );
+}
+
+/**
+ * Get the reasons for reimbursement
+ *
+ * @return array
+ */
+function get_reimbursement_reasons() {
+ return array(
+ 'last-minute-purchase' => __( 'Last-minute purchase', 'wordcamporg' ),
+ 'vendor-required-cash' => __( 'Vendor required cash payment', 'wordcamporg' ),
+ 'payment-on-delivery' => __( 'Vendor required payment at delivery', 'wordcamporg' ),
+ 'convenience' => __( 'Organizer convenience', 'wordcamporg' ),
+ 'central-missed-payment' => __( "Payment by Central didn't come through", 'wordcamporg' ),
+ 'other' => __( 'Other (describe in next field)', 'wordcamporg' ),
+ );
+}
+
+/**
+ * Render Expenses Metabox
+ *
+ * @param \WP_Post $post
+ *
+ */
+function render_expenses_metabox( $post ) {
+ wp_nonce_field( 'expenses', 'expenses_nonce' );
+
+ $expenses = get_post_meta( $post->ID, '_wcbrr_expenses', true );
+ if ( ! $expenses ) {
+ $expenses = array( array( 'id' => 1 ) );
+ }
+
+ wp_localize_script( 'wordcamp-reimbursement-requests', 'wcbPaymentCategories', \WordCamp_Budgets::get_payment_categories() );
+
+ require_once( dirname( __DIR__ ) . '/views/reimbursement-request/metabox-expenses.php' );
+ require_once( dirname( __DIR__ ) . '/views/reimbursement-request/template-expense.php' );
+}
+
+/**
+ * Display the status of a post after its title on the Payment Requests page
+ *
+ * @todo centralize this, since it's the same in other modules
+ *
+ * @param array $states
+ *
+ * @return array
+ */
+function display_post_states( $states ) {
+ global $post;
+
+ $custom_states = get_custom_statuses();
+
+ foreach ( $custom_states as $slug => $name ) {
+ if ( $slug == $post->post_status && $slug != get_query_var( 'post_status' ) ) {
+ $states[ $slug ] = $name;
+ }
+ }
+
+ return $states;
+}
+
+/**
+ * Set the status when reimbursements are submitted.
+ *
+ * @param array $post_data
+ * @param array $post_data_raw
+ *
+ * @return array
+ */
+function set_request_status( $post_data, $post_data_raw ) {
+ if ( ! \WordCamp_Budgets::post_edit_is_actionable( $post_data, POST_TYPE ) ) {
+ return $post_data;
+ }
+
+ // Requesting to save draft
+ if ( isset( $post_data_raw['wcbsi-save-draft'] ) ) {
+ if ( current_user_can( 'draft_post', $post_data['ID'] ) ) {
+ $post_data['post_status'] = 'draft';
+ }
+ }
+
+ // Requesting to submit/update the post
+ elseif ( isset( $post_data_raw['send-reimbursement-request'] ) ) {
+ if ( current_user_can( 'manage_network' ) ) {
+ $post_data['post_status'] = $_POST['post_status'];
+ } else {
+ $post_data['post_status'] = 'wcbrr_submitted';
+ }
+ }
+
+ return $post_data;
+}
+
+/**
+ * Save the post's data
+ *
+ * @param int $post_id
+ * @param \WP_Post $post
+ */
+function save_request( $post_id, $post ) {
+ if ( ! \WordCamp_Budgets::post_edit_is_actionable( $post, POST_TYPE ) ) {
+ return;
+ }
+
+ verify_metabox_nonces();
+ validate_and_save_notes( $post, $_POST['wcbrr_new_note'] );
+
+ /*
+ * We need to determine if the user is allowed to modify the request -- in terms of this plugin's post_status
+ * restrictions, not in terms of current_user_can( 'edit_post', N ) -- but at this point in the execution
+ * the status has already changed from the original one to the new one, so user_can_edit_request() would often
+ * return an incorrect result, because it would be evaluating the new status, when it should use the old one.
+ * That would result in all the meta fields the user entered being ignored when going from `draft` to
+ * `submitted`, `info_requested` to `submitted`, etc.
+ *
+ * To avoid that, we create a stub WP_Post with the original post status, and give that to
+ * user_can_edit_request() instead.
+ */
+ $original_post = new \WP_Post( (object) array( 'post_status' => $_POST['original_post_status'] ) );
+
+ if ( user_can_edit_request( $original_post ) ) {
+ $text_fields = array( 'name_of_payer', 'currency', 'reason' );
+ validate_and_save_text_fields( $post_id, $text_fields, $_POST );
+
+ \WordCamp_Budgets::validate_save_payment_method_fields( $post_id, 'wcbrr' );
+
+ validate_and_save_expenses( $post_id, $_POST['wcbrr-expenses-data'] );
+
+ // Attach existing files
+ remove_action( 'save_post', __NAMESPACE__ . '\save_request', 10 ); // avoid infinite recursion
+ \WordCamp_Budgets::attach_existing_files( $post_id, $_POST );
+ add_action( 'save_post', __NAMESPACE__ . '\save_request', 10, 2 );
+ }
+}
+
+/**
+ * Verify that each metabox has a valid nonce
+ */
+function verify_metabox_nonces() {
+ $nonces = array(
+ 'status_nonce',
+ 'notes_nonce',
+ 'general_information_nonce',
+ 'payment_details_nonce',
+ 'expenses_nonce'
+ );
+
+ foreach ( $nonces as $nonce ) {
+ check_admin_referer( str_replace( '_nonce', '', $nonce ), $nonce );
+ }
+}
+
+/**
+ * Validate and save text fields
+ *
+ * @param int $post_id
+ * @param array $field_names
+ * @param array $data
+ */
+function validate_and_save_text_fields( $post_id, $field_names, $data ) {
+ foreach ( $field_names as $field ) {
+ $meta_key = "_wcbrr_$field";
+ $value = sanitize_text_field( wp_unslash( $data[ $meta_key ] ) );
+
+ if ( empty( $value ) ) {
+ delete_post_meta( $post_id, $meta_key );
+ } else {
+ update_post_meta( $post_id, $meta_key, $value );
+ }
+ }
+}
+
+/**
+ * Validate and save expense data
+ *
+ * @param int $post_id
+ * @param array $expenses
+ */
+function validate_and_save_expenses( $post_id, $expenses ) {
+ $expenses = json_decode( wp_unslash( $expenses ) );
+
+ if ( empty( $expenses ) ) {
+ delete_post_meta( $post_id, '_wcbrr_expenses' );
+ return;
+ }
+
+ $defaults = array(
+ '_wcbrr_category' => '',
+ '_wcbrr_category_other' => '',
+ '_wcbrr_vendor_name' => '',
+ '_wcbrr_description' => '',
+ '_wcbrr_date' => '',
+ '_wcbrr_amount' => 0,
+ '_wcbrr_vendor_location' => '',
+ );
+
+ foreach ( $expenses as & $expense ) {
+ $expense = shortcode_atts( $defaults, $expense ); // 'id' is intentionally removed because it's just a temporary client-side value
+
+ $expense['_wcbrr_category'] = sanitize_text_field( $expense['_wcbrr_category'] );
+ $expense['_wcbrr_category_other'] = sanitize_text_field( $expense['_wcbrr_category_other'] );
+ $expense['_wcbrr_vendor_name'] = sanitize_text_field( $expense['_wcbrr_vendor_name'] );
+ $expense['_wcbrr_description'] = sanitize_text_field( $expense['_wcbrr_description'] );
+ $expense['_wcbrr_date'] = empty( $expense['_wcbrr_date'] ) ? '' : date( 'Y-m-d', strtotime( $expense['_wcbrr_date'] ) );
+ $expense['_wcbrr_amount'] = \WordCamp_Budgets::validate_amount( $expense['_wcbrr_amount'] );
+ $expense['_wcbrr_vendor_location'] = in_array( $expense['_wcbrr_vendor_location'], array( 'local', 'online' ) ) ? $expense['_wcbrr_vendor_location'] : '';
+ }
+
+ update_post_meta( $post_id, '_wcbrr_expenses', $expenses );
+}
+
+/**
+ * Validate and save expense data
+ *
+ * @param \WP_Post $post
+ * @param array $expenses
+ */
+function validate_and_save_notes( $post, $new_note_message ) {
+ $new_note_message = sanitize_text_field( wp_unslash( $new_note_message ) );
+
+ if ( empty( $new_note_message ) ) {
+ return;
+ }
+
+ $notes = get_post_meta( $post->ID, '_wcbrr_notes', true );
+
+ $new_note = array(
+ 'timestamp' => time(),
+ 'author_id' => get_current_user_id(),
+ 'message' => $new_note_message
+ );
+
+ $notes[] = $new_note;
+
+ update_post_meta( $post->ID, '_wcbrr_notes', $notes );
+ notify_parties_of_new_note( $post, $new_note );
+}
+
+/**
+ * Notify WordCamp Central or the request author when new notes are added
+ *
+ * @param \WP_Post $request
+ * @param array $note
+ */
+function notify_parties_of_new_note( $request, $note ) {
+ $note_author = get_user_by( 'id', $note['author_id'] );
+
+ if ( $note_author->has_cap( 'manage_network' ) ) {
+ $to = \WordCamp_Budgets::get_requester_formatted_email( $request->post_author );
+ } else {
+ $to = 'support@wordcamp.org';
+ }
+
+ if ( ! $to ) {
+ return;
+ }
+
+ $subject = 'New note on ' . sanitize_text_field( $request->post_title );
+ $note_author_name = get_requester_name( $note['author_id'] );
+ $request_url = admin_url( sprintf( 'post.php?post=%s&action=edit', $request->ID ) );
+ $headers = array( 'Reply-To: support@wordcamp.org' );
+
+ $message = sprintf( "
+ %s has added the following note on the reimbursement request for %s:
+
+ %s
+
+ You can view the request and respond to their note at:
+
+ %s",
+ sanitize_text_field( $note_author_name ),
+ sanitize_text_field( $request->post_title ),
+ sanitize_text_field( $note['message'] ),
+ esc_url_raw( $request_url )
+ );
+ $message = str_replace( "\t", '', $message );
+
+ wp_mail( $to, $subject, $message, $headers );
+}
+
+/**
+ * Notify the organizer when the status of their invoice changes or when notes are added
+ *
+ * @param string $new_status
+ * @param string $old_status
+ * @param \WP_Post $request
+ */
+function notify_organizer_request_updated( $new_status, $old_status, $request ) {
+ if ( $new_status === $old_status ) {
+ return;
+ }
+
+ $to = \WordCamp_Budgets::get_requester_formatted_email( $request->post_author );
+ $relevant_statuses = array( 'wcbrr_info_requested', 'wcbrr_rejected', 'wcbrr_in_process', 'wcbrr_paid' );
+
+ if ( ! $to || ! in_array( $request->post_status, $relevant_statuses, true ) ) {
+ return;
+ }
+
+ $subject = 'Status update for ' . sanitize_text_field( $request->post_title );
+ $status_name = get_status_name( $request->post_status );
+ $request_url = admin_url( sprintf( 'post.php?post=%s&action=edit', $request->ID ) );
+ $headers = array( 'Reply-To: support@wordcamp.org' );
+
+ $message = sprintf( "
+ The status of your reimbursement request for %s has been updated to %s.
+
+ You can view the request and add notes at:
+
+ %s",
+ sanitize_text_field( $request->post_title ),
+ sanitize_text_field( $status_name ),
+ esc_url_raw( $request_url )
+ );
+ $message = str_replace( "\t", '', $message );
+
+ wp_mail( $to, $subject, $message, $headers );
+}
+
+/**
+ * Modify the default capabilities
+ *
+ * @todo maybe centralize this, since similar functionality in payment-requests.php and sponsor-invoice.php
+ *
+ * @param array $required_capabilities The primitive capabilities that are required to perform the requested meta capability
+ * @param string $requested_capability The requested meta capability
+ * @param int $user_id The user ID.
+ * @param array $args Adds the context to the cap. Typically the object ID.
+ */
+function modify_capabilities( $required_capabilities, $requested_capability, $user_id, $args ) {
+ global $post;
+
+ if ( ! is_a( $post, 'WP_Post' ) || POST_TYPE !== $post->post_type ) {
+ return $required_capabilities;
+ }
+
+ $drafted_status = in_array( $post->post_status, array( 'auto-draft', 'draft' ), true );
+ $draft_or_incomplete_status = $drafted_status || 'wcbrr_info_requested' === $post->post_status;
+
+ switch( $requested_capability ) {
+ case 'draft_post':
+ if ( $draft_or_incomplete_status ) {
+ $required_capabilities = array( 'edit_posts' );
+ } else {
+ $required_capabilities[] = 'manage_network';
+ }
+ break;
+
+ case 'delete_post':
+ if ( ! $drafted_status ) {
+ $required_capabilities[] = 'manage_network';
+ }
+ break;
+ }
+
+ return $required_capabilities;
+}
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsjavascriptreimbursementrequestsjs"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/reimbursement-requests.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/reimbursement-requests.js (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/javascript/reimbursement-requests.js 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,282 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+jQuery( document ).ready( function( $ ) {
+ 'use strict';
+
+ var wcb = window.WordCampBudgets;
+ var app = wcb.ReimbursementRequests = {
+
+ /**
+ * Main entry point
+ */
+ init : function () {
+ try {
+ var expensesContainer = $( '#wcbrr-expenses-container' );
+
+ app.expenses = new app.Expenses( JSON.parse( $( '#wcbrr-expenses-data' ).val() ) );
+ app.expensesView = new app.ExpensesView( {
+ el : expensesContainer,
+ collection : app.expenses }
+ );
+ expensesContainer.removeClass( 'loading-content' );
+
+ app.registerEventHandlers();
+ wcb.attachedFilesView = new wcb.AttachedFilesView( { el: $( '#wcbrr_general_information' ) } );
+ } catch ( exception ) {
+ wcb.log( exception );
+ }
+ },
+
+ /**
+ * Registers event handlers
+ */
+ registerEventHandlers : function() {
+ var reason = $( '#_wcbrr_reason' );
+
+ reason.change( app.toggleOtherReasonDescription );
+ reason.trigger( 'change' ); // Set the initial state
+
+ $( '#row-payment-method' ).find( 'input[name=payment_method]' ).change( wcb.togglePaymentMethodFields );
+ $( '#wcbrr_general_information' ).find( 'a.wcb-insert-media' ).click( wcb.showUploadModal );
+ $( '#wcbrr-add-another-expense' ).click( app.addNewExpense );
+
+ $( '#_wcbrr_currency' ).change( function() {
+ app.expenses.trigger( 'updateTotal' );
+ } );
+ },
+
+ /**
+ * Toggle the extra input field when the user selects the Other option for the Reason dropdown
+ *
+ * @param {object} event
+ */
+ toggleOtherReasonDescription : function( event ) {
+ try {
+ var otherCategoryDescription = $( '#_wcbrr_reason_other_container' );
+
+ if ( 'other' == $( this ).find( 'option:selected' ).val() ) {
+ $( otherCategoryDescription ).removeClass( 'hidden' );
+ } else {
+ $( otherCategoryDescription ).addClass( 'hidden' );
+ }
+
+ // todo make the transition smoother
+ } catch ( exception ) {
+ wcb.log( exception );
+ }
+ },
+
+ /**
+ * Add a new, empty expense to the collection
+ *
+ * @param {object} event
+ */
+ addNewExpense : function( event ) {
+ try {
+ event.preventDefault();
+
+ app.expenses.add( {} );
+ } catch ( exception ) {
+ wcb.log( exception );
+ }
+ }
+ };
+
+ /*
+ * Model for an expense
+ */
+ app.Expense = Backbone.Model.extend();
+
+ /*
+ * Collection for Expense models
+ */
+ app.Expenses = Backbone.Collection.extend( {
+ model : app.Expense,
+
+ /**
+ * Initialize the view
+ */
+ initialize : function( models ) {
+ _.each( models, function( element, index ) {
+ element.id = index + 1;
+ } );
+
+ this.listenTo( this, 'add', this.setId );
+ this.listenTo( this, 'syncToDom', this.syncToDom );
+ this.listenTo( this, 'remove', this.syncToDom );
+ this.listenTo( this, 'updateTotal', this.updateTotal );
+ },
+
+ /**
+ * Set the ID of new models added to the collection
+ *
+ * @param {object} model
+ */
+ setId : function( model ) {
+ model.set( { id : this.length } );
+ },
+
+ /**
+ * Sync the collection to the input field used as temporary storage
+ *
+ * @param {object} event
+ */
+ syncToDom : function( event ) {
+ $( '#wcbrr-expenses-data' ).val( JSON.stringify( this ) );
+ },
+
+ /**
+ * Update the calculated total amount of all expenses
+ */
+ updateTotal : function () {
+ var total = 0.0,
+ currency = $( '#_wcbrr_currency' ).val();
+
+ this.each( function( expense ) {
+ var value = parseFloat( expense.get( '_wcbrr_amount' ) );
+
+ if ( ! isNaN( value ) ) {
+ total += value;
+ }
+ } );
+
+ if ( 'null' === currency.substr( 0, 4 ) ) {
+ currency = '';
+ }
+
+ $( '#total_amount_requested' ).html(
+ _.escape( total )
+ + ' ' +
+ _.escape( currency )
+ );
+ }
+ } );
+
+ /*
+ * View for an individual Expense model
+ */
+ app.ExpenseView = Backbone.View.extend( {
+ template : wp.template( 'wcbrr-expense' ),
+
+ events : {
+ 'change input' : 'update',
+ 'change select' : 'update',
+ 'change textarea' : 'update',
+ 'click .wcbrr-delete-expense' : 'removeFromCollection'
+ },
+
+ /**
+ * Initialize the view
+ */
+ initialize : function() {
+ this.render();
+
+ this.listenTo( this.model, 'change', this.render );
+ this.listenTo( this, 'categoryChanged', this.toggleOtherCategoryInput );
+
+ _.bindAll( this, 'update' );
+ },
+
+ /**
+ * Render the view
+ */
+ render : function() {
+ this.$el.html( this.template( this.model.toJSON() ) );
+
+ // todo add a transition so it's obvious a new one is being added, otherwise can be hard to tell
+ },
+
+ /**
+ * Update the model's attributes when it's corresponding input field changes
+ *
+ * @param {object} event
+ */
+ update : function( event ) {
+ var attribute = event.currentTarget.name,
+ updatedModel = {},
+ value = $( event.currentTarget ).val();
+
+ /*
+ * Remove the unique ID from the DOM element attribute, so that it matches the model's attribute name.
+ * e.g., _wcbrr_vendor_location_4 becomes _wcbrr_vendor_location
+ */
+ attribute = attribute.slice( 0, attribute.lastIndexOf( '_' ) );
+
+ updatedModel[ attribute ] = value;
+
+ /*
+ * Silently update the model to avoid re-rendering the entire view, which would break input focus
+ * while tabbing between fields.
+ */
+ this.model.set( updatedModel, { silent : true } );
+
+ /*
+ * Because the update above was silent, we need to manually trigger some changes
+ */
+ this.model.trigger( 'syncToDom' );
+
+ if ( '_wcbrr_amount' === attribute ) {
+ this.model.trigger( 'updateTotal' );
+ }
+
+ if ( '_wcbrr_category' === attribute ) {
+ this.trigger( 'categoryChanged', value );
+ }
+ },
+
+ /**
+ * Manually toggle the display of the Other category field
+ *
+ * See this.update for why this doesn't happen automatically.
+ *
+ * @param category
+ */
+ toggleOtherCategoryInput : function( category ) {
+ if ( 'other' === category ) {
+ this.$( '#_wcbrr_category_other_container' ).removeClass( 'hidden' );
+ } else {
+ this.$( '#_wcbrr_category_other_container' ).addClass( 'hidden' );
+ }
+ },
+
+ /**
+ * Remove this model from its collection
+ *
+ * @param {object} event
+ */
+ removeFromCollection : function( event ) {
+ this.model.collection.remove( this.model );
+ }
+ } );
+
+ /*
+ * View for a collection of Expense models
+ */
+ app.ExpensesView = Backbone.View.extend( {
+ /**
+ * Initialize the view
+ */
+ initialize : function() {
+ this.render();
+
+ this.listenTo( this.collection, 'add', this.render );
+ this.listenTo( this.collection, 'remove', this.render );
+ },
+
+ /**
+ * Render the view
+ */
+ render : function() {
+ this.$el.html( '' );
+
+ this.collection.each( function( expense ) {
+ var expenseView = new app.ExpenseView( { model : expense } );
+ this.$el.append( expenseView.el );
+ }, this );
+
+ this.collection.updateTotal();
+
+ wcb.setupDatePicker( '#wcbrr-expenses-container' );
+ }
+ } );
+
+ app.init();
+} );
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequestmetaboxexpensesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-expenses.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-expenses.php (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-expenses.php 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,21 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\Budgets\Reimbursement_Requests;
+defined( 'WPINC' ) or die();
+
+?>
+
+<fieldset <?php disabled( user_can_edit_request( $post ), false ); ?> >
+ <input
+ id="wcbrr-expenses-data"
+ name="wcbrr-expenses-data"
+ type="hidden"
+ value="<?php echo esc_attr( wp_json_encode( $expenses ) ); ?>"
+ />
+
+ <div id="wcbrr-expenses-container" class="loading-content">
+ <span class="spinner is-active"></span>
+ </div>
+
+ <?php submit_button( __( 'Add Another Expense', 'wordcamporg' ), 'secondary', 'wcbrr-add-another-expense' ); ?>
+</fieldset>
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequestmetaboxgeneralinformationphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-general-information.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-general-information.php (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-general-information.php 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,87 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\Budgets\Reimbursement_Requests;
+defined( 'WPINC' ) or die();
+
+?>
+
+<fieldset <?php disabled( user_can_edit_request( $post ), false ); ?> >
+ <ul class="wcb-form">
+ <li>
+ <label for="_wcbrr_name_of_payer">
+ <?php _e( 'Name of Payer:', 'wordcamporg' ); ?>
+ </label>
+
+ <input
+ type="text"
+ class="regular-text"
+ id="_wcbrr_name_of_payer"
+ name="_wcbrr_name_of_payer"
+ value="<?php echo esc_attr( $name_of_payer ); ?>"
+ />
+ </li>
+
+ <li>
+ <label for="_wcbrr_currency">
+ <?php _e( 'Currency:', 'wordcamporg' ) ?>
+ </label>
+
+ <select id="_wcbrr_currency" name="_wcbrr_currency">
+ <option value="null-select-one">
+ <?php _e( '-- Select a Currency --', 'wordcamporg' ); ?>
+ </option>
+ <option value="null-separator1"></option>
+
+ <?php foreach ( $available_currencies as $currency_key => $currency_name ) : ?>
+ <option value="<?php echo esc_attr( $currency_key ); ?>" <?php selected( $currency_key, $selected_currency ); ?> >
+ <?php echo esc_html( $currency_name ); ?>
+ </option>
+ <?php endforeach; ?>
+ </select>
+ </li>
+
+ <li>
+ <label for="_wcbrr_reason">
+ <?php _e( 'Reason for Reimbursement:', 'wordcamporg' ); ?>
+ </label>
+
+ <select id="_wcbrr_reason" name="_wcbrr_reason">
+ <option value="null-select-one">
+ <?php _e( '-- Select a Reason --', 'wordcamporg' ); ?>
+ </option>
+ <option value="null-separator1"></option>
+
+ <?php foreach ( $available_reasons as $reason_key => $reason_name ) : ?>
+ <option value="<?php echo esc_attr( $reason_key ); ?>" <?php selected( $reason_key, $selected_reason ); ?> >
+ <?php echo esc_html( $reason_name ); ?>
+ </option>
+ <?php endforeach; ?>
+ </select>
+ </li>
+
+ <li id="_wcbrr_reason_other_container">
+ <label for="_wcbrr_reason_other">
+ <?php _e( 'Other Reason:', 'wordcamporg' ); ?>
+ </label>
+
+ <input
+ type="text"
+ class="regular-text"
+ id="_wcbrr_reason_other"
+ name="_wcbrr_reason_other"
+ value="<?php echo esc_attr( $other_reason ); ?>"
+ />
+ </li>
+
+ <li>
+ <label for="_wcbrr_files">
+ <?php _e( 'Files:', 'wordcamporg' ); ?>
+ </label>
+
+ <div class="wcb-form-input-wrapper">
+ <?php require_once( dirname( __DIR__ ) . '/wordcamp-budgets/field-attached-files.php' ); ?>
+ </div>
+ </li>
+
+ </ul>
+</fieldset>
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequestmetaboxnotesphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-notes.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-notes.php (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-notes.php 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,41 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\Budgets\Reimbursement_Requests;
+defined( 'WPINC' ) or die();
+
+?>
+
+<?php if ( empty ( $existing_notes ) ) : ?>
+
+ <?php _e( 'There are no notes yet.', 'wordcamporg' ); ?>
+
+<?php else : ?>
+
+ <?php foreach ( $existing_notes as $note ) : ?>
+ <div class="wcbrr-note">
+ <span class="wcbrr-note-meta">
+ <?php echo esc_html( date( 'Y-m-d', $note['timestamp'] ) ); ?>
+ <?php echo esc_html( get_requester_name( $note['author_id'] ) ); ?>:
+ </span>
+
+ <?php echo esc_html( $note['message'] ); ?>
+ </div>
+ <?php endforeach; ?>
+
+<?php endif; ?>
+
+<div>
+ <h3>
+ <label for="wcbrr_new_note">
+ <?php _e( 'Add a Note', 'wordcamporg' ); ?>
+ </label>
+ </h3>
+
+ <textarea id="wcbrr_new_note" name="wcbrr_new_note" class="large-text"></textarea>
+
+ <?php submit_button(
+ __( 'Add Note', 'wordcamporg' ),
+ 'secondary',
+ 'wcbrr_add_note'
+ ); ?>
+</div>
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequestmetaboxstatusphp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-status.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-status.php (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/metabox-status.php 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,110 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\Budgets\Reimbursement_Requests;
+defined( 'WPINC' ) or die();
+
+?>
+
+<div id="submitpost" class="wcbrr submitbox">
+ <div id="minor-publishing">
+ <?php if ( $show_draft_button ) : ?>
+ <div id="minor-publishing-actions">
+ <div id="save-action">
+ <?php submit_button( __( 'Save Draft' ), 'secondary', 'wcbsi-save-draft', false ); ?>
+ </div>
+ </div>
+ <?php endif; ?>
+
+ <div id="misc-publishing-actions">
+ <div class="misc-pub-section misc-pub-request-id">
+ <?php _e( 'ID:' ) ?>
+
+ <span id="request_id">
+ <?php echo esc_html( $request_id ); ?>
+ </span>
+ </div> <!-- .misc-pub-section -->
+
+ <div class="misc-pub-section misc-pub-requested-by">
+ <label><?php _e( 'Requested By:' ) ?>
+
+ <span id="requested_by">
+ <?php echo esc_html( $requested_by ); ?>
+ </span>
+ </label>
+ </div> <!-- .misc-pub-section -->
+
+ <div class="misc-pub-section misc-pub-post-status">
+ <label>
+ <?php _e( 'Status:' ) ?>
+
+ <span id="post-status-display">
+ <?php if ( current_user_can( 'manage_network' ) ) : ?>
+
+ <select name="post_status">
+ <?php foreach ( $available_statuses as $status_slug => $status_name ) : ?>
+ <option value="<?php echo esc_attr( $status_slug ); ?>" <?php selected( $post->post_status, $status_slug ); ?> >
+ <?php echo esc_html( $status_name ); ?>
+ </option>
+ <?php endforeach; ?>
+ </select>
+
+ <?php else : ?>
+
+ <?php echo esc_html( $status_name ); ?>
+
+ <?php endif; ?>
+ </span>
+ </label>
+ </div> <!-- .misc-pub-section -->
+
+ <div class="misc-pub-section misc-pub-total-amount-requested">
+ <label>
+ <?php _e( 'Total Amount Requested:' ) ?>
+
+ <span id="total_amount_requested" class="loading-content">
+ <span class="spinner is-active"></span>
+ </span>
+ </label>
+ </div> <!-- .misc-pub-section -->
+
+ <div class="clear"></div>
+ </div> <!-- #misc-publishing-actions -->
+
+ <div class="clear"></div>
+ </div> <!-- #minor-publishing -->
+
+
+ <div id="major-publishing-actions">
+ <?php if ( $show_submit_button ) : ?>
+
+ <div id="delete-action">
+ <?php if ( current_user_can( 'delete_post', $post->ID ) ) : ?>
+ <a class="submitdelete deletion" href="<?php echo get_delete_post_link( $post->ID ); ?>">
+ <?php echo $delete_text; ?>
+ </a>
+ <?php endif; ?>
+ </div>
+
+ <div id="publishing-action">
+ <input name="original_publish" type="hidden" id="original_publish" value="<?php esc_attr( $update_text ) ?>" />
+ <?php submit_button(
+ $update_text,
+ 'primary button-large',
+ 'send-reimbursement-request',
+ false,
+ array( 'accesskey' => 'p' )
+ ); ?>
+ </div>
+
+ <div class="clear"></div>
+
+ <?php else : ?>
+
+ <p>
+ <?php _e( "Requests can't be edited after they've been submitted.", 'wordcamporg' ); ?>
+ </p>
+
+ <?php endif; ?>
+ </div> <!-- #major-publishing-actions -->
+
+</div> <!-- .submitbox -->
</ins></span></pre></div>
<a id="sitestrunkwordcamporgpublic_htmlwpcontentpluginswordcamppaymentsviewsreimbursementrequesttemplateexpensephp"></a>
<div class="addfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Added: sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/template-expense.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/template-expense.php (rev 0)
+++ sites/trunk/wordcamp.org/public_html/wp-content/plugins/wordcamp-payments/views/reimbursement-request/template-expense.php 2016-01-28 00:29:10 UTC (rev 2392)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,153 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+
+namespace WordCamp\Budgets\Reimbursement_Requests;
+defined( 'WPINC' ) or die();
+
+?>
+
+<script type="text/html" id="tmpl-wcbrr-expense">
+ <h3>
+ <?php _e( 'Expense', 'wordcamporg' ); ?> #{{data.id}}
+ </h3>
+
+ <ul class="wcb-form">
+ <li>
+ <label for="_wcbrr_category_{{data.id}}">
+ <?php _e( 'Category:', 'wordcamporg' ) ?>
+ </label>
+
+ <select id="_wcbrr_category_{{data.id}}" name="_wcbrr_category_{{data.id}}">
+ <option value="null-select-one">
+ <?php _e( '-- Select a Category --', 'wordcamporg' ); ?>
+ </option>
+ <option value="null-separator1"></option>
+
+ <# _.each( wcbPaymentCategories, function( categoryName, categoryKey ) { #>
+ <# selected = data._wcbrr_category === categoryKey ? 'selected' : ''; #>
+
+ <option value="{{categoryKey}}" {{selected}}>
+ {{categoryName}}
+ </option>
+ <# } ); #>
+ </select>
+ </li>
+
+ <# var otherCategoryClasses = 'other' === data._wcbrr_category ? '' : 'hidden'; #>
+ <li id="_wcbrr_category_other_container" class="{{otherCategoryClasses}}">
+ <label for="_wcbrr_category_other_{{data.id}}">
+ <?php _e( 'Other Category:', 'wordcamporg' ); ?>
+ </label>
+
+ <input
+ type="text"
+ class="regular-text"
+ id="_wcbrr_category_other_{{data.id}}"
+ name="_wcbrr_category_other_{{data.id}}"
+ value="{{data._wcbrr_category_other}}"
+ />
+ </li>
+
+ <li>
+ <label for="_wcbrr_vendor_name_{{data.id}}">
+ <?php _e( 'Vendor Name:', 'wordcamporg' ); ?>
+ </label>
+
+ <input
+ type="text"
+ class="regular-text"
+ id="_wcbrr_vendor_name_{{data.id}}"
+ name="_wcbrr_vendor_name_{{data.id}}"
+ value="{{data._wcbrr_vendor_name}}"
+ />
+ </li>
+
+ <li>
+ <label for="_wcbrr_description_{{data.id}}">
+ <?php _e( 'Description:', 'wordcamporg' ); ?>
+ </label>
+
+ <textarea
+ rows="2"
+ cols="38"
+ id="_wcbrr_description_{{data.id}}"
+ name="_wcbrr_description_{{data.id}}"
+ maxlength="75"
+ >{{data._wcbrr_description}}</textarea>
+ </li>
+
+ <li>
+ <label for="_wcbrr_date_{{data.id}}">
+ <?php _e( 'Date:', 'wordcamporg' ); ?>
+ </label>
+
+ <input
+ type="date"
+ class="regular-text"
+ id="_wcbrr_date_{{data.id}}"
+ name="_wcbrr_date_{{data.id}}"
+ value="{{data._wcbrr_date}}"
+ />
+ </li>
+
+ <li>
+ <label for="_wcbrr_amount_{{data.id}}">
+ <?php _e( 'Amount:', 'wordcamporg' ); ?>
+ </label>
+
+ <div class="wcb-form-input-wrapper">
+ <input
+ type="text"
+ class="regular-text"
+ id="_wcbrr_amount_{{data.id}}"
+ name="_wcbrr_amount_{{data.id}}"
+ value="{{data._wcbrr_amount}}"
+ />
+
+ <p class="description">
+ <?php _e( 'No commas, thousands separators or currency symbols. Ex. 1234.56', 'wordcamporg' ); ?>
+ </p>
+ </div>
+ </li>
+
+ <li>
+ <label>
+ <?php _e( 'Vendor Location:', 'wordcamporg' ); ?>
+ </label>
+
+ <div class="wcb-form-input-wrapper">
+ <# var checked = 'local' === data._wcbrr_vendor_location ? 'checked' : ''; #>
+ <label>
+ <input
+ type="radio"
+ id="_wcbrr_vendor_location_local_{{data.id}}"
+ name="_wcbrr_vendor_location_{{data.id}}"
+ value="local"
+ {{checked}}
+ />
+ <?php _e( 'Local', 'wordcamporg' ); ?>
+ </label>
+
+ <br />
+
+ <# var checked = 'online' === data._wcbrr_vendor_location ? 'checked' : ''; #>
+ <label>
+ <input
+ type="radio"
+ id="_wcbrr_vendor_location_online_{{data.id}}"
+ name="_wcbrr_vendor_location_{{data.id}}"
+ value="online"
+ {{checked}}
+ />
+ <?php _e( 'Not Local / Online', 'wordcamporg' ); ?>
+ </label>
+ </div>
+ </li>
+ </ul>
+
+ <button class="wcbrr-delete-expense button-secondary" data-expense-id="{{data.id}}">
+ <?php _e( 'Delete Expense', 'wordcamporg' ); ?> #{{data.id}}
+ </button>
+
+ <hr />
+
+</script>
</ins></span></pre>
</div>
</div>
</body>
</html>