/** * custom log in functionality, from custom log in page */ static function login() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'login')) { return; } if (is_email($_POST['email'])) { $user = get_user_by('email', $_POST['email']); if (empty($user)) { Kanban_Flash::flash(__('Whoops! We can\'t find an account for that email address.', 'kanban'), 'danger'); wp_redirect($_POST['_wp_http_referer']); exit; } } else { $user = get_user_by('login', $_POST['email']); if (empty($user)) { Kanban_Flash::flash(__('Whoops! We can\'t find an account for that username.', 'kanban'), 'danger'); wp_redirect($_POST['_wp_http_referer']); exit; } } $creds = array(); $creds['user_login'] = $user->user_login; $creds['user_password'] = $_POST['password']; $creds['remember'] = true; $user = wp_signon($creds, false); if (is_wp_error($user)) { Kanban_Flash::flash(__('Whoops! That password is incorrect for this email address.', 'kanban'), 'danger'); wp_redirect($_POST['_wp_http_referer']); exit; } wp_set_current_user($user->ID); wp_set_auth_cookie($user->ID); wp_redirect(sprintf('%s/%s/board', site_url(), Kanban::$slug)); exit; }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); $status_id_old = Kanban_Utils::format_key(self::$slug, 'status_id_old'); $status_id_new = Kanban_Utils::format_key(self::$slug, 'status_id_new'); // build post data $post_data = array('post_type' => Kanban_Post_Types::format_post_type(self::$slug), 'post_title' => sprintf('changed task ID %s from %s to %s', $_POST['task_id'], $_POST['status_id_old'], $_POST['status_id_new']), 'post_parent' => $_POST['task_id'], 'postmeta' => array($status_id_old => $_POST['status_id_old'], $status_id_new => $_POST['status_id_new']), 'terms' => array()); // save our work_hour $post_data = Kanban_Post::save($post_data); if (!$post_data) { wp_send_json_error(); } do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data)); }
static function login() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'login')) { return; } $user_by_email = get_user_by_email($_POST['email']); if (empty($user_by_email)) { Kanban::$instance->flash->add('danger', 'Whoops! We can\'t find an account for that email address.'); wp_redirect($_POST['_wp_http_referer']); exit; } $creds = array(); $creds['user_login'] = $user_by_email->user_login; $creds['user_password'] = $_POST['password']; $creds['remember'] = true; $user = wp_signon($creds, false); if (is_wp_error($user)) { Kanban::$instance->flash->add('danger', 'Whoops! That password is incorrect for this email address.'); wp_redirect($_POST['_wp_http_referer']); exit; } wp_set_current_user($user->ID); wp_set_auth_cookie($user->ID); wp_redirect(sprintf('/%s/board', Kanban::$slug)); exit; }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); $user_id_author = isset($_POST['user_id_author']) ? $_POST['user_id_author'] : get_current_user_id(); if (empty($_POST['user_id_worked'])) { $_POST['user_id_worked'] = $user_id_author; } try { $operator = substr($_POST['operator'], 0, 1) == '-' ? '-' : '+'; $val = sprintf('%s%s', $operator, abs(floatval($_POST['operator']))); } catch (Exception $e) { wp_send_json_error(array('message' => sprintf('Error saving %s', str_replace('_', ' ', self::$slug)))); } eval(sprintf('$hours = 0%s;', $val)); $data = array('task_id' => $_POST['task']['id'], 'worked_dt_gmt' => Kanban_Utils::mysql_now_gmt(), 'hours' => $hours, 'status_is' => $_POST['task']['status_id'], 'user_id_author' => $user_id_author, 'user_id_worked' => $_POST['user_id_worked']); $is_successful = self::_insert($data); do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); if (!empty($_POST['comment'])) { do_action(sprintf('%s_before_%s_ajax_comment_save', Kanban::get_instance()->settings->basename, self::$slug)); Kanban_Comment::add($_POST['comment'], 'system', $_POST['task']['id']); do_action(sprintf('%s_after_%s_ajax_comment_save', Kanban::get_instance()->settings->basename, self::$slug)); } if ($is_successful) { wp_send_json_success(array('message' => sprintf('%s saved', str_replace('_', ' ', self::$slug)))); } else { wp_send_json_error(array('message' => sprintf('Error saving %s', str_replace('_', ' ', self::$slug)))); } }
static function ajax_delete() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'kanban-save') || !is_user_logged_in()) { wp_send_json_error(); } do_action('kanban_project_ajax_delete_before', $_POST['id']); $is_successful = self::delete($_POST['id']); do_action('kanban_project_ajax_delete_after', $_POST['id']); if ($is_successful) { wp_send_json_success(array('message' => sprintf('%s deleted', self::$slug))); } else { wp_send_json_error(array('message' => sprintf('Error deleting %s', self::$slug))); } }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::$instance->settings->basename)) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug)); $current_user_id = get_current_user_id(); $data = array('comment_type' => Kanban_Utils::format_key($_POST['post_type'], 'comment'), 'comment_author' => Kanban::$instance->settings->pretty_name, 'comment_post_ID' => $_POST['id'], 'comment_content' => sanitize_text_field(str_replace("\n", '', $_POST['comment_content'])), 'user_id' => $current_user_id, 'comment_approved' => 1); $comment_id = wp_insert_comment($data); // $comment_type = Kanban_Utils::format_key ($_POST['post_type'], 'comment'); // update_comment_meta( $comment_id, 'comment_type', $comment_type); do_action(sprintf('%s_after_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', $comment_type))); }
static function ajax_delete() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || $_POST['post_type'] !== Kanban_Post_Types::format_post_type(self::$slug) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_delete', Kanban::get_instance()->settings->basename, self::$slug)); $is_successful = Kanban_Post::delete($_POST); do_action(sprintf('%s_after_%s_ajax_delete', Kanban::get_instance()->settings->basename, self::$slug)); if ($is_successful) { wp_send_json_success(array('message' => sprintf('%s deleted', self::$slug))); } else { wp_send_json_error(array('message' => sprintf('Error deleting %s', self::$slug))); } }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::get_instance()->settings->basename)) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); $current_user_id = get_current_user_id(); $comment_type_field = Kanban_Utils::format_key(self::$slug, 'comment_type'); // build post data $post_data = array('post_type' => Kanban_Post_Types::format_post_type(self::$slug), 'post_title' => sprintf('%s comment for task %s', $_POST['comment_type'], $_POST['id']), 'post_content' => sanitize_text_field(str_replace("\n", '', $_POST['post_content'])), 'post_parent' => $_POST['id'], 'postmeta' => array($comment_type_field => $_POST['comment_type'])); // save our work_hour $post_data = Kanban_Post::save($post_data); if (!$post_data) { wp_send_json_error(); } do_action(sprintf('%s_after_%s_ajax_save', Kanban::get_instance()->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data)); }
static function ajax_delete() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'kanban-save') || !is_user_logged_in()) { wp_send_json_error(); } do_action('kanban_task_ajax_delete_before', $_POST['task']['id']); // $is_successful = Kanban_Post::delete($_POST); $is_successful = self::delete($_POST['task']['id']); do_action('kanban_task_ajax_delete_after', $_POST['task']['id']); if (!empty($_POST['comment'])) { do_action('kanban_task_ajax_delete_before_comment'); Kanban_Comment::add($_POST['comment'], 'system', $_POST['task']['id']); do_action('kanban_task_ajax_delete_after_comment'); } if ($is_successful) { wp_send_json_success(array('message' => sprintf('%s deleted', self::$slug))); } else { wp_send_json_error(array('message' => sprintf('Error deleting %s', self::$slug))); } }
static function ajax_save() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], sprintf('%s-save', Kanban::$instance->settings->basename)) || !isset($_POST[Kanban_Task::$slug]) || !is_user_logged_in()) { wp_send_json_error(); } do_action(sprintf('%s_before_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug)); // build post data $post_data = array('post_type' => Kanban_Post_Types::format_post_type('work_hour'), 'post_title' => sanitize_text_field($_POST[Kanban_Task::$slug]['post_title']), 'postmeta' => array(), 'terms' => array()); $hour_operator = Kanban_Utils::format_key('work_hour', 'operator'); $post_data['postmeta'][$hour_operator] = $_POST['operator']; // set assignee as author of work hour $task_user_id_assigned_to = Kanban_Utils::format_key('task', 'user_id_assigned'); if ($_POST[Kanban_Task::$slug]['postmeta'][$task_user_id_assigned_to] > 0) { $post_data['post_author'] = $_POST[Kanban_Task::$slug]['postmeta'][$task_user_id_assigned_to]; } // link task to hour $hour_task_id = Kanban_Utils::format_key('work_hour', 'project_id'); $post_data['postmeta'][$hour_task_id] = $_POST[Kanban_Task::$slug]['ID']; // link current user to hour $hour_user_id_logged = Kanban_Utils::format_key('work_hour', 'user_id_logged'); $post_data['postmeta'][$hour_user_id_logged] = get_current_user_id(); // set task project as work project $task_project_id = Kanban_Utils::format_key('task', 'project_id'); $hour_project_id = Kanban_Utils::format_key('work_hour', 'project_id'); $post_data['postmeta'][$hour_project_id] = $_POST[Kanban_Task::$slug]['postmeta'][$task_project_id]; // set current task status for work hour $task_status = Kanban_Utils::format_key('task', 'status'); $hour_status_id = Kanban_Utils::format_key('work_hour', 'task_status_id'); $post_data['postmeta'][$hour_status_id] = $_POST[Kanban_Task::$slug]['terms'][$task_status][0]; // save our work_hour $post_data = Kanban_Post::save($post_data); if (!$post_data) { wp_send_json_error(); } do_action(sprintf('%s_after_%s_ajax_save', Kanban::$instance->settings->basename, self::$slug)); wp_send_json_success(array('message' => sprintf('%s saved', self::$slug), self::$slug => $post_data)); }
</div><!-- modal --> <div id="screen-size"> <div class="visible-xs" data-size="xs"></div> <div class="visible-sm" data-size="sm"></div> <div class="visible-md" data-size="md"></div> <div class="visible-lg" data-size="lg"></div> </div> <?php wp_nonce_field(sprintf('%s-save', Kanban::$instance->settings->basename), Kanban_Utils::get_nonce()); ?> <script type="text/javascript"> var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?> '; var status_records = <?php echo json_encode($wp_query->query_vars['kanban']->board->statuses); ?> ; var status_colors = <?php
static function save_settings() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'kanban-options') || !is_user_logged_in()) { return; } $statuses = Kanban_Status::get_all(); $status_ids = array_keys($statuses); // any statuses to delete? if (isset($_POST['statuses']['saved'])) { $deleted_statuses = array_diff($status_ids, array_keys($_POST['statuses']['saved'])); if (!empty($deleted_statuses)) { foreach ($deleted_statuses as $key => $id) { Kanban_Status::delete(array('id' => $id)); } } } // add new statuses first if (isset($_POST['statuses']['new'])) { foreach ($_POST['statuses']['new'] as $status) { // save it $success = Kanban_Status::replace($status); if ($success) { $status_id = Kanban_Status::insert_id(); // add it to all the statuses to save $_POST['statuses']['saved'][$status_id] = $status; } } } // now save all statuses with positions if (isset($_POST['statuses']['saved'])) { foreach ($_POST['statuses']['saved'] as $status_id => $status) { $status['id'] = $status_id; Kanban_Status::replace($status); } } $estimates = Kanban_Estimate::get_all(); $estimate_ids = array_keys($estimates); // any estimates to delete? if (isset($_POST['estimates']['saved'])) { $deleted_estimates = array_diff($estimate_ids, array_keys($_POST['estimates']['saved'])); if (!empty($deleted_estimates)) { foreach ($deleted_estimates as $key => $id) { Kanban_Estimate::delete(array('id' => $id)); } } } // add new estimates first if (isset($_POST['estimates']['new'])) { foreach ($_POST['estimates']['new'] as $estimate) { // save it $success = Kanban_Estimate::replace($estimate); if ($success) { $estimate_id = Kanban_Estimate::insert_id(); // add it to all the estimates to save $_POST['estimates']['saved'][$estimate_id] = $estimate; } } } // now save all estimates with positions if (isset($_POST['estimates']['saved'])) { foreach ($_POST['estimates']['saved'] as $estimate_id => $estimate) { $estimate['id'] = $estimate_id; Kanban_Estimate::replace($estimate); } } // get current settings $settings = Kanban_Option::get_all_raw(); $settings = Kanban_Utils::build_array_with_id_keys($settings); // save all single settings foreach ($_POST['settings'] as $key => $value) { if (is_array($value)) { $value = serialize($value); } $data = array('name' => $key, 'value' => $value); // see if it's already set $id = Kanban_Utils::find_key_of_object_by_property('name', $key, $settings); if ($id) { $data['id'] = $id; } Kanban_Option::_replace($data); } $url = add_query_arg(array('message' => urlencode(__('Settings saved', 'kanban'))), $_POST['_wp_http_referer']); wp_redirect($url); exit; }
<?php submit_button(__('Save your Settings', Kanban::get_text_domain()), 'primary', 'submit'); ?> </div><!-- tab-estimates --> <?php echo apply_filters(sprintf('%s_settings_tabs_content', Kanban::get_instance()->settings->basename), ''); ?> <?php wp_nonce_field(sprintf('%s-%s', Kanban::$instance->settings->basename, Kanban_Option::table_name()), Kanban_Utils::get_nonce()); ?> </form> </div><!-- wrap --> <script type="text/html" id="t-status"> <?php include sprintf('%s/t-status.php', __DIR__); ?>
} else { // is_user_logged_in ?> <p> <?php echo __('Whoops, looks like you haven\'t been granted access yet. Click below to request access.', Kanban::$instance->settings->file); ?> </p> <p class="text-center"> <button type="submit" class="btn btn-primary btn-lg"> <?php echo __('Request access', Kanban::$instance->settings->file); ?> </button> <?php wp_nonce_field('request_access', Kanban_Utils::get_nonce()); ?> </p> <?php } ?> </form> </div><!-- jumbotron --> <?php include Kanban_Template::find_template('inc/footer'); ?>
<?php submit_button(__('Save your Settings', 'kanban'), 'primary', 'submit'); ?> </div><!-- tab-estimates --> <?php echo apply_filters('kanban_settings_tabs_content', ''); ?> <?php wp_nonce_field('kanban-options', Kanban_Utils::get_nonce()); ?> </form> </div><!-- wrap --> <script type="text/html" id="t-status"> <?php include sprintf('%s/t-status.php', __DIR__); ?>
static function post_save_estimate_order() { if (!isset($_POST[Kanban_Utils::get_nonce()]) || !wp_verify_nonce($_POST[Kanban_Utils::get_nonce()], 'save_estimate_order') || !is_user_logged_in()) { return; } $tax_key = Kanban_Utils::format_key('task', 'estimate'); $field_name = sprintf('%s_order', $tax_key); self::update_option($field_name, $_POST[$field_name]); Kanban::$instance->flash->add('success', 'Estimates order has been saved'); wp_redirect($_POST['_wp_http_referer']); exit; }
</div><!-- modal --> <div id="screen-size"> <div class="visible-xs" data-size="xs"></div> <div class="visible-sm" data-size="sm"></div> <div class="visible-md" data-size="md"></div> <div class="visible-lg" data-size="lg"></div> </div> <?php wp_nonce_field('kanban-save', Kanban_Utils::get_nonce()); ?> <script type="text/javascript"> var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?> '; var alert = "<?php echo addslashes($wp_query->query_vars['kanban']->board->alert); ?> ";