Nodebook_Admin::url( 'nodebook', array( 'action' => 'new' ) ) ) );
$layout = Nodebook_Admin::layout( 'board' );
echo '
';
Nodebook_Admin::layout_switch( 'nodebook-board', $layout, array_filter( array( 'who' => $all ? 'all' : '', 'segment' => $segment ) ) );
if ( $team ) {
echo '
' . esc_html__( 'Mine', 'nodebook' ) . ' ' . esc_html__( 'Everyone', 'nodebook' ) . ' ';
}
$segments = Nodebook_Segments::all();
if ( $segments ) {
echo '
';
}
echo '
' . esc_html( 'list' === $layout ? __( 'Drag a row to another group to change its status, or use the menu on the row.', 'nodebook' ) : __( 'Drag a card to another column to change its status, or use the menu on the card.', 'nodebook' ) ) . '
';
$statuses = Nodebook_Fields::statuses();
echo '';
foreach ( $statuses as $slug => $label ) {
$r = Nodebook_Contacts::query(
array(
'status' => $slug,
'mine' => $owner,
'segment' => $segment,
'orderby' => 'last_seen',
'order' => 'DESC',
'per_page' => self::PER_COLUMN,
)
);
echo '
';
}
echo '
';
Nodebook_Admin::footer();
}
private static function card( array $c, array $statuses, $team ) {
$id = (int) $c['id'];
$name = Nodebook_Contacts::display_name( $c );
$view = Nodebook_Admin::url( 'nodebook', array( 'action' => 'view', 'id' => $id ) );
echo '';
echo '' . Nodebook_Admin::avatar( $name, 'c' . $id ) . '
' . esc_html( $name ) . ' '; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- avatar() escapes.
if ( ! empty( $c['company'] ) ) {
echo '
' . esc_html( Nodebook_Fields::name_case( $c['company'] ) ) . ' ';
}
echo '
';
if ( Nodebook_Alerts::is_hot( $c ) ) {
echo '' . esc_html__( 'hot', 'nodebook' ) . ' ';
}
if ( ! empty( $c['remind_at'] ) ) {
$due = strtotime( $c['remind_at'] . ' UTC' ) <= time();
echo ' ' . esc_html( wp_date( 'j M', strtotime( $c['remind_at'] . ' UTC' ) ) ) . ' ';
}
if ( (float) $c['total_spent'] > 0 ) {
echo '' . esc_html( Nodebook_Admin::money( $c['total_spent'] ) ) . ' ';
}
if ( $team && $c['owner_id'] ) {
echo '' . esc_html( Nodebook_Team::name( $c['owner_id'] ) ) . ' ';
}
echo '' . ( $c['last_seen'] ? wp_kses( Nodebook_Admin::ago( $c['last_seen'] ), Nodebook_Admin::KSES ) : esc_html__( 'not seen yet', 'nodebook' ) ) . '
';
// Keyboard / no-drag alternative: a plain form that also works without JavaScript.
echo ' ';
}
/** Change status and log it on the timeline. */
public static function set_status( $id, $status ) {
$id = absint( $id );
$statuses = Nodebook_Fields::statuses();
$c = Nodebook_Contacts::get( $id );
if ( ! $c || ! isset( $statuses[ $status ] ) ) {
return false;
}
if ( $c['status'] !== $status ) {
Nodebook_Contacts::update( $id, array( 'status' => $status ) );
Nodebook_Activities::add(
$id,
'status',
sprintf(
/* translators: 1: old status, 2: new status */
__( 'Status: %1$s → %2$s', 'nodebook' ),
$statuses[ $c['status'] ] ?? $c['status'],
$statuses[ $status ]
),
array( 'user_id' => get_current_user_id() )
);
}
return true;
}
public static function set_status_ajax() {
check_ajax_referer( 'nodebook_ajax', 'nonce' );
if ( ! current_user_can( Nodebook_Admin::cap() ) ) {
wp_send_json_error( null, 403 );
}
$id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0;
$status = isset( $_POST['status'] ) ? sanitize_key( wp_unslash( $_POST['status'] ) ) : '';
if ( ! self::set_status( $id, $status ) ) {
wp_send_json_error( null, 400 );
}
wp_send_json_success( array( 'label' => Nodebook_Fields::statuses()[ $status ] ) );
}
public static function set_status_post() {
$id = isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification -- ID is part of the nonce action verified below.
Nodebook_Admin::require_cap();
check_admin_referer( 'nodebook_status_' . $id );
$status = isset( $_POST['status'] ) ? sanitize_key( wp_unslash( $_POST['status'] ) ) : '';
self::set_status( $id, $status );
$back = isset( $_POST['back'] ) && 'board' === sanitize_key( wp_unslash( $_POST['back'] ) ) ? Nodebook_Admin::url( 'nodebook-board' ) : Nodebook_Admin::url( 'nodebook', array( 'action' => 'view', 'id' => $id ) );
Nodebook_Admin::redirect( $back, 'saved' );
}
}