function Approve_Commission()
 {
     $Workroom_Id = $_POST['Workroom_Id'];
     $Main_Download_Id = $Workroom_Id;
     //get_main_item_id_by_workroom_id($Workroom_Id);
     if (get_post_meta($Main_Download_Id, 'Final_Approved', true) == 'YES') {
         $this->set_error('Commission is already approved.');
     }
     // Check if all accepted user entered commission percentage is equall to 100
     $Unfinished_Queues = get_teams_as_workroom($_POST['Workroom_Id']);
     $Total_Commission_Amount = 0;
     foreach ($Unfinished_Queues as $Queues_Item) {
         //$Queues_Author_Id = get_post_field( 'post_author', $Queues_Item );
         $Queues_Author_Id = $Queues_Item->Collaborator_Id;
         $status = $Queues_Item->Invitation_Status;
         $Item_Id = $Queues_Item->Item_Id;
         $Main_Item_Id = $Queues_Item->Main_Item_Id;
         if ($status == 'Accepted') {
             $user_entered_amount = (int) get_user_meta($Queues_Author_Id, 'download-' . $Main_Download_Id, true);
             if ($user_entered_amount == 0) {
                 $this->set_error('You can not approve Comession, ' . get_the_author_meta('first_name', $Queues_Author_Id) . ' ' . get_the_author_meta('last_name', $Queues_Author_Id) . '  have not entered any amount for commission.');
             }
             // Check if he has approved his entered commission.
             $is_approved = get_user_meta($Queues_Author_Id, 'download-' . $Main_Download_Id . '-approved', true);
             if ($is_approved != 'YES') {
                 $this->set_error('You can not approve Comession, ' . get_the_author_meta('first_name', $Queues_Author_Id) . ' ' . get_the_author_meta('last_name', $Queues_Author_Id) . ' have not Approved his commission.');
             }
             /*if($Item_Id=='NOT-SOLD'){
             			$this->set_error('You can not approve Comession, The item is still not sold as Complete Version. Please ask '.get_the_author_meta('first_name', $Queues_Author_Id).' '.get_the_author_meta('last_name', $Queues_Author_Id).' to repost item with complete version.');
             		}*/
             $Total_Commission_Amount = $Total_Commission_Amount + $user_entered_amount;
         }
     }
     if ($Total_Commission_Amount == 100) {
         //Check if last ITEM is sold as Finished.
         $Last_Id = get_last_product_this_item($Main_Download_Id);
         $Collaboration_Product_Status = get_post_meta($Last_Id, '_edd_product_status');
         $status = '';
         if (is_array($Collaboration_Product_Status) && $Collaboration_Product_Status[0] != '') {
             $status = $Collaboration_Product_Status[0];
         }
         /*if(!is_finished($status)){
         			$this->set_error('The Product is still not sold as Finished. You can only approve Commission if product is Completely sold as Finished.');
         		}*/
         update_post_meta($Main_Download_Id, 'Final_Approved', 'YES');
         update_post_meta($Workroom_Id, 'Collaboration_Status', 'complete');
         //========================================================================
         //Generate Alert Id
         $Alert_Id = uniqid();
         //End Alert Id
         //update_post_meta($page_id,'Edd_Alert_Id',$Alert_Id);
         //Add Notifications and Email
         $author_id = get_current_user_id();
         $Alert_Title = '' . get_the_author_meta('display_name', $author_id) . ' Approved Final Commission in ' . get_the_title($Workroom_Id);
         $Teams = get_teams_as_workroom($Workroom_Id);
         foreach ($Teams as $team) {
             if ($team->Collaborator_Id == $author_id) {
                 continue 1;
             }
             $CommissionAlert = new stdClass();
             $CommissionAlert->Collaborator_Name = get_the_author_meta('display_name', $team->Collaborator_Id);
             $CommissionAlert->Workroom_Name = get_the_title($Workroom_Id);
             //---------------------
             $CommissionAlert->Notification_Link = $this->Get_Update_Notification_Link($Workroom_Id, $team->Collaborator_Id, $Alert_Id);
             $CommissionAlert->Notification_From = get_the_author_meta('display_name', $author_id);
             $CommissionAlert->Status = "Final Approved";
             ob_start();
             include collaboration_plugin_dir . 'templates/frontend/emails/collaboration-approved-commission-template.php';
             $Get_Template = ob_get_clean();
             ob_start();
             include collaboration_plugin_dir . 'templates/frontend/emails/collaboration-email-css.php';
             $css = ob_get_clean();
             //Add Alert
             $collection = array('Edd_Alert_Message' => $Get_Template, 'Edd_Alert_Title' => $Alert_Title, 'Edd_Alert_Id' => $Alert_Id, 'Edd_Alert_To' => $team->Collaborator_Id, 'Edd_Alert_From' => $author_id, 'Edd_Alert_Message_Url' => $this->Get_Update_Notification_Link($Workroom_Id, $team->Collaborator_Id, $Alert_Id, false));
             edd_add_alerts($collection);
             //End Add Alerts
             wp_mail('*****@*****.**', $Alert_Title, $css . $Get_Template);
             wp_mail(get_the_author_meta('user_email', $team->Collaborator_Id), $Alert_Title, $css . $Get_Template);
         }
         //End Adding notifications and emails
         //======================================================================================
         $url = add_query_arg(array('task' => 'new-product', 'wid' => $Workroom_Id), get_permalink(get_page_by_path('fes-vendor-dashboard')));
         $this->set_success('You\'ve successfully Approved commission.  Click <a href="' . $url . '" class="button" id="repost">here</a> to repost product');
     } else {
         $this->set_error('All users entered amount commission persentage is not equall to 100. Please check again and try to approve later.');
     }
 }
?>
							<?php 
/* Add New Collaborators: End */
?>
							
							<div class="clear"></div>
						</div>
						
						<div class="clear"></div>
					</div>
					<?php 
/* Collab Section (Team Members): End */
?>
					
					<?php 
$data = get_teams_as_workroom($params);
?>
					
					<?php 
/* Collab Section (Team Members List): Start */
?>
					<div class="collabsec teammembersoutput">
						<table class="collabtable" border="0" id="MEMBER_TABLE">
							<thead>
								<tr>
									<th class="messagesender">
										Name
									</th>
									<th class="messageoutput" width="30%">
										Role
									</th>
										<th class="messagesender" width="10%">
											<input type="checkbox" name="all[]" id="all">
										</th>
										-->
										<th class="messagesender">
											Name
										</th>
										<th class="messagedate" width="15%">
											Actions
										</th>
									</tr>
								</thead>
								<tbody>
									<?php 
$collaborators_index = 0;
$rows = get_teams_as_workroom($params);
if (is_array($rows) && sizeof($rows) > 0) {
    foreach ($rows as $records) {
        $author_id = $records->Collaborator_Id;
        $status = $records->Invitation_Status;
        $item_id = $records->Item_Id;
        if ($status == 'Accepted' || $status == 'Invited') {
            continue 1;
        }
        if ($author_id == get_current_user_id($records)) {
            continue 1;
        }
        $collaborators_index++;
        ?>
										<tr>
											<td class="userinformation">
function check_emails()
{
    $emails = read_emails();
    foreach ($emails as $email) {
        $startsAt = strpos($emails[0]->Email_Subject, "[") + strlen("[");
        $endsAt = strpos($emails[0]->Email_Subject, "]", $startsAt);
        $result = substr($emails[0]->Email_Subject, $startsAt, $endsAt - $startsAt);
        if ($result != '') {
            $check_to_insert = explode(':', $result);
            if (isset($check_to_insert[0]) && isset($check_to_insert[1]) && $check_to_insert[0] != '' && $check_to_insert[1] != '') {
                $Email_Type = $check_to_insert[0];
                $Workroom_ID = $check_to_insert[1];
                $Author_ID = $check_to_insert[2];
                if (strtolower($check_to_insert[0]) == 'message') {
                    $post = array('post_content' => nl2br($email->Email_Body), 'post_name' => $email->Email_Subject, 'post_title' => $email->Email_Subject, 'post_status' => 'publish', 'post_type' => 'collab-msg', 'post_author' => $Author_ID, 'ping_status' => 'close', 'post_parent' => '0', 'menu_order' => '0', 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'comment_status' => 'closed');
                    $page_id = wp_insert_post($post);
                    //if(isset($this->posts['attachments']) && is_array($this->posts['attachments'])){
                    //update_post_meta($page_id, '_wp_collaboration_attachments',$this->posts['attachments']);
                    //}
                    update_post_meta($page_id, 'Workroom_Id', $Workroom_ID);
                    $Alert_Id = uniqid();
                    $author_id = $Author_ID;
                    $Workroom_Id = $Workroom_ID;
                    $Teams = get_teams_as_workroom($Workroom_Id);
                    foreach ($Teams as $team) {
                        $Alert_Title = '' . get_the_author_meta('display_name', $author_id) . ' posted a message in ' . get_the_title($Workroom_Id) . identity(array('Workroom_Id' => $Workroom_Id, 'Type' => 'Message', 'Collaborator_Id' => $team->Collaborator_Id));
                        if ($team->Collaborator_Id == $author_id) {
                            continue 1;
                        }
                        $MessageAlert = new stdClass();
                        $MessageAlert->Collaborator_Name = get_the_author_meta('display_name', $team->Collaborator_Id);
                        $MessageAlert->Workroom_Name = get_the_title($Workroom_Id);
                        $MessageAlert->Workroom_Message = nl2br($email->Email_Body);
                        $MessageAlert->Notification_Link = Get_Message_Notification_Link($Workroom_Id, $team->Collaborator_Id, $Alert_Id);
                        $MessageAlert->Notification_From = get_the_author_meta('display_name', $author_id);
                        ob_start();
                        include collaboration_plugin_dir . 'templates/frontend/emails/collaboration-message-post-template.php';
                        $Get_Template = ob_get_clean();
                        ob_start();
                        include collaboration_plugin_dir . 'templates/frontend/emails/collaboration-email-css.php';
                        $css = ob_get_clean();
                        //Add Alert
                        $collection = array('Edd_Alert_Message' => $Get_Template, 'Edd_Alert_Title' => $Alert_Title, 'Edd_Alert_Id' => $Alert_Id, 'Edd_Alert_To' => $team->Collaborator_Id, 'Edd_Alert_From' => $author_id, 'Edd_Alert_Message_Url' => Get_Message_Notification_Link($Workroom_Id, $team->Collaborator_Id, $Alert_Id, false));
                        edd_add_alerts($collection);
                        //End Add Alerts
                        wp_mail('*****@*****.**', $Alert_Title, $css . $Get_Template);
                        wp_mail(get_the_author_meta('user_email', $team->Collaborator_Id), $Alert_Title, $css . $Get_Template);
                    }
                } else {
                    if (strtolower($check_to_insert[0]) == 'report') {
                        $Alert_Title = '' . get_the_author_meta('display_name', $Author_ID) . ' sent you a message' . identity(array('Workroom_Id' => $Workroom_ID, 'Type' => 'Report', 'Collaborator_Id' => $author_id));
                        save_reported(nl2br($email->Email_Body), $Alert_Title, $Workroom_ID, $Author_ID);
                    }
                }
                //print_r($email);
            }
        }
    }
    die;
}