05-30-2012, 02:48 AM
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:
add this:
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.
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: )
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.
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: )