Пример #1
0
 public function reassign_process()
 {
     global $wpdb;
     check_ajax_referer('owf_reassign_ajax_nonce', 'security');
     if (!current_user_can('ow_reassign_task')) {
         wp_die(__('You are not allowed to reassign tasks.'));
     }
     $current_user = sanitize_text_field($_POST["task_user"]) != "" ? intval(sanitize_text_field($_POST["task_user"])) : get_current_user_id();
     $action_history_id = intval($_POST["oasiswf"]);
     $reassign_user_id = intval($_POST["reassign_id"]);
     $reassign_comments = sanitize_text_field($_POST['reassignComments']);
     $action_table = OW_Utility::instance()->get_action_table_name();
     $action_history_table = OW_Utility::instance()->get_action_history_table_name();
     $reassign_comments_json = "";
     $reassign_comments_json_array = "";
     if (!empty($reassign_comments)) {
         $reassign_comments_json = json_encode(array('send_id' => $current_user, 'comment' => stripcslashes($reassign_comments), "comment_timestamp" => current_time("mysql")));
         $reassign_comments_json_array = json_encode(array(array('send_id' => $current_user, 'comment' => stripcslashes($reassign_comments), "comment_timestamp" => current_time("mysql"))));
     }
     $ow_email = new OW_Email();
     if ($action_history_id && $reassign_user_id) {
         $ow_history_service = new OW_History_Service();
         $action = $ow_history_service->get_action_history_by_id($action_history_id);
         // insert record into history table regarding this action
         $data = (array) $action;
         if ($data["assign_actor_id"] != -1) {
             // assignment or publish step (reassigned)
             unset($data["ID"]);
             if (empty($data['due_date']) || $data['due_date'] == '0000-00-00') {
                 unset($data['due_date']);
             }
             if (empty($data['reminder_date']) || $data['reminder_date'] == '0000-00-00') {
                 unset($data['reminder_date']);
             }
             if (empty($data['reminder_date_after']) || $data['reminder_date_after'] == '0000-00-00') {
                 unset($data['reminder_date_after']);
             }
             $data["assign_actor_id"] = $reassign_user_id;
             $data["from_id"] = $action_history_id;
             $data["create_datetime"] = current_time('mysql');
             if (!empty($reassign_comments)) {
                 $data['comment'] = $reassign_comments_json_array;
             }
             $new_history_id = OW_Utility::instance()->insert_to_table($action_history_table, $data);
             if ($new_history_id) {
                 $wpdb->update($action_history_table, array("action_status" => "reassigned"), array("ID" => $action_history_id, "assign_actor_id" => $current_user));
                 $ow_email->delete_step_email($action_history_id, $current_user);
                 $ow_email->send_step_email($new_history_id, $reassign_user_id);
                 // send mail to the actor .
                 echo trim($new_history_id);
             }
         } else {
             // review step (reassigned)
             $reviews = $ow_history_service->get_review_action_by_status("assignment", $action_history_id);
             foreach ($reviews as $review) {
                 if ($review->actor_id == $reassign_user_id) {
                     echo __("Selected user is already assigned the task. Please select another user.", "oasisworkflow");
                     exit;
                 }
             }
             $review = $ow_history_service->get_review_action_by_actor($current_user, "assignment", $action_history_id);
             // if the reassign is in a review process, insert data into the fc_action table
             $review = (array) $review;
             $review_id = $review["ID"];
             unset($review["ID"]);
             if (empty($review['due_date']) || $review['due_date'] == '0000-00-00') {
                 unset($review['due_date']);
             }
             if (empty($review['comments'])) {
                 unset($review['comments']);
             }
             $review["actor_id"] = $reassign_user_id;
             $new_review_history_id = OW_Utility::instance()->insert_to_table($action_table, $review);
             if ($new_review_history_id) {
                 $wpdb->update($action_table, array("review_status" => "reassigned", "comments" => $reassign_comments_json_array, "update_datetime" => current_time("mysql")), array("ID" => $review_id));
                 $data = array("to_id" => $new_review_history_id, "sign_off_date" => current_time("mysql"));
                 $ow_email->delete_step_email($action_history_id, $current_user);
                 $ow_email->send_step_email($action_history_id, $reassign_user_id);
                 // send mail to the actor .
                 echo trim($new_review_history_id);
             }
         }
         die;
     }
 }