Forum


Replies: 7   Views: 2947
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  · 19-10-2011 - 02:42

After months of looking at it off and on, I am still trying to get this software to work. I did get one patch in short order. It's extremely frustrating.

I have a very simple example where I have three functions that each creates a docx. Basically a position description, exclusivity agreement and resume template for a job posting (163 in this case). I call them in order like below:

$this->create_position_docx_subs('163');
$this->create_exclusivity_template_subs('163');
$this->create_resume_template_subs('163');

Very standard stuff - I copied one below at the bottom of this message for reference. Basically just like the examples that are provided as "documentation" except I didn't see one with multiple files.

The first docx that is created is always fine - subsequent docx's are always corrupt. It doesn't matter the order that they're called - only the first docx is fine - the next two are always corrupt (and can be automatically recovered when opened in Word, but that's not very professional). So in the example above the position docx is fine and the other two are corrupt. If I call them in this order:

$this->create_resume_template_subs('163');
$this->create_position_docx_subs('163');
$this->create_exclusivity_template_subs('163');

the resume docx is fine and the other two are corrupt (becauseI created the resume docx first). If I call the PHP script three times, each time commenting two functions out like this:

$this->create_resume_template_subs('163');
//$this->create_position_docx_subs('163');
//$this->create_exclusivity_template_subs('163');

all three will work. If I comment out each of the other two function calls in subsequent script executions each document is also created fine. It's only when I try to create more than one docx at the same time that I get corruption issues. So it's not a problem with the data I'm sending to php docx. It's a problem trying to create three different docx files in the same script.

Has anyone else experience this problem or has anyone else created more than one docx in script??

This is the example:
function create_exclusivity_template_subs($post_id)
{
$excl_docx = new CreateDocx();
$excl_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']));
$excl_docx->addTemplateVariable('TITLE', htmlspecialchars($job['job_title']));

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

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

$excl_docx->createDocx($position_path.$position_name);
$excl_docx->__destruct();
} // create_exclusivity_template_subs

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

One other note. I created a simple php script like the below that created three docx files. This DID work. However these simple examples don't really say that much because they don't reflect the real world when other things are going on in memory (like the SQL calls in the real functions).

$docx = new CreateDocx();
$docx->addTemplate('doc_gen/exclusivity_template_subs.docx');
$docx->addTemplateVariable('TITLE', "the title");
$docx->addTemplateVariable('REQ', "123 - 4567");
$docx->createDocx("doc_gen/subs/TEST_A");

$res_docx = new CreateDocx();
$res_docx->addTemplate('doc_gen/resume_template_subs.docx');
$res_docx->addTemplateVariable('TITLE', "another title");
$res_docx->addTemplateVariable('REQ', "456-2344");
$res_docx->createDocx("doc_gen/subs/TEST_B");

$docx = new CreateDocx();
$docx->addTemplate('doc_gen/position_template_subs.docx');
$docx->addTemplateVariable('TITLE', "title again");
$docx->addTemplateVariable('DEADLINE_DATE', "the date");
$docx->addTemplateVariable('NUM_POSITIONS', "23");
$docx->addTemplateVariable('START_DATE', "12-23-22");
$docx->addTemplateVariable('END_DATE', "01-31-11");
$docx->addTemplateVariable('REQ_NUMBER', "12");
$docx->addTemplateVariable('MAX_RATE', "$"."130000");
$docx->addTemplateVariable('short_description', "This is the short description");
$docx->addTemplateVariable('long_description', "This is the long one",'html');
$docx->createDocx("doc_gen/subs/TEST_C");

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

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

I did a little research with PackageExplorerer on the original file and the file repaired (163 repair ..) by MS Word. There errors between the two are the same - except the corrupted file seems to have a foot1.xml that was removed when MS Word automatically fixed the corrupted file. There were also other errors, but they were the same between the two files.

Anyone have footer issues? I don't have a header/footer in my templates.

This is what was in the corrupt file that wasn't in the fixed file:
Validating /word/footer1.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared


From the tool:
Validation of '163 repair IUI Exclusivity Agreement.docx' started at 11:58 PM

Validating /customXml/item1.xml
Validating /customXml/item2.xml
Validating /customXml/item3.xml
Validating /customXml/itemProps1.xml
Validating /customXml/itemProps2.xml
Validating /customXml/itemProps3.xml
Validating /docProps/app.xml
Validating /docProps/core.xml
Validating /word/document.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
The element 'anchor' in namespace 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing' has invalid child element 'sizeRelH' in namespace 'http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing'.
Validating /word/fontTable.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Skipping /word/media/image1.png
Validating /word/settings.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
The element 'compat' in namespace 'http://schemas.openxmlformats.org/wordprocessingml/2006/main' has invalid child element 'compatSetting' in namespace 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'. List of possible elements expected: 'useSingleBorderforContiguousCells, wpJustification, noTabHangInd, noLeading, spaceForUL, noColumnBalance, balanceSingleByteDoubleByteWidth, noExtraLineSpacing, doNotLeaveBackslashAlone, ulTrailSpace, doNotExpandShiftReturn, spacingInWholePoints, lineWrapLikeWord6, printBodyTextBeforeHeader, printColBlack, wpSpaceWidth, showBreaksInFrames, subFontBySize, suppressBottomSpacing, suppressTopSpacing, suppressSpacingAtTopOfPage, suppressTopSpacingWP, suppressSpBfAfterPgBrk, swapBordersFacingPages, convMailMergeEsc, truncateFontHeightsLikeWP6, mwSmallCaps, usePrinterMetrics, doNotSuppressParagraphBorders, wrapTrailSpaces, footnoteLayoutLikeWW8, shapeLayoutLikeWW8, alignTablesRowByRow, forgetLastTabAlignment, adjustLineHeightInTable, autoSpaceLikeWord95, noSpaceRaiseLower, doNotUseHTMLParagraphAutoSpacing, layoutRawTableWidth, layoutTableRowsApart, useWord97LineBreakRules, doNotBreakWrappedTables, doNotSnapToGridInCell, selectFldWithFirstOrLastChar, applyBreakingRules, doNotWrapTextWithPunct, doNotUseEastAsianBre....
The 'http://schemas.openxmlformats.org/officeDocument/2006/math:val' attribute is invalid - The value '0' is invalid according to its datatype 'http://schemas.openxmlformats.org/officeDocument/2006/math:ST_OnOff' - The Enumeration constraint failed.
Validating /word/styles.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Validating /word/stylesWithEffects.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Validating /word/theme/theme1.xml
Validating /word/webSettings.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Validation found errors

Validation of '163 - 270643 Enterprise Architect IUI Exclusivity Agreement.docx' started at 11:59 PM

Validating /customXml/item1.xml
Validating /customXml/item2.xml
Validating /customXml/item3.xml
Validating /customXml/itemProps1.xml
Validating /customXml/itemProps2.xml
Validating /customXml/itemProps3.xml
Validating /docProps/app.xml
Validating /docProps/core.xml
Validating /word/document.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
The element 'anchor' in namespace 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing' has invalid child element 'sizeRelH' in namespace 'http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing'.
Validating /word/fontTable.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Validating /word/footer1.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Skipping /word/media/image1.png
Validating /word/settings.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
The element 'compat' in namespace 'http://schemas.openxmlformats.org/wordprocessingml/2006/main' has invalid child element 'compatSetting' in namespace 'http://schemas.openxmlformats.org/wordprocessingml/2006/main'. List of possible elements expected: 'useSingleBorderforContiguousCells, wpJustification, noTabHangInd, noLeading, spaceForUL, noColumnBalance, balanceSingleByteDoubleByteWidth, noExtraLineSpacing, doNotLeaveBackslashAlone, ulTrailSpace, doNotExpandShiftReturn, spacingInWholePoints, lineWrapLikeWord6, printBodyTextBeforeHeader, printColBlack, wpSpaceWidth, showBreaksInFrames, subFontBySize, suppressBottomSpacing, suppressTopSpacing, suppressSpacingAtTopOfPage, suppressTopSpacingWP, suppressSpBfAfterPgBrk, swapBordersFacingPages, convMailMergeEsc, truncateFontHeightsLikeWP6, mwSmallCaps, usePrinterMetrics, doNotSuppressParagraphBorders, wrapTrailSpaces, footnoteLayoutLikeWW8, shapeLayoutLikeWW8, alignTablesRowByRow, forgetLastTabAlignment, adjustLineHeightInTable, autoSpaceLikeWord95, noSpaceRaiseLower, doNotUseHTMLParagraphAutoSpacing, layoutRawTableWidth, layoutTableRowsApart, useWord97LineBreakRules, doNotBreakWrappedTables, doNotSnapToGridInCell, selectFldWithFirstOrLastChar, applyBreakingRules, doNotWrapTextWithPunct, doNotUseEastAsianBre....
The 'http://schemas.openxmlformats.org/officeDocument/2006/math:val' attribute is invalid - The value '0' is invalid according to its datatype 'http://schemas.openxmlformats.org/officeDocument/2006/math:ST_OnOff' - The Enumeration constraint failed.
Validating /word/styles.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Validating /word/stylesWithEffects.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Validating /word/theme/theme1.xml
Validating /word/webSettings.xml
The 'http://schemas.openxmlformats.org/markup-compatibility/2006:Ignorable' attribute is not declared.
Validation found errors

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

Hello,

We're checking that issue, please contact us (http://www.phpdocx.com/contact).

Regards.

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

After spending more hours trying to recreate this error outside of my production system and without any connections to databases and such I created this script which shows the problem. The first file works - all the others are corrupted.


[code]<?php
require_once "phpdocx_pro/classes/CreateDocx.inc";

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

$job['job_title'] ='Business Analyst';
$job['deadline_date'] ='10/19/2011';
$job['num_openings']='';
$job['start_date']='11/02/2011';
$job['end_date']='09/30/2012';

$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 . " - 3433";
$docx->addTemplateVariable('REQ_NUMBER', htmlspecialchars($req));

$job['approx_salary']='51.00';
$docx->addTemplateVariable('MAX_RATE', "$".htmlspecialchars($job['approx_salary']));

$job['short_description']='Business Analyst Level 3 - 4 to 7 Years';
$job['long_description']='<br><br>Serve as the Senior Analyst on projects to gather requirements, document existing business processes, and make recommendations on how to improve existing business work flows and processes. Gather requirements using interviews, document analysis, requirements workshops, surveys, site visits, business process descriptions, use cases, scenarios, business analysis, task and workflow analysis. Critically evaluate information gathered from multiple sources, reconcile conflicts, decompose high-level information into details, abstract up from low-level information to a general understanding, and distinguish user requests from the underlying true needs. Proactively communicate and collaborate with external and internal customers to analyze information needs and functional requirements and deliver the following artifacts as needed: (Functional requirements (Business Requirements Document), iii. Use Cases, GUI, Screen and Interface designs) Utilize experience and knowledge in using enterprise-wide requirements definition and management systems and methodologies. Successfully lead and support multiple initiatives simultaneously Work independently with users to define concepts and under direction of project managers and application developers. Drive and challenge business units on their assumptions of how they will successfully execute their plans. Strong analytical and product management skills required, including a thorough understanding of how to interpret customer business needs and translate them into application and operational requirements. Excellent verbal and written communication skills and the ability to interact professionally with a diverse group, executives, managers, and subject matter experts. Serves as the conduit between the customer community (internal and external customers) and the software development team through which requirements flow. Develop requirements specifications according to standard templates, using natural language. Collaborate with developers and subject matter experts to establish the technical vision and analyze tradeoffs between usability and performance needs. Make recommendations based on best practices and industry standards Be the liaison between the business units, technology teams, and Office of Information Technology Managers.<br><br>Preference given to DC Residents and residents of the local metro area.<br>Background check required if selected.<br><br>Candidate Characteristics:<br>Possesses detailed understanding in the areas of application programming, database and system design. Understands Mainframe, Internet, Intranet, Extranet andclient/server architectures. Understands legacy and web base systems.<br><br>Work Location: DOES: 4058 Minnesota Ave NE<br>Project: Various UI Projects<br>';

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

$record['SKILL'] = 'Reporting Tools';
$record['YRS'] = '5.00';
$record['EXPERTISE'] = 'Proficient';
$record['REQ_DES'] = 'Highly desired';
$skill_array[]= $record;

$record['SKILL'] = 'C#';
$record['YRS'] = '5.00';
$record['EXPERTISE'] = 'Proficient';
$record['REQ_DES'] = 'Highly desired';
$skill_array[]= $record;

$record['SKILL'] = '.NET';
$record['YRS'] = '5.00';
$record['EXPERTISE'] = 'Proficient';
$record['REQ_DES'] = 'Highly desired';
$skill_array[]= $record;

$record['SKILL'] = 'JCL';
$record['YRS'] = '5.00';
$record['EXPERTISE'] = 'Proficient';
$record['REQ_DES'] = 'Highly desired';
$skill_array[]= $record;

$record['SKILL'] = 'Unemployment Insurance (UI) Tax and Benefits Knowledge';
$record['YRS'] = '5.00';
$record['EXPERTISE'] = 'Proficient';
$record['REQ_DES'] = 'Highly desired';
$skill_array[]= $record;

$record['SKILL'] = 'Database Design';
$record['YRS'] = '5.00';
$record['EXPERTISE'] = 'Proficient';
$record['REQ_DES'] = 'Highly desired';
$skill_array[]= $record;

$record['SKILL'] = 'SDLC';
$record['YRS'] = '5.00';
$record['EXPERTISE'] = 'Proficient';
$record['REQ_DES'] = 'Highly desired';
$skill_array[]= $record;

$record['SKILL'] = 'SQL';
$record['YRS'] = '5.00';
$record['EXPERTISE'] = 'Proficient';
$record['REQ_DES'] = 'Highly desired';
$skill_array[]= $record;

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

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

$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);
$docx->__destruct();
} // create_position_docx

function create_resume_template_subs($post_id)
{
$res_docx = new CreateDocx();
$res_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);

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

$req = $post_id." - ".$job['system_id'];
$res_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);
$res_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);
$res_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);
$res_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";

$res_docx->createDocx($position_path.$position_name);
$res_docx->__destruct();
} // create_resume_template_subs

function create_exclusivity_template_subs($post_id)
{
$excl_docx = new CreateDocx();
$excl_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);
*/

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

$req = $post_id . " - 1234";
$excl_docx->addTemplateVariable('REQ', htmlspecialchars($req));

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

$excl_docx->createDocx($position_path.$position_name);
$excl_docx->__destruct();
} // create_exclusivity_template_subs

function tst_docx(){
$application =& application();
$this->_user_status = $application->clean_cookie('status', 'basename');
$this->set_name('tst_docx');

//this can be a bool value, or one of the strings 'employer' or 'seeker'
$this->_need_login = false;

} // tst_docx

function display()
{
$this->load_page('menu');
parent::display();
}

function default_action(){

parent::default_action();

} // default_action

create_position_docx_subs('178');
create_exclusivity_template_subs('163');
create_exclusivity_template_subs('164');
create_exclusivity_template_subs('165');
//$this->create_resume_template_subs('163');



?>[/code]

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

One other thing that I just happened to notice. In another script I've just added creation of a second docx and it works in my initial tests - both docx's are fine. The only difference is that both of the docx's in this script are single page. I wonder if the phpdocx code has some issue creating multiple pages? For example, I have a table in the template that is filled with an array of values. That table sometimes flows on to the second page dependent upon how much data is in the array. Perhaps this related to the foot1.xml error message above when the packageobject tool complained.