Forum


Replies: 7   Views: 3484
Creating more than one docx results in corrupt files
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by hchandler  · 11-04-2013 - 12:13

I also tried creating one function to create the three docx's instead of one function for each - with the same results. The first docx is fine, subsequent ones are corrupt.

I copy the code below (not that it would really make that much sense to look through).

function create_docxs($post_id)
{
$docx = new CreateDocx();
$docx->addTemplate('doc_gen/position_template_subs.docx');

// get job info
$job_results = mysql_query("SELECT id, deadline_date, start_date, end_date, job_title,
short_description, long_description, system_id, approx_salary, approx_salary_range
FROM jb_jobs WHERE id = ".$post_id);
$job = mysql_fetch_array($job_results, MYSQL_ASSOC);

$docx->addTemplateVariable('TITLE', htmlspecialchars($job['job_title']));
$docx->addTemplateVariable('DEADLINE_DATE', htmlspecialchars($job['deadline_date']));
$docx->addTemplateVariable('NUM_POSITIONS', htmlspecialchars($job['num_openings']));
$docx->addTemplateVariable('START_DATE', htmlspecialchars($job['start_date']));
$docx->addTemplateVariable('END_DATE', htmlspecialchars($job['end_date']));

$req = $post_id." - ".$job['system_id'];
$docx->addTemplateVariable('REQ_NUMBER', htmlspecialchars($req));

if ($job['approx_salary_range'] > 0)
{
$docx->addTemplateVariable('MAX_RATE', "$".htmlspecialchars($job['approx_salary_range']));
}
else
{
$docx->addTemplateVariable('MAX_RATE', "$".htmlspecialchars($job['approx_salary']));
}


$docx->addTemplateVariable('short_description', htmlspecialchars($job['short_description']));
$docx->addTemplateVariable('long_description', $job['long_description'],'html');

// Load the skills
$skills_result = mysql_query("SELECT skills.skill_name AS SKILL, skills.number_years AS YRS,
skills.expertise_lv AS EXPERTISE, skills.req_des AS REQ_DES
FROM jb_skills AS skills WHERE job_id = ".$post_id);

while ($record = mysql_fetch_assoc($skills_result))
{
$record['SKILL'] = htmlspecialchars($record['SKILL']);
$skill_array[] = $record;
}

$skill_settings = array('header' => true);
$docx->addTemplateVariable($skill_array,'table', $skill_settings);

// Load the compliance
$cert_result = mysql_query("SELECT description FROM jb_compliance WHERE jb_compliance.job_id = $post_id
where description NOT IN ('Background Check','DC Resident Status',
'ITSA Template Used','No Reimbursable Expenses','Permission to Submit')");

while ($record = mysql_fetch_assoc($cert_result))
{
$record['DESCR'] = htmlspecialchars($record['description']);
$cert_array[] = $record;
}

if (empty($cert_array))
{
$record['DESCR'] = 'No compliance items.';
$cert_array[] = $record;
}
$cert_settings = array('header' => true);
$docx->addTemplateVariable($cert_array,'table', $cert_settings);

// Load the questions
$questions_result = mysql_query("SELECT question AS QUESTION FROM jb_questions WHERE job_id = ".$post_id);

while ($record = mysql_fetch_assoc($questions_result))
{
$record['QUESTION'] = htmlspecialchars($record['QUESTION']);
$question_array[] = $record;
}

if (empty($question_array))
{
$record['QUESTION'] = 'No questions.';
$question_array[] = $record;
}
$question_settings = array('header' => false);
$docx->addTemplateVariable($question_array,'table', $question_settings);

// Create file info
$position_path = "doc_gen/subs/";
$position_name = $req." ".$job['job_title']." IUI Position Requirement Sub";

$docx->createDocx($position_path.$position_name);

// Resume template
$docx->addTemplate('doc_gen/resume_template_subs.docx');

// get job info
$job_results = mysql_query("SELECT id, deadline_date, start_date, end_date, job_title,
short_description, long_description, system_id, approx_salary, approx_salary_range
FROM jb_jobs WHERE id = ".$post_id);
$job = mysql_fetch_array($job_results, MYSQL_ASSOC);

$docx->addTemplateVariable('TITLE', htmlspecialchars($job['job_title']));

$req = $post_id." - ".$job['system_id'];
$docx->addTemplateVariable('REQ', $job['system_id']);

// Load the skills
$skills_result = mysql_query("SELECT skills.skill_name AS SKILL, skills.number_years AS YRS,
skills.expertise_lv AS EXPERTISE, skills.req_des AS REQ_DES
FROM jb_skills AS skills WHERE job_id = ".$post_id);

while ($record = mysql_fetch_assoc($skills_result))
{
$record['SKILL'] = htmlspecialchars($record['SKILL']);
$skill_array[] = $record;
}

$skill_settings = array('header' => true);
$docx->addTemplateVariable($skill_array,'table', $skill_settings);

// Load the compliance
$cert_result = mysql_query("SELECT description FROM jb_compliance WHERE jb_compliance.job_id = $post_id
where description NOT IN ('Background Check','DC Resident Status',
'ITSA Template Used','No Reimbursable Expenses','Permission to Submit')");

while ($record = mysql_fetch_assoc($cert_result))
{
$record['DESCR'] = htmlspecialchars($record['description']);
$cert_array[] = $record;
}

if (empty($cert_array))
{
$record['DESCR'] = 'No compliance items.';
$cert_array[] = $record;
}
$cert_settings = array('header' => true);
$docx->addTemplateVariable($cert_array,'table', $cert_settings);

// Load the questions
$questions_result = mysql_query("SELECT question AS QUESTION FROM jb_questions WHERE job_id = ".$post_id);

while ($record = mysql_fetch_assoc($questions_result))
{
$record['QUESTION'] = htmlspecialchars($record['QUESTION']);
$question_array[] = $record;
}

$question_settings = array('header' => false);
$docx->addTemplateVariable($question_array,'table', $question_settings);

// Create file info
$position_path = "doc_gen/subs/";
$position_name = $req." ".$job['job_title']." IUI Staffing Resume Template Sub";

$docx->createDocx($position_path.$position_name);

// Exclusivity

$docx->addTemplate('doc_gen/exclusivity_template_subs.docx');

// get job info
$job_results = mysql_query("SELECT id, deadline_date, start_date, end_date, job_title,
short_description, long_description, system_id, approx_salary, approx_salary_range
FROM jb_jobs WHERE id = ".$post_id);
$job = mysql_fetch_array($job_results, MYSQL_ASSOC);

var_dump(htmlspecialchars($job['job_title']));
$docx->addTemplateVariable('TITLE', htmlspecialchars($job['job_title']));

$req = $post_id." - ".$job['system_id'];
var_dump(htmlspecialchars($req));
$docx->addTemplateVariable('REQ', htmlspecialchars($req));

// Create file info
$position_path = "doc_gen/subs/";
$position_name = $req." ".$job['job_title']." IUI Exclusivity Agreement";

$docx->createDocx($position_path.$position_name);

} // create_themall