By: Raul
Date: 2013-02-25
Time: 17:50
|
Re: Allowed memory size exhausted FATAL ERROR
There is no infinite loop. The code perform a mail merge using a MS Word .docx template.
Here is the code:
<?php
$conn = @mysql_pconnect("", "", "");
$selectedDB = @mysql_select_db("");
if(!$conn || !$selectedDB){
echo "No se puede conectar con la base de datos....";
exit();
}
//Hacer la busqueda de miembros con FVL por vencerse.
$date = new DateTime(date("Y-m-d"));
$date->modify('+180 day');
$sixMonthLater = $date->format('Y-m-d');
$dateDelimiter = new DateTime(date("Y-m-d"));
$dateDelimiter->modify('-6 month');
$delimiterDate = $dateDelimiter->format('Y-m-d');
$q = "QUERY SENTENCE...";
// load the TinyButStrong libraries
include_once('tbs_class.php');
// load the OpenTBS plugin
if (file_exists('tbs_plugin_opentbs.php')) {
include_once('tbs_plugin_opentbs.php');
} else {
echo "No se encuentra el plug-in.";exit();
}
$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load OpenTBS plugin
// Read user choices
if (!isset($_POST['btnSubmit'])) exit("No se puede procesar. Debe acceder a traves de prueba.php");
$suffix = (isset($_POST['suffix']) && (trim($_POST['suffix'])!=='') && ($_SERVER['SERVER_NAME']=='localhost')) ? trim($_POST['suffix']) : '';
$expiredBeforeToday = array();
$expiredToday = array();
$thirtyToExpire = array();
$ninetyToExpire = array();
$sixToExpire = array();
$ninetyDays = new DateTime(date("Y-m-d"));
$ninetyDays->modify('+90 day');
$thirtyDays = new DateTime(date("Y-m-d"));
$thirtyDays->modify('+30 day');
$todayDate = new DateTime(date("Y-m-d"));
$query = @mysql_query($q);
$hoy = date("Y-m-d");
while($row = mysql_fetch_assoc($query)){
$fvl = new DateTime($row['fvl']);
if($fvl < $todayDate){
$expiredBeforeToday[] = array('num_miembro'=>$row['num_miembro'], 'fecha'=>formatDate(substr($hoy, 8, 2), substr($hoy, 5, 2), substr($hoy, 0, 4)), 'nombre'=>(empty($row['ini']) ? $row['nombre'] : $row['nombre']." ".$row['ini']), 'paterno'=>$row['paterno'], 'materno'=>$row['materno'], 'user'=>$row['user'], 'password'=>$row['password'], 'dir1'=>(empty($row['dir2']) ? $row['dir1'] : $row['dir1']."\r\n".$row['dir2']), 'pueblo'=>$row['pueblo'], 'pais'=>$row['pais'], 'zipcode'=>(empty($row['zip4']) ? $row['zipcode'] : $row['zipcode']."-".$row['zip4']));
}
else if($fvl == $todayDate){
$expiredToday[] = array('num_miembro'=>$row['num_miembro'], 'fecha'=>formatDate(substr($hoy, 8, 2), substr($hoy, 5, 2), substr($hoy, 0, 4)), 'nombre'=>(empty($row['ini']) ? $row['nombre'] : $row['nombre']." ".$row['ini']), 'paterno'=>$row['paterno'], 'materno'=>$row['materno'], 'user'=>$row['user'], 'password'=>$row['password'], 'dir1'=>(empty($row['dir2']) ? $row['dir1'] : $row['dir1']."\r\n".$row['dir2']), 'pueblo'=>$row['pueblo'], 'pais'=>$row['pais'], 'zipcode'=>(empty($row['zip4']) ? $row['zipcode'] : $row['zipcode']."-".$row['zip4']));
}
else if($todayDate < $fvl && $fvl < $thirtyDays){
$thirtyToExpire[] = array('num_miembro'=>$row['num_miembro'], 'fecha'=>formatDate(substr($hoy, 8, 2), substr($hoy, 5, 2), substr($hoy, 0, 4)), 'nombre'=>(empty($row['ini']) ? $row['nombre'] : $row['nombre']." ".$row['ini']), 'paterno'=>$row['paterno'], 'materno'=>$row['materno'], 'user'=>$row['user'], 'password'=>$row['password'], 'dir1'=>(empty($row['dir2']) ? $row['dir1'] : $row['dir1']."\r\n".$row['dir2']), 'pueblo'=>$row['pueblo'], 'pais'=>$row['pais'], 'zipcode'=>(empty($row['zip4']) ? $row['zipcode'] : $row['zipcode']."-".$row['zip4']));
}
else if($thirtyDays < $fvl && $fvl < $ninetyDays){
$ninetyToExpire[] = array('num_miembro'=>$row['num_miembro'], 'fecha'=>formatDate(substr($hoy, 8, 2), substr($hoy, 5, 2), substr($hoy, 0, 4)), 'nombre'=>(empty($row['ini']) ? $row['nombre'] : $row['nombre']." ".$row['ini']), 'paterno'=>$row['paterno'], 'materno'=>$row['materno'], 'user'=>$row['user'], 'password'=>$row['password'], 'dir1'=>(empty($row['dir2']) ? $row['dir1'] : $row['dir1']."\r\n".$row['dir2']), 'pueblo'=>$row['pueblo'], 'pais'=>$row['pais'], 'zipcode'=>(empty($row['zip4']) ? $row['zipcode'] : $row['zipcode']."-".$row['zip4']));
}
else{
$sixToExpire[] = array('num_miembro'=>$row['num_miembro'], 'fecha'=>formatDate(substr($hoy, 8, 2), substr($hoy, 5, 2), substr($hoy, 0, 4)), 'nombre'=>(empty($row['ini']) ? $row['nombre'] : $row['nombre']." ".$row['ini']), 'paterno'=>$row['paterno'], 'materno'=>$row['materno'], 'user'=>$row['user'], 'password'=>$row['password'], 'dir1'=>(empty($row['dir2']) ? $row['dir1'] : $row['dir1']."\r\n".$row['dir2']), 'pueblo'=>$row['pueblo'], 'pais'=>$row['pais'], 'zipcode'=>(empty($row['zip4']) ? $row['zipcode'] : $row['zipcode']."-".$row['zip4']));
}
unset($fvl);
}
if(!empty($expiredBeforeToday)){
$template = basename("pruebaExpirado_antes.docx");
$x = pathinfo($template);
$template_ext = $x['extension'];
if (file_exists($template)){
$TBS->LoadTemplate($template);
// Merge data
$TBS->MergeBlock('b', $expiredBeforeToday);
// delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
// Define the name of the output file
$file_name = "afvl_expirado_antes.docx";
if ($suffix==='') {
// Save
$TBS->Show(OPENTBS_FILE, $file_name);
} else {
// save as file
$file_name = str_replace('.','_'.$suffix.'.',$file_name);
$TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
}
}
}
if(!empty($expiredToday)){
$template = basename("pruebaExpirado_hoy.docx");
$x = pathinfo($template);
$template_ext = $x['extension'];
if (file_exists($template)){
$TBS->LoadTemplate($template);
// Merge data
$TBS->MergeBlock('b', $expiredToday);
// delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
// Define the name of the output file
$file_name = "afvl_expirado_hoy.docx";
if ($suffix==='') {
// Save
$TBS->Show(OPENTBS_FILE, $file_name);
} else {
// save as file
$file_name = str_replace('.','_'.$suffix.'.',$file_name);
$TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
}
}
}
if(!empty($thirtyToExpire)){
$template = basename("pruebaExpirado_treinta.docx");
$x = pathinfo($template);
$template_ext = $x['extension'];
if (file_exists($template)){
$TBS->LoadTemplate($template);
// Merge data
$TBS->MergeBlock('b', $thirtyToExpire);
// delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
// Define the name of the output file
$file_name = "afvl_treinta_para_expirar.docx";
if ($suffix==='') {
// Save
$TBS->Show(OPENTBS_FILE, $file_name);
} else {
// save as file
$file_name = str_replace('.','_'.$suffix.'.',$file_name);
$TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
}
}
}
if(!empty($ninetyToExpire)){
$template = basename("pruebaExpirado_noventa.docx");
$x = pathinfo($template);
$template_ext = $x['extension'];
if (file_exists($template)){
$TBS->LoadTemplate($template);
// Merge data
$TBS->MergeBlock('b', $ninetyToExpire);
// delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
// Define the name of the output file
$file_name = "afvl_noventa_para_expirar.docx";
if ($suffix==='') {
// Save
$TBS->Show(OPENTBS_FILE, $file_name);
} else {
// save as file
$file_name = str_replace('.','_'.$suffix.'.',$file_name);
$TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
}
}
}
if(!empty($sixToExpire)){
$template = basename("carta_renovacion.docx");
$x = pathinfo($template);
$template_ext = $x['extension'];
if (file_exists($template)){
$TBS->LoadTemplate($template);
// Merge data
$TBS->MergeBlock('b', $sixToExpire);
// delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);
// Define the name of the output file
$file_name = "afvl_seis_para_expirar.docx";
if ($suffix==='') {
// Save
$TBS->Show(OPENTBS_FILE, $file_name);
} else {
// save as file
$file_name = str_replace('.','_'.$suffix.'.',$file_name);
$TBS->Show(OPENTBS_FILE+TBS_EXIT, $file_name);
}
}
}
exit();
?>
<?php
function formatDate($day, $month, $year){
switch($month){
case "01":
$month = "enero";
break;
case "02":
$month = "febrero";
break;
case "03":
$month = "marzo";
break;
case "04":
$month = "abril";
break;
case "05":
$month = "mayo";
break;
case "06":
$month = "junio";
break;
case "07":
$month = "julio";
break;
case "08":
$month = "agosto";
break;
case "09":
$month = "septiembre";
break;
case 10:
$month = "octubre";
break;
case 11:
$month = "noviembre";
break;
case 12:
$month = "diciembre";
break;
}
return $day." de ".$month." de ".$year;
}
?>
|
|