public function export() { if ($GLOBALS['TL_CONFIG']['generator_type'] == 'LivedocX') { require_once 'libs/nusoap/nusoap.php'; if ($this->Input->get('key') != 'pdf') { return ''; } $thisID = $this->Input->get('id'); // Turn off WSDL caching ini_set('soap.wsdl_cache_enabled', 0); // SOAP WSDL endpoint define('ENDPOINT', 'https://api.livedocx.com/1.2/mailmerge.asmx?wsdl'); // Define timezone date_default_timezone_set('Europe/Berlin'); // Instantiate nuSOAP Client $soap = new SoapClient(ENDPOINT); // Set charset encoding for outgoing messages // $soap ->soap_defencoding = 'UTF-8'; $soap->LogIn(array('username' => $GLOBALS['TL_CONFIG']['livedocx_username'], 'password' => $GLOBALS['TL_CONFIG']['livedocx_password'])); // Upload template $data = file_get_contents('templates/proposal-template.docx', FILE_USE_INCLUDE_PATH); // Assign field values data to template $soap->SetLocalTemplate(array('template' => base64_encode($data), 'format' => 'docx')); $event = $this->Database->prepare("SELECT * FROM tl_pic_proposal WHERE id=?")->limit(1)->execute($thisID); if (!$event->numRows) { $this->log('Event not found', 'export_proposal_to_pdf()', TL_ERROR); header('Location: ?do=Proposals'); return; } $name = $this->Database->prepare("SELECT * FROM tl_pic_customer_company WHERE id=?")->limit(1)->execute($event->customer_company_id); $format = 'd/m/Y'; $proposal_date = $event->proposal_date; $proposal_startdate = $event->proposal_startdate; $proposal_enddate = $event->proposal_enddate; $this->proposal_date = gmdate($format, $proposal_date); $event->proposal_date = gmdate($format, $proposal_date); $event->proposal_startdate = gmdate($format, $proposal_startdate); $event->proposal_enddate = gmdate($format, $proposal_enddate); $objProposal = $this->Database->prepare("SELECT * FROM tl_pic_proposal WHERE id=?")->limit(1)->execute($thisID); $services = unserialize($objProposal->services); $fieldValues = array('company_name' => $GLOBALS['TL_CONFIG']['company_name'], 'address1' => $GLOBALS['TL_CONFIG']['company_address1'], 'address2' => $GLOBALS['TL_CONFIG']['company_address2'], 'city' => $GLOBALS['TL_CONFIG']['company_city'], 'postcode' => $GLOBALS['TL_CONFIG']['company_postcode'], 'phone' => $GLOBALS['TL_CONFIG']['company_phone'], 'firstname' => $GLOBALS['TL_CONFIG']['contact_firstname'], 'lastname' => $GLOBALS['TL_CONFIG']['contact_lastname'], 'phone' => $GLOBALS['TL_CONFIG']['contact_phone'], 'email' => $GLOBALS['TL_CONFIG']['contact_email'], 'website' => $GLOBALS['TL_CONFIG']['company_website'], 'curr' => $GLOBALS['TL_CONFIG']['company_defaultCurrency'], 'proposal_label' => $event->proposal_label, 'customer_company_name' => $name->customer_company_name, 'proposal_version' => $event->proposal_version, 'proposal_date' => $event->proposal_date, 'proposal_startdate' => $event->proposal_startdate, 'proposal_enddate' => $event->proposal_enddate, 'introduction_headline' => $event->introduction_headline, 'introduction' => $event->introduction, 'endtext_headline' => $event->endtext_headline, 'endtext' => $event->endtext); $array_size = sizeof($services); $sum_days = 0; $sum = 0; $blockFieldValues = array(); $i = 0; while ($i < $array_size) { $current_service = $this->Database->prepare("SELECT * FROM tl_pic_services WHERE id=?")->limit(1)->execute($services[$i]['service']); $sum_days = $sum_days + $services[$i]['days_spent']; $sum = $sum + $services[$i]['price']; if ($i >= 0 && $i <= 5) { $page = 5; } if ($i >= 6 && $i <= 10) { $page = 6; } if ($i >= 11 && $i <= 15) { $page = 7; } $id = (string) $i + 1; $blockFieldValues[$i]['service_name_' . (string) $i] = $current_service->service_name; $blockFieldValues[$i]['service_description_' . (string) $i] = $current_service->service_description; $blockFieldValues[$i]['days_spent_' . (string) $i] = $services[$i]['days_spent']; $blockFieldValues[$i]['price_' . (string) $i] = $GLOBALS['TL_CONFIG']['company_defaultCurrency'] . $services[$i]['price']; $blockFieldValues[$i]['id_' . (string) $i] = "2." . $id . " "; $blockFieldValues[$i]['p_' . (string) $i] = $page; $i++; } $array_size = sizeof($services); $sum_days = 0; $sum = 0; $blockFieldValues2 = array(); $i = 0; while ($i < $array_size) { $current_service = $this->Database->prepare("SELECT * FROM tl_pic_services WHERE id=?")->limit(1)->execute($services[$i]['service']); $sum_days = $sum_days + $services[$i]['days_spent']; $sum = $sum + $services[$i]['price']; if ($i >= 0 && $i <= 5) { $page = 5; } if ($i >= 6 && $i <= 10) { $page = 6; } if ($i >= 11 && $i <= 15) { $page = 7; } $id = (string) $i + 1; $blockFieldValues2[$i]['service_name_' . (string) $i] = $current_service->service_name; $blockFieldValues2[$i]['service_description_' . (string) $i] = $current_service->service_description; $blockFieldValues2[$i]['days_spent_' . (string) $i] = $services[$i]['days_spent']; $blockFieldValues2[$i]['price_' . (string) $i] = $GLOBALS['TL_CONFIG']['company_defaultCurrency'] . $services[$i]['price']; $blockFieldValues2[$i]['id_' . (string) $i] = "2." . $id . " "; $blockFieldValues2[$i]['p_' . (string) $i] = $page; $i++; } $array_size = sizeof($services); $sum_days = 0; $sum = 0; $blockFieldValues3 = array(); $i = 0; while ($i < $array_size) { $current_service = $this->Database->prepare("SELECT * FROM tl_pic_services WHERE id=?")->limit(1)->execute($services[$i]['service']); $sum_days = $sum_days + $services[$i]['days_spent']; $sum = $sum + $services[$i]['price']; if ($i >= 0 && $i <= 5) { $page = 5; } if ($i >= 6 && $i <= 10) { $page = 6; } if ($i >= 11 && $i <= 15) { $page = 7; } $id = (string) $i + 1; $blockFieldValues3[$i]['service_name_' . (string) $i] = $current_service->service_name; $blockFieldValues3[$i]['service_description_' . (string) $i] = $current_service->service_description; $blockFieldValues3[$i]['days_spent_' . (string) $i] = $services[$i]['days_spent']; $blockFieldValues3[$i]['price_' . (string) $i] = $GLOBALS['TL_CONFIG']['company_defaultCurrency'] . $services[$i]['price']; $blockFieldValues3[$i]['id_' . (string) $i] = "2." . $id . " "; $blockFieldValues3[$i]['p_' . (string) $i] = $page; $i++; } $avp = 6; $last = 7; if ($array_size > 6) { $avp = 7; $last = 8; } if ($array_size > 11) { $avp = 8; $last = 9; } $custom_fields = unserialize($objProposal->custom_fields); $custom_fields_size = sizeof($custom_fields); for ($i = 0; $i < $custom_fields_size; $i++) { $fieldValues = $fieldValues + array($custom_fields[$i]['field_name'] => $custom_fields[$i]['value']); } $fieldValues = $fieldValues + array('sum' => $sum, 'sum_days' => $sum_days, 'avp' => $avp, 'last' => $last); $result = $soap->SetFieldValues(array('fieldValues' => $this->nuSoap_assocArrayToArrayOfArrayOfString($fieldValues))); $soap->SetBlockFieldValues(array('blockName' => 'content', 'blockFieldValues' => $this->nuSoap_multiAssocArrayToArrayOfArrayOfString($blockFieldValues))); $soap->SetBlockFieldValues(array('blockName' => 'content_menu', 'blockFieldValues' => $this->nuSoap_multiAssocArrayToArrayOfArrayOfString($blockFieldValues2))); $soap->SetBlockFieldValues(array('blockName' => 'content_array', 'blockFieldValues' => $this->nuSoap_multiAssocArrayToArrayOfArrayOfString($blockFieldValues3))); // Build the document $soap->CreateDocument(); // Get document as PDF $result = $soap->RetrieveDocument(array('format' => 'pdf')); $data = $result->RetrieveDocumentResult; $soap->LogOut(); unset($soap); header('Content-Type: application/x-download'); header('Content-Disposition: attachment; filename="' . $event->proposal_label . '.pdf"'); header('Cache-Control: private, max-age=0, must-revalidate'); header('Pragma: public'); echo base64_decode($data); return; } else { echo 'LivedocX only is available at the moment !'; } }
function resman_livedocx_create_documents() { global $wpdb; $fieldValues = array(); $username = get_option('resman_livedocx_username'); $password = get_option('resman_livedocx_password'); $dateformat = get_option('resman_date_format'); if ($dateformat == '') { $dateformat = 'Y-m-d'; } $ldx = new SoapClient(LIVEDOCX_URL, array('user_agent' => 'Wordpress-Resume-Manager/' . RESMAN_VERSION . ' http://pento.net/projects/wordpress-resume-mananger-plugin/')); $ldx->LogIn(array('username' => $username, 'password' => $password)); $template = file_get_contents(WP_PLUGIN_DIR . '/' . RESMAN_FOLDER . '/template/classic.docx'); $ldx->SetLocalTemplate(array('template' => base64_encode($template), 'format' => 'docx')); // PERSONAL $sql = 'SELECT d.value AS value, f.name AS name FROM ' . $wpdb->prefix . 'resman_data AS d LEFT JOIN ' . $wpdb->prefix . 'resman_fields AS f on f.id = d.fieldid WHERE f.section="personal";'; $data = $wpdb->get_results($sql, ARRAY_A); $nationality = array(); $fieldValues['personal-count'] = 0; foreach ($data as $item) { switch ($item['name']) { case 'nationality': $nationality[] = $item['value']; break; default: $fieldValues['personal-' . $item['name']] = $item['value']; } $fieldValues['personal-count']++; } if (count($nationality)) { $fieldValues['personal-nationality'] = implode(', ', $nationality); } // GENERAL $sql = 'SELECT d.value AS value, f.name AS name FROM ' . $wpdb->prefix . 'resman_data AS d LEFT JOIN ' . $wpdb->prefix . 'resman_fields AS f on f.id = d.fieldid WHERE f.section="general";'; $data = $wpdb->get_results($sql, ARRAY_A); $fieldValues['general-count'] = 0; foreach ($data as $item) { $fieldValues['general-' . $item['name']] = $item['value']; $fieldValues['general-count']++; } // EXPERIENCE $sql = 'SELECT d.value AS value, f.name AS name, d.repeatgroup_count AS repeatgroup FROM ' . $wpdb->prefix . 'resman_data AS d LEFT JOIN ' . $wpdb->prefix . 'resman_fields AS f on f.id = d.fieldid WHERE f.section="experience" ORDER BY d.repeatgroup_count;'; $data = $wpdb->get_results($sql, ARRAY_A); $experience = array(); $fieldValues['experience-count'] = 0; foreach ($data as $item) { switch ($item['name']) { case 'start': case 'end': $experience[$item['repeatgroup'] - 1]['experience-' . $item['name']] = date($dateformat, strtotime($item['value'])); break; case 'abstract': $experience[$item['repeatgroup'] - 1]['experience-' . $item['name']] = resman_livedocx_format_abstract($item['value']); break; default: $experience[$item['repeatgroup'] - 1]['experience-' . $item['name']] = $item['value']; } } $fields = array('start', 'end', 'title', 'abstract', 'name', 'address', 'sector'); $expBlock = array(); foreach ($experience as $key => $exp) { if (!isset($experience[$key]['experience-start'])) { $experience[$key]['experience-start'] = __('Present', 'resman'); } if (!isset($experience[$key]['experience-end'])) { $experience[$key]['experience-end'] = __('Present', 'resman'); } foreach ($fields as $field) { if (!isset($experience[$key]['experience-' . $field])) { $experience[$key]['experience-' . $field] = ''; } $expBlock[$fieldValues['experience-count']]['experience-' . $field] = $experience[$key]['experience-' . $field]; } $fieldValues['experience-count']++; } $ldx->SetBlockFieldValues(array('blockName' => 'experience', 'blockFieldValues' => resman_multiAssocArrayToArrayOfArrayOfString($expBlock))); // EDUCATION $sql = 'SELECT d.value AS value, f.name AS name, d.repeatgroup_count AS repeatgroup FROM ' . $wpdb->prefix . 'resman_data AS d LEFT JOIN ' . $wpdb->prefix . 'resman_fields AS f on f.id = d.fieldid WHERE f.section="education" ORDER BY d.repeatgroup_count;'; $data = $wpdb->get_results($sql, ARRAY_A); $education = array(); $fieldValues['education-count'] = 0; foreach ($data as $item) { switch ($item['name']) { case 'start': case 'end': $education[$item['repeatgroup'] - 1]['education-' . $item['name']] = date($dateformat, strtotime($item['value'])); break; case 'abstract': $education[$item['repeatgroup'] - 1]['education-' . $item['name']] = resman_livedocx_format_abstract($item['value']); break; default: $education[$item['repeatgroup'] - 1]['education-' . $item['name']] = $item['value']; } } $fields = array('start', 'end', 'title', 'abstract', 'name', 'address', 'field'); $eduBlock = array(); foreach ($education as $key => $exp) { if (!isset($education[$key]['education-start'])) { $education[$key]['education-start'] = __('Present', 'resman'); } if (!isset($education[$key]['education-end'])) { $education[$key]['education-end'] = __('Present', 'resman'); } foreach ($fields as $field) { if (!isset($education[$key]['education-' . $field])) { $education[$key]['education-' . $field] = ''; } $eduBlock[$fieldValues['education-count']]['education-' . $field] = $education[$key]['education-' . $field]; } $fieldValues['education-count']++; } $ldx->SetBlockFieldValues(array('blockName' => 'education', 'blockFieldValues' => resman_multiAssocArrayToArrayOfArrayOfString($eduBlock))); // SKILLS $sql = 'SELECT d.value AS value, f.name AS name FROM ' . $wpdb->prefix . 'resman_data AS d LEFT JOIN ' . $wpdb->prefix . 'resman_fields AS f on f.id = d.fieldid WHERE f.section="skills";'; $data = $wpdb->get_results($sql, ARRAY_A); $fieldValues['skills-count'] = 0; foreach ($data as $item) { $fieldValues['skills-' . $item['name']] = resman_livedocx_format_abstract($item['value']); $fieldValues['skills-count']++; } $ldx->SetFieldValues(array('fieldValues' => resman_assocArrayToArrayOfArrayOfString($fieldValues))); $ldx->CreateDocument(); resman_livedocx_write_document($ldx, 'html'); $doctypes = array('txt', 'pdf', 'doc', 'docx', 'rtf'); foreach ($doctypes as $doc) { if (get_option('resman_output_' . $doc)) { resman_livedocx_write_document($ldx, $doc); } } $ldx->LogOut(); unset($ldx); }