Forum


Replies: 7   Views: 3266
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

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]