Loading

Send email to admin once task is re-opened - code inside :)

General Discussion around Collabtive

Send email to admin once task is re-opened - code inside :)

Postby BaneD » 14.01.2016, 11:28

This is a follow up - in some sense - to the other thread: Send email to admin once task is completed - code inside :)

Basically I had applied the same logic - I wish to be notified if someone was to re-open some task. Reason? It tells me that task is not to be considered as complete and that some other tasks could end up delayed because of the same. As such I made the mod to have the admin emailed as soon as the task was re-opened.

Again to see if someone is admin, I have used the permission for deleting the task as a reference point.

This is the code for the same:

Code: Select all
//Requires:
//taskreopenedsubject = "One of the tasks has been re-opened";
//taskreopenedtext = "One of the tasks has been re-opened:";
// To be added on line 286 (in default taskmanagement.php file), right behind the following code: if ($task->open($tid)) { within the elseif ($action == "open") { segment

//Lets check if emails are turned on or not
if ($settings["mailnotify"])
{
  $currentTask = $task->getTask($tid);
  $currentProject = new project();

  // We need the list of all of the members of the current project
  $users = $currentProject->getProjectMembers($id, $currentProject->countMembers($id));

  //Lets strole through them..
  foreach($users as $member)
  {

    //Lets check if this is admin account or not and continue further only if it is
    // Admin account - in my opinion - is each account that is given delete privilege of a task, since I do not see it as a good practice that anyone could delete the same
    if ( $member['role']['tasks']['del'] == 1 )
    {
      //Admins should get the email, and in my opinion admins would need to have their emails set, but just in case, we check this and don't send it to the one that closed it (if also admin)
      if (!empty($member["email"]) && $userid != $member["ID"])
      {

        //We will need user language
        $userlang = readLangfile($member['locale']);

        //now adding a temp fix without modifying language files:
        $userlang["taskreopenedsubject"] = "One of the tasks has been re-opened";
        $userlang["taskreopenedtext"] = "One of the tasks has been re-opened:";

        //Lets add the title and the text of the task
        $title = $currentTask['title'];
        $text = $currentTask['text'];

        // send email
        $subject = $userlang["taskreopenedsubject"] . ' (' . $userlang['by'] . ' ' . $username . ')';

        $mailcontent = $userlang["hello"] . ",<br /><br/>" .
                                $userlang["taskreopenedtext"] . ' (' . $userlang['by'] . ' ' . $username . ')' .
                                "<h3><a href = \"" . $url . "managetask.php?action=showtask&id=$id&tid=$tid\">$title</a></h3>".
                                $text;

        $themail = new emailer($settings);

        $themail->send_mail($member["email"], $subject , $mailcontent);
      }
    }
  }
}


As mentioned at the top of the code, there are few requirements to make this work:
1. taskreopenedsubject and taskreopenedtext are missing from the language files so you would need to add them there or have them added within the code as I did above.
2. this should be applied by going to line 286 and making a new line where you paste the code from above. If you have made some changes to your managetask.php this code would not be on the same line, but you can find it by searching for if ($task->open($tid)) { which is within the elseif ($action == "open") { segment,

I hope the code above will help someone :)
BaneD
 
Posts: 16
Joined: 13.01.2016, 20:26

Return to General

Who is online

Users browsing this forum: No registered users

cron