Community Support for OpenDocMan (Deprecated)

Full Version: Mail for rewieving
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, in first sorry for my english, not very famous.
Just a question: why a mail is not send to a rewiever when a new file is uploaded. I have just the message in the admin page that there is one file to rewieving. I think that it would be good that a mail was send to qay to a reviewer (or to the admin) that a new file is waiting.
Is it possible? If yes, why?

Thanks everybody.
Greats from France
Pat
I don't believe that feature is currently in the OpenDocMan core code. That being said, this sounds like a great opportunity for an easy plugin to be written by someone. Or you could add this to our feature request page and see if others vote on it: http://opendocman.uservoice.com/
In fact, is very easy to add this function in the "add.php" file.
I do this with a function (SendMailMime) what is on my site:
on the file add.php after the line 643 where is written this:

Code:
// Call the plugin API
        callPluginMethod('onAfterAdd',$fileId);


i have put the function to send mails:

Code:
        // modified by pat46fr for sending a mail to a rewiever
                
function SendMailMIME($MailTo, $From, $Subject, $Body, $File="")
{
    // generate a random string to be used as the boundary marker
    $boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
    
    if ($File!="") {
        // open the file for a binary read
        $handle = fopen($File,'r');
                
        // read the file content into a variable
        $data = fread($handle,filesize($File));
                
        // close the file
        fclose($handle);
        
        // now we encode it and split it into acceptable length lines
        $data = chunk_split(base64_encode($data));
    }            
        
    // now we'll build the message headers
    $headers = "From: ".$From."\n"."MIME-Version: 1.0\n"."Content-Type: multipart/alternative;\n"." boundary=\"{$boundary}\"\n\n";
    
    // next, we'll build the message body. note that we insert two dashes in front of the MIME boundary when we use it
    $headers .= "--{$boundary}\n"."Content-Type: text/html; charset=iso-8859-1\n".$Body."\n\n";
    
    if ($File!="") {
        // now we'll insert a boundary to indicate we're starting the attachment we have to specify the content type, filename, and disposition as an attachment, then add the file content and set another boundary to indicate that the end of the file has been reached
        $headers .= "--{".$boundary."}\n"."Content-Type: text/plain; charset=iso-8859-1\n"."name=\"{".$File."}\"\n"."Content-Transfer-Encoding: base64\n Content-Disposition: attachment; \n"."filename=\"{".$File."}\"\n\n".$data."\n\n--{".$boundary."}--\n";
    }
        
    // now we just send the message
    
    $LF = "\n";

    $headers  = 'MIME-Version: 1.0'.$LF;
    $headers .= 'Content-type: text/html; charset=iso-8859-1'.$LF;
    $headers .= "From: ".$From.$LF;

    return(@mail($MailTo, $Subject, $Body, $headers));
}

after just call the function with good parameters
Code:
        
        // mail avis arrivee document
        $bodyL = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>ODM- Nouveau document</title><style type=\"text/css\"><!-- body,td,th {    font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12px;} body {background-color: #CCFFCC;}--></style></head>\n";
        $bodyL.="<body>\n";        
        $bodyL.="Il y a un nouveau fichier a examiner";
        $bodyL.="<p> qui vient d'être posté.</p>";
        $bodyL.= "<a href='http://www.//[i]My_site.fr[/i]/odm/index.php'>Connectez vous pour le valider</a>";

        SendMailMIME("[i]Mail_adress_of_a_rewiever[/i] ", "ODM", "Nouveau document", $bodyL,"");
        
        //Fin modif pat46 *********************************************************
    //the end of the initial code    
        header('Location: details.php?id=' . $fileId . '&last_message=' . $message);
    }
}
........

It just a simply example for just one rewiever (it's my case), but i think it it possible de read the database and change the Mail_adress_of_a_rewiever for each rewiever.
And add for looking if "authorization" in parameters is False or True because a mail is send if the "authorization" is true or false Sad I think is not very hard to do but for today is all (i am tired, lol)

I hope that enjoy someone Smile and thanks foor the initial job.
Pat46fr
Hey, a little word:
It' possible to send mail only if the parameter "authorization" is true, to do that only put a condition for send mail:
Code:
if ($GLOBALS['CONFIG']['authorization'] == 'True') //si demande autoristion
{
SendMailMIME("[i]Mail_adress_of_a_rewiever[/i] ", "ODM", "Nouveau document", $bodyL,"");
}

Pat
Thanks. Maybe Stephen can implement it in next release.
Hello, after several tests i have find the way to send mail to rewiever when a document is posted. The best way (for me) is to modifie the file "details.php" and not the "add.php". More infos on the document are avaiable in this file.
My modification do:
_ find the department of the file
_ find rewiever(s) for this department
_ in not rewiever, take the admin as rewiever
_ send mail(s) to rewiever(s) with infos on the document

For doing that, in the "details.php", after the line 81 where is write:
Quote:$reviewer = $filedata->getReviewerName();

add this:

Code:
// modified by pat46fr for sending a mail to a rewiever ***************************************************************************************
$department = $filedata->getDepartment();

function SendMailMIME($MailTo, $From, $Subject, $Body, $File="")
{
    // generate a random string to be used as the boundary marker
    $boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
        if ($File!="") {
        // open the file for a binary read
        $handle = fopen($File,'r');
                
        // read the file content into a variable
        $data = fread($handle,filesize($File));
                
        // close the file
        fclose($handle);
        
        // now we encode it and split it into acceptable length lines
        $data = chunk_split(base64_encode($data));
    }            
        
    // now we'll build the message headers
    $headers = "From: ".$From."\n"."MIME-Version: 1.0\n"."Content-Type: multipart/alternative;\n"." boundary=\"{$boundary}\"\n\n";
    // next, we'll build the message body. note that we insert two dashes in front of the MIME boundary when we use it
    $headers .= "--{$boundary}\n"."Content-Type: text/html; charset=iso-8859-1\n".$Body."\n\n";
    
    if ($File!="") {
        // now we'll insert a boundary to indicate we're starting the attachment we have to specify the content type, filename, and disposition as an attachment, then add the file content and set another boundary to indicate that the end of the file has been reached
        $headers .= "--{".$boundary."}\n"."Content-Type: text/plain; charset=iso-8859-1\n"."name=\"{".$File."}\"\n"."Content-Transfer-Encoding: base64\n Content-Disposition: attachment; \n"."filename=\"{".$File."}\"\n\n".$data."\n\n--{".$boundary."}--\n";
    }
        
    // now we just send the message
    $LF = "\n";
    $headers  = 'MIME-Version: 1.0'.$LF;
    $headers .= 'Content-type: text/html; charset=iso-8859-1'.$LF;
    $headers .= "From: ".$From.$LF;
    return(@mail($MailTo, $Subject, $Body, $headers));
}


        if ($GLOBALS['CONFIG']['authorization'] == 'True') //si demande autoristion
        {            
        
//department name (for the mail text)
$ChercheNomDept = mysql_query ("select Name from odm_department where id = ".$department."") or die('Erreur SQL !'.$reponse.'<br>'.mysql_error());
$rs_NomDept = mysql_fetch_array($ChercheNomDept);
$NomDept = $rs_NomDept[0];
        
//search rewiever(s) of department        
$reponse = mysql_query ("select * from odm_dept_reviewer where dept_id = ".$department."") or die('Erreur SQL !'.$reponse.'<br>'.mysql_error());    
$rs = mysql_fetch_array($reponse);

IF ($rs == "") //no rewiever
{
$Id_rewiever = 1;   // select the admin as rewiever
$chercherewiever = mysql_query ("select * from odm_user where id = ".$Id_rewiever."") or die('Erreur SQL !'.$reponse.'<br>'.mysql_error());
$rs_infosrewiever = mysql_fetch_array($chercherewiever);
$nameRewiever = $rs_infosrewiever[1];
$mailRewiever = $rs_infosrewiever[5];
    // create body of mail
        $bodyL = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>ODM - Nouveau document</title><style type=\"text/css\"><!-- body,td,th {    font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12px;} body {background-color: #CCFFCC;}--></style></head>\n";
        $bodyL.="<body>\n";        
        $bodyL.="Cher <b>".$nameRewiever."</b>, il y a un nouveau fichier à valider dans ODM:<br>";
        $bodyL.="Nom <b>".$realname." </b><br>";
        $bodyL.="mis par <b>".$owner."</b><br>";
        $bodyL.="dans le service <b>".$NomDept.".</b><br>";
        $bodyL.= "<p><a href='http://the_site_name/odm/index.php'/odm/index.php'>Connectez vous pour le valider</a></p>";

        SendMailMIME($mailRewiever, "ODM", "Nouveau document sur ODM", $bodyL,"");    //sending mail
        
}
else
{
$reponse = mysql_query ("select * from odm_dept_reviewer where dept_id = ".$department."") or die('Erreur SQL !'.$reponse.'<br>'.mysql_error());    
    //one or more rewievers
    while ($rs = mysql_fetch_array($reponse))
    {
$Id_rewiever = $rs[1];  

//select rewiever for get infos
$chercherewiever = mysql_query ("select * from odm_user where id = ".$Id_rewiever."") or die('Erreur SQL !'.$reponse.'<br>'.mysql_error());
$rs_infosrewiever = mysql_fetch_array($chercherewiever);
$nameRewiever = $rs_infosrewiever[1];
$mailRewiever = $rs_infosrewiever[5];

        // create body of mail
        $bodyL = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"><title>ODM - Nouveau document</title><style type=\"text/css\"><!-- body,td,th {    font-family: Verdana, Arial, Helvetica, sans-serif; font-size:12px;} body {background-color: #CCFFCC;}--></style></head>\n";
        $bodyL.="<body>\n";        
        $bodyL.="Cher <b>".$nameRewiever."</b>, il y a un nouveau fichier à valider dans ODM:<br>";
        $bodyL.="Nom <b>".$realname." </b><br>";
        $bodyL.="mis par <b>".$owner."</b><br>";
        $bodyL.="dans le service <b>".$NomDept.".</b><br>";
        $bodyL.= "<p><a href=the_site_name/odm/index.php'>Connectez vous pour le valider</a></p>";

        SendMailMIME($mailRewiever, "ODM", "Nouveau document sur ODM", $bodyL,"");    //sending mail
        }
        }    
        }
    //Fin modif pat46 *********************************************************

You must be modified the "the_site_name" in the last line of body of the mail to write your site in place

For me this code is functional. Perhaps (sure) it's possible to do best and more 'pretty' but i am not a pro of php and y do that only for pleasure. Smile
I hope that this will be help someone, and perhaps integrated in ODM a day.

Good journey everybody.
Pat46fr ( a frenchman who trie to speak english :oops: )