Exemplo n.º 1
0
 public static function render_instance(BlockInstance $instance, $editing = false)
 {
     // Check if XSLT extension is loaded properly, because we will need it...
     // The XSL extension implements the XSL standard, performing XSLT transformations using the libxslt library.
     $xslext = extension_loaded('xsl');
     if (!$xslext) {
         $missingextensions = array();
         !$xslext && ($missingextensions[] = 'xsl');
         $errormsg = '<p>' . get_string('europassextensionmissing', 'artefact.europass') . '</p>';
         $errormsg .= '<ul>';
         foreach ($missingextensions as $extension) {
             $errormsg .= '<li><a href="http://www.php.net/' . $extension . '">' . $extension . '</a></li>';
         }
         $errormsg .= '</ul>';
         return $errormsg;
         exit;
     }
     require_once get_config('docroot') . 'artefact/lib.php';
     $smarty = smarty_core();
     $configdata = $instance->get('configdata');
     $configdata['viewid'] = $instance->get('view');
     // Get data about the resume field in this blockinstance
     if (!empty($configdata['artefactid'])) {
         $europassfield = $instance->get_artefact_instance($configdata['artefactid']);
         if ($europassfield->get('artefacttype') != 'application') {
             $rendered = $europassfield->render_self($configdata);
             $result = $rendered['html'];
             if (!empty($rendered['javascript'])) {
                 $result .= '<script type="text/javascript">' . $rendered['javascript'] . '</script>';
             }
         } else {
             require_once get_config('docroot') . 'artefact/europass/lib/locale.php';
             $personalinformation = null;
             try {
                 $personalinformation = artefact_instance_from_type('personalinformation');
             } catch (Exception $e) {
             }
             if (!empty($personalinformation)) {
                 $gender = $personalinformation->get_composite('gender');
             } else {
                 $gender = null;
             }
             $occupation = get_occupation($europassfield->get('description'), get_config('lang'), $gender);
             $result = $occupation['label'];
         }
         return $result;
     }
     return '';
 }
Exemplo n.º 2
0
function generate_xr_projects($projects, $parameters)
{
    $spam_mode = $parameters['spam_mode'];
    $xr_label = $parameters['xr_label'];
    $xr_tpl = $parameters['xr_tpl'];
    //$content = preg_replace("/\[BANER\-$W\-$H\]/",get_baner($W,$H),$content,1);
    $tpl_name = $xr_tpl['tpl_name'];
    $tpl_content = $xr_tpl['tpl_content'];
    $id_mail_type = $xr_tpl['id_mail_type'];
    $id_hp_links = $xr_tpl['id_hp_links'];
    $id_sign_links = $xr_tpl['id_sign_links'];
    $id_post_links = $xr_tpl['id_post_links'];
    $lang = $xr_tpl['lang'];
    $rand_text = $xr_tpl['rand_text'];
    //echo get_nick_mask("NICK_MASK-3-8") ;
    //exit;
    foreach ($projects as $project) {
        //print_r($project);
        $tpl = $tpl_content;
        $project_names = get_project_names();
        //$tpl = preg_replace("/\[NICK\_MASK\-$X\-$Y\]/",get_nick_mask("NICK_MASK-$X-$Y"),$tpl,1);
        //$tpl = preg_replace('/\[NICK_MASK\-(\d+)\-(\d+)\]/',get_nick_mask("NICK_MASK-$1-$2"),$tpl);
        //$tpl = str_replace('NICK_MASK',get_nick_mask(),$tpl);
        $HOME_RAND_URL_VARS = get_home_rand_url_vars($id_hp_links, $project);
        $NICK_MASK = get_nick_mask();
        $CITY = get_city();
        $city = $CITY['city'];
        $country = $CITY['country'];
        $occupation = get_occupation($lang);
        $interest = get_interest($lang);
        $genders = get_gender();
        $gender = $genders['gender'];
        $firstname = ucfirst(strtolower($genders['firstname']));
        echo $gender . "\n" . $firstname;
        exit;
        //разделение по типам проектов
        # Href:
        $href_tpl = $tpl;
        $href_project_name = $project_names['Href'];
    }
}
function generate_europasscv_xml($userid, $showHTML = false, $locale = 'en_GB', $internaldateformat = 'dmy11', $externaldateformat = '/numeric/long', $photograph = null)
{
    // ================================
    // Load values from Mahara database
    // ================================
    // load user's existing contact information
    $element_list = array('firstname' => 'text', 'lastname' => 'text', 'email' => 'emaillist', 'address' => 'textarea', 'city' => 'text', 'country' => 'select', 'homenumber' => 'text', 'mobilenumber' => 'text', 'faxnumber' => 'text', 'officialwebsite' => 'text');
    $contactinfo = array('firstname' => null, 'lastname' => null, 'email' => null, 'address' => null, 'city' => null, 'country' => null, 'homenumber' => null, 'mobilenumber' => null, 'faxnumber' => null, 'officialwebsite' => null);
    $contactinfo_data = get_records_select_array('artefact', "owner=? AND artefacttype IN (" . join(",", array_map(create_function('$a', 'return db_quote($a);'), array_keys($element_list))) . ")", array($userid));
    if ($contactinfo_data) {
        foreach ($contactinfo_data as $field) {
            $contactinfo[$field->artefacttype] = $field->title;
        }
    }
    // load user's existing demographics information
    $demographics = null;
    try {
        $demographics = artefact_instance_from_type('personalinformation', $userid);
    } catch (Exception $e) {
    }
    !empty($demographics) ? $citizenship = $demographics->get_composite('citizenship') : ($citizenship = null);
    if (strlen($citizenship) == 2 or in_array($citizenship[2], array(',', ';', '/', '-'))) {
        $nationalities_list = explode(",", str_replace(" ", "", $demographics->get_composite('citizenship')));
    } else {
        $nationalities_list = array();
        // no nationality OR nationality value(s) not equals ISO 3166-1-alpha-2 code(s)
    }
    // user's application for desired employment / occupational field
    $application = null;
    try {
        $application = artefact_instance_from_type('application', $userid);
    } catch (Exception $e) {
    }
    if ($application == array()) {
        $application_data = null;
    } else {
        if ($application->get('description') == null) {
            $application_data = null;
        } else {
            //log_debug($demographics);
            if ($demographics == null) {
                $gender = null;
            } else {
                $gender = $demographics->get_composite('gender');
            }
            $application_data = get_occupation($application->get('description'), $locale, $gender);
        }
    }
    // load user's existing workexperience
    $artefact_id = get_field('artefact', 'id', 'artefacttype', 'employmenthistory', 'owner', $userid);
    if ($artefact_id !== false) {
        $workexperience_list = get_records_select_array('artefact_resume_employmenthistory', "artefact=?", array($artefact_id));
    } else {
        $workexperience_list = array();
    }
    // load user's existing education
    $artefact_id = get_field('artefact', 'id', 'artefacttype', 'educationhistory', 'owner', $userid);
    if ($artefact_id !== false) {
        $education_list = get_records_select_array('artefact_resume_educationhistory', "artefact=?", array($artefact_id));
    } else {
        $education_list = array();
    }
    //$education_entries = count($education_list);
    // load user's existing mother tongue(s) and foreign language(s)
    $artefact_id = get_field('artefact', 'id', 'artefacttype', 'mothertongue', 'owner', $userid);
    if ($artefact_id !== false) {
        $mothertongue_list = get_records_select_array('artefact_europass_mothertongue', "artefact=?", array($artefact_id));
    } else {
        $mothertongue_list = array();
    }
    $artefact_id = get_field('artefact', 'id', 'artefacttype', 'otherlanguage', 'owner', $userid);
    if ($artefact_id !== false) {
        $otherlanguage_list = get_records_select_array('artefact_europass_otherlanguage', "artefact=?", array($artefact_id));
    } else {
        $otherlanguage_list = array();
    }
    // load user's existing skills and misc data
    $skills = array('socialskill' => null, 'organisationalskill' => null, 'technicalskill' => null, 'computerskill' => null, 'artisticskill' => null, 'otherskill' => null);
    $drivinglicence = null;
    $misc = array('additionalinfo' => null, 'annexes' => null);
    try {
        $skills['socialskill'] = artefact_instance_from_type('socialskill', $userid)->get('description');
    } catch (Exception $e) {
    }
    try {
        $skills['organisationalskill'] = artefact_instance_from_type('organisationalskill', $userid)->get('description');
    } catch (Exception $e) {
    }
    try {
        $skills['technicalskill'] = artefact_instance_from_type('technicalskill', $userid)->get('description');
    } catch (Exception $e) {
    }
    try {
        $skills['computerskill'] = artefact_instance_from_type('computerskill', $userid)->get('description');
    } catch (Exception $e) {
    }
    try {
        $skills['artisticskill'] = artefact_instance_from_type('artisticskill', $userid)->get('description');
    } catch (Exception $e) {
    }
    try {
        $skills['otherskill'] = artefact_instance_from_type('otherskill', $userid)->get('description');
    } catch (Exception $e) {
    }
    try {
        $drivinglicence = unserialize(artefact_instance_from_type('drivinglicence', $userid)->get('description'));
    } catch (Exception $e) {
    }
    try {
        $misc['additionalinfo'] = artefact_instance_from_type('additionalinfo', $userid)->get('description');
    } catch (Exception $e) {
    }
    try {
        $misc['annexes'] = artefact_instance_from_type('annexes', $userid)->get('description');
    } catch (Exception $e) {
    }
    // ======================
    // Dinamically create XML
    // ======================
    $xmlDoc = new DOMDocument('1.0', 'UTF-8');
    // We want a nice output
    //$xmlDoc->formatOutput = true;
    //$xmlDoc->preserveWhitespace = false;
    $styleSheet = $xmlDoc->createProcessingInstruction('xml-stylesheet', 'href="http://europass.cedefop.europa.eu/xml/cv_' . $locale . '.xsl" type="text/xsl"');
    $xmlDoc->appendChild($styleSheet);
    $rootElement = $xmlDoc->createElement('europass:learnerinfo');
    $rootNode = $xmlDoc->appendChild($rootElement);
    $rootNode->setAttribute('locale', $locale);
    $rootNode->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
    $rootNode->setAttribute('xmlns:europass', 'http://europass.cedefop.europa.eu/Europass/V2.0');
    $rootNode->setAttribute('xsi:schemaLocation', 'http://europass.cedefop.europa.eu/Europass/V2.0 http://europass.cedefop.europa.eu/xml/EuropassSchema_V2.0.xsd');
    $children = array('docinfo', 'prefs', 'identification', 'application', 'workexperiencelist', 'educationlist', 'languagelist', 'skilllist', 'misclist');
    foreach ($children as $child) {
        $childRoot = $xmlDoc->getElementsByTagName('europass:learnerinfo')->item(0);
        $childElement = $xmlDoc->createElement($child);
        $childElement->nodeValue = null;
        $childRoot->appendChild($childElement);
    }
    // =======================
    // Dinamically set docinfo
    // =======================
    // Dinamically set issuedate
    $childRoot = $xmlDoc->getElementsByTagName('docinfo')->item(0);
    $childElement = $xmlDoc->createElement('issuedate');
    $childElement->nodeValue = date('Y-m-d\\TH:i:sP');
    $childRoot->appendChild($childElement);
    // Dinamically set xsdversion
    $childRoot = $xmlDoc->getElementsByTagName('docinfo')->item(0);
    $childElement = $xmlDoc->createElement('xsdversion');
    $childElement->nodeValue = 'V2.0';
    $childRoot->appendChild($childElement);
    // Dinamically set comment
    $childRoot = $xmlDoc->getElementsByTagName('docinfo')->item(0);
    $childElement = $xmlDoc->createElement('comment');
    $childElement->nodeValue = 'Automatically generated Europass CV from Mahara e-portfolio data';
    $childRoot->appendChild($childElement);
    // ========================================
    // Dinamically set prefs and identification
    // ========================================
    // Dinamically set first and last name
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step1.lastName');
    $childElement->setAttribute('before', 'step1.firstName');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    $childRoot = $xmlDoc->getElementsByTagName('identification')->item(0);
    $childElement = $xmlDoc->createElement('firstname');
    $childElement->nodeValue = valid_xml_string($contactinfo['firstname']);
    $childRoot->appendChild($childElement);
    $childElement = $xmlDoc->createElement('lastname');
    $childElement->nodeValue = valid_xml_string($contactinfo['lastname']);
    $childRoot->appendChild($childElement);
    // ---------------------------
    // Dinamically set contactinfo
    // ---------------------------
    $childRoot = $xmlDoc->getElementsByTagName('identification')->item(0);
    $childElement = $xmlDoc->createElement('contactinfo');
    $childRoot->appendChild($childElement);
    // Dinamically set address
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step1.addressInfo');
    $childElement->setAttribute('keep', 'true');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    $childRoot = $xmlDoc->getElementsByTagName('contactinfo')->item(0);
    $childElement = $xmlDoc->createElement('address');
    $childRoot->appendChild($childElement);
    // Dinamically set addressLine, municipality, postalCode
    $childRoot = $xmlDoc->getElementsByTagName('address')->item(0);
    $childElement = $xmlDoc->createElement('addressLine');
    $childElement->nodeValue = valid_xml_string($contactinfo['address']);
    $childRoot->appendChild($childElement);
    $childElement = $xmlDoc->createElement('municipality');
    $childElement->nodeValue = valid_xml_string($contactinfo['city']);
    $childRoot->appendChild($childElement);
    //$childElement = $xmlDoc->createElement('postalCode');
    //$childElement->nodeValue = valid_xml_string($postalCode);
    //$childRoot->appendChild($childElement);
    $childElement = $xmlDoc->createElement('country');
    $childRoot->appendChild($childElement);
    // Dinamically set country
    $childRoot = $xmlDoc->getElementsByTagName('country')->item(0);
    $childElement = $xmlDoc->createElement('code');
    $childElement->nodeValue = strtoupper($contactinfo['country']);
    $childRoot->appendChild($childElement);
    $childElement = $xmlDoc->createElement('label');
    $childElement->nodeValue = get_string_from_file('country.' . $contactinfo['country'], get_config('docroot') . 'artefact/europass/lang/' . get_lang_from_locale($locale) . '/artefact.europass.php');
    $childRoot->appendChild($childElement);
    // Dinamically set telephone, fax, mobile, email and web page
    $contactinfo = array('telephone' => $contactinfo['homenumber'], 'fax' => $contactinfo['faxnumber'], 'mobile' => $contactinfo['mobilenumber'], 'email' => $contactinfo['email']);
    foreach ($contactinfo as $field => $value) {
        $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
        $childElement = $xmlDoc->createElement('field');
        $childElement->setAttribute('name', 'step1.' . $field);
        $childElement->setAttribute('keep', $value == null ? 'false' : 'true');
        $childElement->nodeValue = null;
        $childRoot->appendChild($childElement);
        $childRoot = $xmlDoc->getElementsByTagName('contactinfo')->item(0);
        $childElement = $xmlDoc->createElement($field);
        $childElement->nodeValue = valid_xml_string($value);
        $childRoot->appendChild($childElement);
    }
    // ----------------------------
    // Dinamically set demographics
    // ----------------------------
    $childRoot = $xmlDoc->getElementsByTagName('identification')->item(0);
    $childElement = $xmlDoc->createElement('demographics');
    $childRoot->appendChild($childElement);
    // Dinamically set birthDate and gender
    if ($demographics != null) {
        $demographics = array('birthDate' => strftime('%Y-%m-%d', $demographics->get_composite('dateofbirth') + 3600), 'gender' => $demographics->get_composite('gender') == 'male' ? 'M' : 'F');
        foreach ($demographics as $field => $value) {
            $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step1.' . $field);
            $childElement->setAttribute('keep', $value == null ? 'false' : 'true');
            if ($field == 'birthDate') {
                $childElement->setAttribute('format', $externaldateformat);
            }
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            $childRoot = $xmlDoc->getElementsByTagName('demographics')->item(0);
            $childElement = $xmlDoc->createElement(strtolower($field));
            // strtolower - to convert birthDate to birthdate!
            $childElement->nodeValue = valid_xml_string($value);
            $childRoot->appendChild($childElement);
        }
    }
    // Dinamically set nationality or nationalities
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step1.nationality');
    $childElement->setAttribute('keep', $nationalities_list == array() ? 'false' : 'true');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    $n = 0;
    foreach ($nationalities_list as $nationality) {
        // Dinamically set each nationality
        $childRoot = $xmlDoc->getElementsByTagName('demographics')->item(0);
        $childElement = $xmlDoc->createElement('nationality');
        $childRoot->appendChild($childElement);
        $children = array('code', 'label');
        foreach ($children as $child) {
            $childRoot = $xmlDoc->getElementsByTagName('nationality')->item($n);
            $childElement = $xmlDoc->createElement($child);
            if ($child == 'code') {
                $childElement->nodeValue = strtoupper($nationality);
            }
            if ($child == 'label') {
                $childElement->nodeValue = get_string_from_file('nationality.' . $nationality, get_config('docroot') . 'artefact/europass/lang/' . get_lang_from_locale($locale) . '/artefact.europass.php');
            }
            $childRoot->appendChild($childElement);
        }
        $n++;
    }
    // Dinamically set photograph
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step1.photo');
    $childElement->setAttribute('keep', $photograph == null ? 'false' : 'true');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    $childRoot = $xmlDoc->getElementsByTagName('identification')->item(0);
    $childElement = $xmlDoc->createElement('photo');
    $childElement->setAttribute('type', 'JPEG');
    $childElement->nodeValue = $photograph;
    $childRoot->appendChild($childElement);
    // =====================================
    // Dinamically set prefs and application
    // =====================================
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step1.application.label');
    $childElement->setAttribute('keep', $application_data == null ? 'false' : 'true');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    $childRoot = $xmlDoc->getElementsByTagName('application')->item(0);
    $childElement = $xmlDoc->createElement('code');
    $childElement->nodeValue = valid_xml_string($application_data['code']);
    $childRoot->appendChild($childElement);
    $childElement = $xmlDoc->createElement('label');
    $childElement->nodeValue = valid_xml_string($application_data['label']);
    $childRoot->appendChild($childElement);
    // =============================================
    // Dinamically set prefs and workexperience list
    // =============================================
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step3List');
    $childElement->setAttribute('keep', 'true');
    $childElement->setAttribute('before', 'step4List');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    // -----------------------------------
    // Dinamically set each workexperience
    // -----------------------------------
    $i = 0;
    if (!empty($workexperience_list)) {
        foreach ($workexperience_list as $workexperience) {
            $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
            // Set workexperience period
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step3List[' . $i . '].period');
            $childElement->setAttribute('format', $externaldateformat);
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set workexperience position
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step3List[' . $i . '].position.label');
            $childElement->setAttribute('keep', $workexperience->jobtitle == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set workexperience activites
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step3List[' . $i . '].activities');
            $childElement->setAttribute('keep', $workexperience->positiondescription == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set workexperience company name
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step3List[' . $i . '].company.name');
            $childElement->setAttribute('keep', $workexperience->employer == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set workexperience company address
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step3List[' . $i . '].company.addressInfo');
            $childElement->setAttribute('keep', $workexperience->employeraddress == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set workexperience company sector - FALSE (because we do not have this data in Mahara)!
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step3List[' . $i . '].company.sector.label');
            $childElement->setAttribute('keep', 'false');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Dinamically set data for each workexperience
            $childRoot = $xmlDoc->getElementsByTagName('workexperiencelist')->item(0);
            $childElement = $xmlDoc->createElement('workexperience');
            $childRoot->appendChild($childElement);
            $children = array('period', 'position', 'activities', 'employer');
            foreach ($children as $child) {
                $childRoot = $xmlDoc->getElementsByTagName('workexperience')->item($i);
                $childElement = $xmlDoc->createElement($child);
                if ($child == 'activities') {
                    $childElement->nodeValue = $showHTML ? replacehtmlchars(nl2br($workexperience->positiondescription)) : valid_xml_string($workexperience->positiondescription);
                }
                //$childElement->nodeValue = null;
                $childRoot->appendChild($childElement);
            }
            // workexperience - period
            $parentRoot = $xmlDoc->getElementsByTagName('workexperience')->item($i);
            $childRoot = $parentRoot->firstChild;
            $childElement = $xmlDoc->createElement('from');
            $childRoot->appendChild($childElement);
            $grandchildRoot = $childRoot->firstChild;
            if ($workexperience->startdate != null) {
                $workstartdate = europass_date($workexperience->startdate, $internaldateformat);
                if ($workstartdate['year'] != '') {
                    $grandchildElement = $xmlDoc->createElement('year');
                    $grandchildElement->nodeValue = $workstartdate['year'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
                if ($workstartdate['month'] != '--00') {
                    $grandchildElement = $xmlDoc->createElement('month');
                    $grandchildElement->nodeValue = $workstartdate['month'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
                if ($workstartdate['day'] != '---00') {
                    $grandchildElement = $xmlDoc->createElement('day');
                    $grandchildElement->nodeValue = $workstartdate['day'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
            }
            $childElement = $xmlDoc->createElement('to');
            $childRoot->appendChild($childElement);
            $grandchildRoot = $childRoot->firstChild->nextSibling;
            if ($workexperience->enddate != null) {
                $workenddate = europass_date($workexperience->enddate, $internaldateformat);
                if ($workenddate['year'] != '') {
                    $grandchildElement = $xmlDoc->createElement('year');
                    $grandchildElement->nodeValue = $workenddate['year'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
                if ($workenddate['month'] != '--00') {
                    $grandchildElement = $xmlDoc->createElement('month');
                    $grandchildElement->nodeValue = $workenddate['month'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
                if ($workenddate['day'] != '---00') {
                    $grandchildElement = $xmlDoc->createElement('day');
                    $grandchildElement->nodeValue = $workenddate['day'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
            }
            // position - label
            $childRoot = $xmlDoc->getElementsByTagName('position')->item($i);
            $childElement = $xmlDoc->createElement('label');
            $childElement->nodeValue = valid_xml_string($workexperience->jobtitle);
            $childRoot->appendChild($childElement);
            // employer
            $childRoot = $xmlDoc->getElementsByTagName('employer')->item($i);
            $childElement = $xmlDoc->createElement('name');
            $childElement->nodeValue = valid_xml_string($workexperience->employer);
            $childRoot->appendChild($childElement);
            $childElement = $xmlDoc->createElement('address');
            $childRoot->appendChild($childElement);
            $childRoot = $xmlDoc->getElementsByTagName('address')->item($i + 1);
            // $i+1 because, we already have one address element!
            $childElement = $xmlDoc->createElement('addressLine');
            $childElement->nodeValue = valid_xml_string($workexperience->employeraddress);
            $childRoot->appendChild($childElement);
            // create empty node for company sector
            $childRoot = $xmlDoc->getElementsByTagName('employer')->item($i);
            $childElement = $xmlDoc->createElement('sector');
            $childRoot->appendChild($childElement);
            $i++;
        }
    }
    // ========================================
    // Dinamically set prefs and education list
    // ========================================
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step4List');
    $childElement->setAttribute('keep', 'true');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    // ------------------------------
    // Dinamically set each education
    // ------------------------------
    $j = 0;
    if (!empty($education_list)) {
        foreach ($education_list as $education) {
            $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
            // Set education period
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step4List[' . $j . '].period');
            $childElement->setAttribute('format', $externaldateformat);
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set education title
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step4List[' . $j . '].title');
            $childElement->setAttribute('keep', $education->qualname == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set education skills
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step4List[' . $j . '].skills');
            $childElement->setAttribute('keep', $education->qualdescription == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set education institution name
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step4List[' . $j . '].educationalOrg.name');
            $childElement->setAttribute('keep', $education->institution == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set education institution address
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step4List[' . $j . '].educationalOrg.addressInfo');
            $childElement->setAttribute('keep', $education->institutionaddress == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Set education level
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step4List[' . $j . '].level.label');
            $childElement->setAttribute('keep', $education->qualtype == null ? 'false' : 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            // Dinamically set data for each education
            $childRoot = $xmlDoc->getElementsByTagName('educationlist')->item(0);
            $childElement = $xmlDoc->createElement('education');
            $childRoot->appendChild($childElement);
            $children = array('period', 'title', 'skills', 'organisation', 'level', 'educationalfield');
            foreach ($children as $child) {
                $childRoot = $xmlDoc->getElementsByTagName('education')->item($j);
                $childElement = $xmlDoc->createElement($child);
                if ($child == 'title') {
                    $childElement->nodeValue = valid_xml_string($education->qualname);
                }
                if ($child == 'skills') {
                    $childElement->nodeValue = valid_xml_string($education->qualdescription);
                }
                $childRoot->appendChild($childElement);
            }
            // education - period
            $parentRoot = $xmlDoc->getElementsByTagName('education')->item($j);
            $childRoot = $parentRoot->firstChild;
            $childElement = $xmlDoc->createElement('from');
            $childRoot->appendChild($childElement);
            $grandchildRoot = $childRoot->firstChild;
            if ($education->startdate != null) {
                $learnstartdate = europass_date($education->startdate, $internaldateformat);
                if ($learnstartdate['year'] != '') {
                    $grandchildElement = $xmlDoc->createElement('year');
                    $grandchildElement->nodeValue = $learnstartdate['year'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
                if ($learnstartdate['month'] != '--00') {
                    $grandchildElement = $xmlDoc->createElement('month');
                    $grandchildElement->nodeValue = $learnstartdate['month'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
                if ($learnstartdate['day'] != '---00') {
                    $grandchildElement = $xmlDoc->createElement('day');
                    $grandchildElement->nodeValue = $learnstartdate['day'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
            }
            $childElement = $xmlDoc->createElement('to');
            $childRoot->appendChild($childElement);
            $grandchildRoot = $childRoot->firstChild->nextSibling;
            if ($education->enddate != null) {
                $learnenddate = europass_date($education->enddate, $internaldateformat);
                if ($learnenddate['year'] != '') {
                    $grandchildElement = $xmlDoc->createElement('year');
                    $grandchildElement->nodeValue = $learnenddate['year'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
                if ($learnenddate['month'] != '--00') {
                    $grandchildElement = $xmlDoc->createElement('month');
                    $grandchildElement->nodeValue = $learnenddate['month'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
                if ($learnenddate['day'] != '---00') {
                    $grandchildElement = $xmlDoc->createElement('day');
                    $grandchildElement->nodeValue = $learnenddate['day'];
                    $grandchildRoot->appendChild($grandchildElement);
                }
            }
            // organisation
            $childRoot = $xmlDoc->getElementsByTagName('organisation')->item($j);
            $childElement = $xmlDoc->createElement('name');
            $childElement->nodeValue = valid_xml_string($education->institution);
            $childRoot->appendChild($childElement);
            $childElement = $xmlDoc->createElement('address');
            $childRoot->appendChild($childElement);
            $childRoot = $xmlDoc->getElementsByTagName('address')->item($j + $i + 1);
            // $j+$i+1 because, we already have $i+1 previous address elements!
            $childElement = $xmlDoc->createElement('addressLine');
            $childElement->nodeValue = valid_xml_string($education->institutionaddress);
            $childRoot->appendChild($childElement);
            // level - label
            $childRoot = $xmlDoc->getElementsByTagName('level')->item($j);
            $childElement = $xmlDoc->createElement('label');
            $childElement->nodeValue = valid_xml_string($education->qualtype);
            $childRoot->appendChild($childElement);
            // create empty node for organisation type
            $childRoot = $xmlDoc->getElementsByTagName('organisation')->item($j);
            $childElement = $xmlDoc->createElement('type');
            $childRoot->appendChild($childElement);
            $j++;
        }
    }
    // =======================================
    // Dinamically set prefs and language list
    // =======================================
    // Dinamically add mother tongue(s)
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step5.motherLanguages');
    $childElement->setAttribute('keep', count($mothertongue_list) > 0 ? 'true' : 'false');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    $childRoot = $xmlDoc->getElementsByTagName('languagelist')->item(0);
    $childElement = $xmlDoc->createElement('language');
    $childElement->setAttribute('xsi:type', 'europass:mother');
    $childRoot->appendChild($childElement);
    $language_label = null;
    if (!empty($mothertongue_list)) {
        foreach ($mothertongue_list as $mothertongue) {
            $language_label .= get_string_from_file('language.' . $mothertongue->language, get_config('docroot') . 'artefact/europass/lang/' . get_lang_from_locale($locale) . '/artefact.europass.php') . ', ';
        }
        $language_label = substr($language_label, 0, -2);
        // omitt last comma and whitespace from $language_label
        $childRoot = $xmlDoc->getElementsByTagName('language')->item(0);
        if (count($mothertongue_list) == 1) {
            $childElement = $xmlDoc->createElement('code');
            $childElement->nodeValue = $mothertongue->language;
            $childRoot->appendChild($childElement);
        }
        $childElement = $xmlDoc->createElement('label');
        $childElement->nodeValue = $language_label;
        $childRoot->appendChild($childElement);
    }
    //Dinamically add foreign language(s)
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step5.foreignLanguageList');
    $childElement->setAttribute('keep', count($otherlanguage_list) > 0 ? 'true' : 'false');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    $l = 0;
    if (!empty($otherlanguage_list)) {
        foreach ($otherlanguage_list as $otherlanguage) {
            $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
            $childElement = $xmlDoc->createElement('field');
            $childElement->setAttribute('name', 'step5.foreignLanguageList[' . $l . ']');
            $childElement->setAttribute('keep', 'true');
            $childElement->nodeValue = null;
            $childRoot->appendChild($childElement);
            $childRoot = $xmlDoc->getElementsByTagName('languagelist')->item(0);
            $childElement = $xmlDoc->createElement('language');
            $childElement->setAttribute('xsi:type', 'europass:foreign');
            $childRoot->appendChild($childElement);
            $childRoot = $xmlDoc->getElementsByTagName('language')->item($l + 1);
            // Because mothertongue has index 0...
            $childElement = $xmlDoc->createElement('code');
            $childElement->nodeValue = $otherlanguage->language;
            $childRoot->appendChild($childElement);
            $childElement = $xmlDoc->createElement('label');
            $childElement->nodeValue = get_string_from_file('language.' . $otherlanguage->language, get_config('docroot') . 'artefact/europass/lang/' . get_lang_from_locale($locale) . '/artefact.europass.php');
            $childRoot->appendChild($childElement);
            $childElement = $xmlDoc->createElement('level');
            $childRoot->appendChild($childElement);
            $grandchildRoot = $childRoot->lastChild;
            $levels = array('listening' => $otherlanguage->listening, 'reading' => $otherlanguage->reading, 'spokeninteraction' => $otherlanguage->spokeninteraction, 'spokenproduction' => $otherlanguage->spokenproduction, 'writing' => $otherlanguage->writing);
            foreach ($levels as $field => $value) {
                $grandchildElement = $xmlDoc->createElement($field);
                $grandchildElement->nodeValue = strtolower($value);
                $grandchildRoot->appendChild($grandchildElement);
            }
            $l++;
        }
    }
    // ====================================
    // Dinamically set prefs and skill list
    // ====================================
    $skills = array('social' => $skills['socialskill'], 'organisational' => $skills['organisationalskill'], 'technical' => $skills['technicalskill'], 'computer' => $skills['computerskill'], 'artistic' => $skills['artisticskill'], 'other' => $skills['otherskill']);
    foreach ($skills as $field => $value) {
        $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
        $childElement = $xmlDoc->createElement('field');
        $childElement->setAttribute('name', 'step6.' . $field . 'Skills');
        $childElement->setAttribute('keep', $value == null ? 'false' : 'true');
        $childElement->nodeValue = null;
        $childRoot->appendChild($childElement);
        $childRoot = $xmlDoc->getElementsByTagName('skilllist')->item(0);
        $childElement = $xmlDoc->createElement('skill');
        $childElement->setAttribute('type', $field);
        $childElement->nodeValue = $showHTML ? replacehtmlchars($value) : valid_xml_string($value);
        $childRoot->appendChild($childElement);
    }
    // Dinamically set driving licence(s)
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'step6.drivingLicences');
    $childElement->setAttribute('keep', $drivinglicence == null ? 'false' : 'true');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    $childRoot = $xmlDoc->getElementsByTagName('skilllist')->item(0);
    $childElement = $xmlDoc->createElement('structured-skill');
    $childElement->setAttribute('xsi:type', 'europass:driving');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    if (!empty($drivinglicence)) {
        // Which driving licences are allowed.
        // NOTE: Driving licence AM is currently not allowed... but it will be in 2013.
        $allowedfields = array('A', 'A1', 'B', 'B1', 'BE', 'C', 'C1', 'CE', 'C1E', 'D', 'D1', 'DE', 'D1E');
        foreach ($drivinglicence as $field => $value) {
            $childRoot = $xmlDoc->getElementsByTagName('structured-skill')->item(0);
            // Set drivinglicence if it exists...
            if ($value != null && in_array($field, $allowedfields)) {
                $childElement = $xmlDoc->createElement('drivinglicence');
                $childElement->nodeValue = valid_xml_string($field);
                $childRoot->appendChild($childElement);
            }
        }
    }
    // ===================================
    // Dinamically set prefs and misc list
    // ===================================
    $misc = array('additional' => $misc['additionalinfo'], 'annexes' => $misc['annexes']);
    foreach ($misc as $field => $value) {
        $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
        $childElement = $xmlDoc->createElement('field');
        $childElement->setAttribute('name', 'step7.' . $field . ($field == 'additional' ? 'Info' : ''));
        $childElement->setAttribute('keep', $value == null ? 'false' : 'true');
        $childElement->nodeValue = null;
        $childRoot->appendChild($childElement);
        $childRoot = $xmlDoc->getElementsByTagName('misclist')->item(0);
        $childElement = $xmlDoc->createElement('misc');
        $childElement->setAttribute('type', $field);
        $childElement->nodeValue = $showHTML ? replacehtmlchars($value) : valid_xml_string($value);
        $childRoot->appendChild($childElement);
    }
    // ===================================
    // Dinamically set prefs (grid option)
    // ===================================
    $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0);
    $childElement = $xmlDoc->createElement('field');
    $childElement->setAttribute('name', 'grid');
    $childElement->setAttribute('keep', 'false');
    $childElement->nodeValue = null;
    $childRoot->appendChild($childElement);
    // ================================
    // Return dinamically generated XML
    // ================================
    return $xmlDoc->saveXML();
}
Exemplo n.º 4
0
function importeuropassform_submit(Pieform $form, $values)
{
    global $SESSION, $USER;
    $userid = $USER->get('id');
    $dbnow = db_format_timestamp(time());
    // Get locked fields of the institution that the user belongs to...
    $lockedfields = array();
    $records = get_records_sql_array('
		SELECT ilpf.profilefield
		FROM {usr} u INNER JOIN {auth_instance} ai
			ON u.authinstance = ai.id JOIN {institution_locked_profile_field} ilpf
			ON ai.institution = ilpf.name
		WHERE u.id = ?
		ORDER BY ilpf.profilefield', array($userid));
    if ($records) {
        foreach ($records as $record) {
            $lockedfields[] = $record->profilefield;
        }
    }
    $filename = $values['file']['tmp_name'];
    if ($filename != null) {
        $xmlDoc = new DOMDocument('1.0', 'UTF-8');
        //$xmlDoc->load($filename);
        // Upper line not working, so try another approach...
        // SEE: http://php.net/manual/en/function.dom-import-simplexml.php
        //$simplexmlDoc = simplexml_load_file($filename); // not working...
        $contents = file_get_contents($filename);
        $simplexmlDoc = simplexml_load_string($contents);
        $xmlNode = dom_import_simplexml($simplexmlDoc);
        $xmlNode = $xmlDoc->importNode($xmlNode, true);
        $xmlDoc->appendChild($xmlNode);
        // ======================================
        // Step 1: Import personal information...
        // ======================================
        // These are only fields that can be locked!
        if (!empty($values['identification']) && is_object($xmlDoc->getElementsByTagName('identification')->item(0))) {
            $SESSION->add_info_msg(get_string('fieldnotimported', 'artefact.europass', 'firstname'));
            $SESSION->add_info_msg(get_string('fieldnotimported', 'artefact.europass', 'lastname'));
            // Import address info...
            if (!in_array('address', $lockedfields)) {
                // Check if object exists - it only exists in Europass CV XML
                if (is_object($xmlDoc->getElementsByTagName('addressLine')->item(0))) {
                    $address = $xmlDoc->getElementsByTagName('addressLine')->item(0)->nodeValue;
                    if ($address != null) {
                        $id = get_field('artefact', 'id', 'artefacttype', 'address', 'owner', $userid);
                        if ($id != false) {
                            update_record('artefact', array('title' => $address, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                        } else {
                            insert_record('artefact', array('artefacttype' => 'address', 'owner' => $userid, 'author' => $userid, 'title' => $address, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                        }
                    }
                }
            } else {
                $SESSION->add_info_msg(get_string('lockedfieldnotimported', 'artefact.europass', 'address'));
            }
            // Import municipality/city...
            if (!in_array('city', $lockedfields)) {
                // Check if object exists - it only exists in Europass CV XML
                if (is_object($xmlDoc->getElementsByTagName('municipality')->item(0))) {
                    $municipality = $xmlDoc->getElementsByTagName('municipality')->item(0)->nodeValue;
                    if ($municipality != null) {
                        $id = get_field('artefact', 'id', 'artefacttype', 'city', 'owner', $userid);
                        if ($id != false) {
                            update_record('artefact', array('title' => $municipality, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                        } else {
                            insert_record('artefact', array('artefacttype' => 'city', 'owner' => $userid, 'author' => $userid, 'title' => $municipality, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                        }
                    }
                }
            } else {
                $SESSION->add_info_msg(get_string('lockedfieldnotimported', 'artefact.europass', 'municipality'));
            }
            // Import (home) telephone number...
            if (!in_array('homenumber', $lockedfields)) {
                // Check if object exists - it only exists in Europass CV XML
                if (is_object($xmlDoc->getElementsByTagName('telephone')->item(0))) {
                    $telephone = $xmlDoc->getElementsByTagName('telephone')->item(0)->nodeValue;
                    if ($telephone != null) {
                        $id = get_field('artefact', 'id', 'artefacttype', 'homenumber', 'owner', $userid);
                        if ($id != false) {
                            update_record('artefact', array('title' => $telephone, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                        } else {
                            insert_record('artefact', array('artefacttype' => 'homenumber', 'owner' => $userid, 'author' => $userid, 'title' => $telephone, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                        }
                    }
                }
            } else {
                $SESSION->add_info_msg(get_string('lockedfieldnotimported', 'artefact.europass', 'telephone'));
            }
            // Import mobile number...
            if (!in_array('mobilenumber', $lockedfields)) {
                // Check if object exists - it only exists in Europass CV XML
                if (is_object($xmlDoc->getElementsByTagName('mobile')->item(0))) {
                    $mobile = $xmlDoc->getElementsByTagName('mobile')->item(0)->nodeValue;
                    if ($mobile != null) {
                        $id = get_field('artefact', 'id', 'artefacttype', 'mobilenumber', 'owner', $userid);
                        if ($id != false) {
                            update_record('artefact', array('title' => $mobile, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                        } else {
                            insert_record('artefact', array('artefacttype' => 'mobilenumber', 'owner' => $userid, 'author' => $userid, 'title' => $mobile, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                        }
                    }
                }
            } else {
                $SESSION->add_info_msg(get_string('lockedfieldnotimported', 'artefact.europass', 'mobile'));
            }
            // Import fax number...
            if (!in_array('faxnumber', $lockedfields)) {
                // Check if object exists - it only exists in Europass CV XML
                if (is_object($xmlDoc->getElementsByTagName('fax')->item(0))) {
                    $fax = $xmlDoc->getElementsByTagName('fax')->item(0)->nodeValue;
                    if ($fax != null) {
                        $id = get_field('artefact', 'id', 'artefacttype', 'faxnumber', 'owner', $userid);
                        if ($id != false) {
                            update_record('artefact', array('title' => $fax, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                        } else {
                            insert_record('artefact', array('artefacttype' => 'faxnumber', 'owner' => $userid, 'author' => $userid, 'title' => $fax, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                        }
                    }
                }
            } else {
                $SESSION->add_info_msg(get_string('lockedfieldnotimported', 'artefact.europass', 'fax'));
            }
            // Import country...
            if (!in_array('country', $lockedfields) && is_object($xmlDoc->getElementsByTagName('country')->item(0))) {
                $parent = $xmlDoc->getElementsByTagName('country')->item(0);
                $clone = $parent->cloneNode(true);
                // Check if object exists - it only exists in Europass CV XML
                if (is_object($clone->getElementsByTagName('code')->item(0))) {
                    $country = strtolower($clone->getElementsByTagName('code')->item(0)->nodeValue);
                    if ($country != null) {
                        $id = get_field('artefact', 'id', 'artefacttype', 'country', 'owner', $userid);
                        if ($id != false) {
                            update_record('artefact', array('title' => $country, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                        } else {
                            insert_record('artefact', array('artefacttype' => 'country', 'owner' => $userid, 'author' => $userid, 'title' => $country, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                        }
                    }
                }
            } else {
                $SESSION->add_info_msg(get_string('lockedfieldnotimported', 'artefact.europass', 'fax'));
            }
            // -------------------
            // Import demographics
            // -------------------
            // No locked fields from here on...
            $personalinfo = get_record('artefact', 'artefacttype', 'personalinformation', 'owner', $userid);
            if (!$personalinfo) {
                $artefactid = insert_record('artefact', array('artefacttype' => 'personalinformation', 'owner' => $userid, 'title' => get_string('identification', 'artefact.europass'), 'author' => $userid, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow), 'id', true);
                insert_record('artefact_resume_personal_information', array('artefact' => $artefactid));
            } else {
                $artefactid = $personalinfo->id;
            }
            // Get birthdate...
            $birthdate = null;
            if (is_object($xmlDoc->getElementsByTagName('birthdate')->item(0))) {
                $birthdate = $xmlDoc->getElementsByTagName('birthdate')->item(0)->nodeValue;
                $birthdate = strftime('%Y-%m-%d %H:%M:%S', strtotime($birthdate));
            }
            // Get gender...
            $gender = null;
            if (is_object($xmlDoc->getElementsByTagName('gender')->item(0))) {
                $gendervalue = $xmlDoc->getElementsByTagName('gender')->item(0)->nodeValue;
                switch ($gendervalue) {
                    case 'M':
                        $gender = 'male';
                        break;
                    case 'F':
                        $gender = 'female';
                        break;
                    default:
                        $gender = null;
                        // When NA option is set.
                }
            }
            // Get nationality...
            $citizenship = null;
            if (is_object($xmlDoc->getElementsByTagName('nationality'))) {
                $nationalities = $xmlDoc->getElementsByTagName('nationality');
                foreach ($nationalities as $nationality) {
                    $citizenship .= $nationality->getElementsByTagName('label')->item(0)->nodeValue . ', ';
                }
                $citizenship = substr($citizenship, 0, -2);
                // Remove ', ' at the end of string.
            }
            // Import demographics...
            $demographics = array();
            if ($birthdate != null) {
                $demographics = array_merge($demographics, array('dateofbirth' => $birthdate));
            }
            if ($gender != null) {
                $demographics = array_merge($demographics, array('gender' => $gender));
            }
            if ($citizenship != null) {
                $demographics = array_merge($demographics, array('citizenship' => $citizenship));
            }
            $id = get_field('artefact_resume_personal_information', 'artefact', 'artefact', $artefactid);
            if ($id != false) {
                if (!empty($demographics)) {
                    update_record('artefact_resume_personal_information', $demographics, array('artefact' => $artefactid));
                    update_record('artefact', array('mtime' => $dbnow, 'atime' => $dbnow), array('id' => $artefactid));
                }
            } else {
                insert_record('artefact_resume_personal_information', array_merge($demographics, array('artefact' => $artefactid)));
                update_record('artefact', array('mtime' => $dbnow, 'atime' => $dbnow), array('id' => $artefactid));
            }
        }
        // =============================
        // Step 2: Import application...
        // =============================
        // Check if object exists - it only exists in Europass CV XML
        if (!empty($values['application']) && is_object($xmlDoc->getElementsByTagName('application')->item(0))) {
            // Import application code...
            $parent = $xmlDoc->getElementsByTagName('application')->item(0);
            $clone = $parent->cloneNode(true);
            if (is_object($clone->getElementsByTagName('code')->item(0))) {
                $application = $clone->getElementsByTagName('code')->item(0)->nodeValue;
                if ($application != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'application', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('application', 'artefact.europass'), 'description' => 'i' . $application, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'application', 'owner' => $userid, 'author' => $userid, 'title' => get_string('application', 'artefact.europass'), 'description' => 'i' . $application, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
            }
        }
        // =================================
        // Step 3: Import work experience...
        // =================================
        // Check if object exists - it only exists in Europass CV XML
        if (!empty($values['workexperience']) && is_object($xmlDoc->getElementsByTagName('workexperiencelist')->item(0))) {
            $employment = get_record('artefact', 'artefacttype', 'employmenthistory', 'owner', $userid);
            if (!$employment) {
                $artefactid = insert_record('artefact', array('artefacttype' => 'employmenthistory', 'owner' => $userid, 'title' => get_string('employmenthistory', 'artefact.resume'), 'author' => $userid, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow), 'id', true);
            } else {
                $artefactid = $employment->id;
            }
            // -----------------------
            // Import work experiences
            // -----------------------
            $workexperiences = $xmlDoc->getElementsByTagName('workexperience');
            $getgender = $xmlDoc->getElementsByTagName('gender')->item(0)->nodeValue;
            switch ($getgender) {
                case 'F':
                    $gender = 'female';
                    break;
                case 'M':
                    $gender = 'male';
                    break;
                default:
                    $gender = null;
            }
            foreach ($workexperiences as $workexperience) {
                // Get startdate...
                $startdate = null;
                if ($workexperience->getElementsByTagName('from')->item(0)->hasChildNodes()) {
                    $parent = $workexperience->getElementsByTagName('from')->item(0);
                    $clone = $parent->cloneNode(true);
                    $start = array('year' => 0, 'month' => 0, 'day' => 0);
                    // Get year, if it exists...
                    if (is_object($clone->getElementsByTagName('year')->item(0))) {
                        $start['year'] = trim($clone->getElementsByTagName('year')->item(0)->nodeValue);
                    }
                    // Get month, if it exists...
                    if (is_object($clone->getElementsByTagName('month')->item(0))) {
                        $start['month'] = ltrim(trim($clone->getElementsByTagName('month')->item(0)->nodeValue), '-');
                    }
                    // Get day, if it exists...
                    if (is_object($clone->getElementsByTagName('day')->item(0))) {
                        $start['day'] = ltrim(trim($clone->getElementsByTagName('day')->item(0)->nodeValue), '-');
                    }
                    $startdate = mahara_date($start, $values['internaldate']);
                }
                // Get enddate...
                $enddate = null;
                if ($workexperience->getElementsByTagName('to')->item(0)->hasChildNodes()) {
                    $parent = $workexperience->getElementsByTagName('to')->item(0);
                    $clone = $parent->cloneNode(true);
                    $end = array('year' => 0, 'month' => 0, 'day' => 0);
                    // Get year, if it exists...
                    if (is_object($clone->getElementsByTagName('year')->item(0))) {
                        $end['year'] = trim($clone->getElementsByTagName('year')->item(0)->nodeValue);
                    }
                    // Get month, if it exists...
                    if (is_object($clone->getElementsByTagName('month')->item(0))) {
                        $end['month'] = ltrim(trim($clone->getElementsByTagName('month')->item(0)->nodeValue), '-');
                    }
                    // Get day, if it exists...
                    if (is_object($clone->getElementsByTagName('day')->item(0))) {
                        $end['day'] = ltrim(trim($clone->getElementsByTagName('day')->item(0)->nodeValue), '-');
                    }
                    $enddate = mahara_date($end, $values['internaldate']);
                }
                // Get employer (name & address)...
                $employer = null;
                $employeraddress = null;
                if ($workexperience->getElementsByTagName('employer')->item(0)->hasChildNodes()) {
                    $parent = $workexperience->getElementsByTagName('employer')->item(0);
                    $clone = $parent->cloneNode(true);
                    // Get employer's name...
                    if (is_object($clone->getElementsByTagName('name')->item(0))) {
                        $employer = $clone->getElementsByTagName('name')->item(0)->nodeValue;
                    }
                    // Get employer's address...
                    if (is_object($clone->getElementsByTagName('addressLine')->item(0))) {
                        $employeraddress = $clone->getElementsByTagName('addressLine')->item(0)->nodeValue;
                    }
                    if (is_object($clone->getElementsByTagName('postalCode')->item(0))) {
                        $employeraddress .= ', ' . $clone->getElementsByTagName('postalCode')->item(0)->nodeValue;
                    }
                    if (is_object($clone->getElementsByTagName('municipality')->item(0))) {
                        $employeraddress .= ' ' . $clone->getElementsByTagName('municipality')->item(0)->nodeValue;
                    }
                    if ($clone->getElementsByTagName('country')->item(0)->hasChildNodes()) {
                        $country = $clone->getElementsByTagName('country')->item(0)->cloneNode(true);
                        if (is_object($country->getElementsByTagName('code')->item(0))) {
                            $countrycode = strtolower($country->getElementsByTagName('code')->item(0)->nodeValue);
                            $countryname = get_string_from_file('country.' . $countrycode, get_config('docroot') . 'artefact/europass/lang/' . get_config('lang') . '/artefact.europass.php');
                            $employeraddress .= ', ' . $countryname;
                        } else {
                            if (is_object($country->getElementsByTagName('label')->item(0))) {
                                $employeraddress .= ', ' . $country->getElementsByTagName('label')->item(0)->nodeValue;
                            }
                        }
                    }
                }
                // Get jobtitle...
                $jobtitle = null;
                if ($workexperience->getElementsByTagName('position')->item(0)->hasChildNodes()) {
                    $parent = $workexperience->getElementsByTagName('position')->item(0);
                    $clone = $parent->cloneNode(true);
                    // Get position code if it exists, else get label
                    if (is_object($clone->getElementsByTagName('code')->item(0))) {
                        $code = 'i' . $clone->getElementsByTagName('code')->item(0)->nodeValue;
                        $occupation = get_occupation($code, set_default_locale(get_config('lang')), $gender);
                        $jobtitle = $occupation['label'];
                    } elseif (is_object($clone->getElementsByTagName('label')->item(0))) {
                        $jobtitle = $clone->getElementsByTagName('label')->item(0)->nodeValue;
                    }
                }
                // Get positiondescription...
                $positiondescription = null;
                if (is_object($workexperience->getElementsByTagName('activities')->item(0))) {
                    $positiondescription = $workexperience->getElementsByTagName('activities')->item(0)->nodeValue;
                }
                // Import employment history...
                $employmentdata = array('artefact' => $artefactid, 'startdate' => $startdate, 'employer' => $employer);
                if ($enddate != null) {
                    $employmentdata = array_merge($employmentdata, array('enddate' => $enddate));
                }
                if ($employeraddress != null) {
                    $employmentdata = array_merge($employmentdata, array('employeraddress' => $employeraddress));
                }
                if ($jobtitle != null) {
                    $employmentdata = array_merge($employmentdata, array('jobtitle' => $jobtitle));
                }
                if ($positiondescription != null) {
                    $employmentdata = array_merge($employmentdata, array('positiondescription' => $positiondescription));
                }
                $id = get_field('artefact_resume_employmenthistory', 'id', 'artefact', $artefactid, 'startdate', $startdate, 'employer', $employer);
                if ($id != false) {
                    update_record('artefact_resume_employmenthistory', $employmentdata, array('id' => $id));
                } else {
                    insert_record('artefact_resume_employmenthistory', $employmentdata);
                }
            }
            update_record('artefact', array('mtime' => $dbnow, 'atime' => $dbnow), array('id' => $artefactid));
        }
        // ===========================
        // Step 4: Import education...
        // ===========================
        // Check if object exists - it only exists in Europass CV XML
        if (!empty($values['education']) && is_object($xmlDoc->getElementsByTagName('educationlist')->item(0))) {
            $education = get_record('artefact', 'artefacttype', 'educationhistory', 'owner', $userid);
            if (!$education) {
                $artefactid = insert_record('artefact', array('artefacttype' => 'educationhistory', 'owner' => $userid, 'title' => get_string('educationhistory', 'artefact.resume'), 'author' => $userid, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow), 'id', true);
            } else {
                $artefactid = $education->id;
            }
            // ----------------
            // Import education
            // ----------------
            $educationlist = $xmlDoc->getElementsByTagName('education');
            foreach ($educationlist as $education) {
                // Get startdate...
                $startdate = null;
                if ($education->getElementsByTagName('from')->item(0)->hasChildNodes()) {
                    $parent = $education->getElementsByTagName('from')->item(0);
                    $clone = $parent->cloneNode(true);
                    $start = array('year' => 0, 'month' => 0, 'day' => 0);
                    // Get year, if it exists...
                    if (is_object($clone->getElementsByTagName('year')->item(0))) {
                        $start['year'] = trim($clone->getElementsByTagName('year')->item(0)->nodeValue);
                    }
                    // Get month, if it exists...
                    if (is_object($clone->getElementsByTagName('month')->item(0))) {
                        $start['month'] = ltrim(trim($clone->getElementsByTagName('month')->item(0)->nodeValue), '-');
                    }
                    // Get day, if it exists...
                    if (is_object($clone->getElementsByTagName('day')->item(0))) {
                        $start['day'] = ltrim(trim($clone->getElementsByTagName('day')->item(0)->nodeValue), '-');
                    }
                    $startdate = mahara_date($start, $values['internaldate']);
                }
                // Get enddate...
                $enddate = null;
                if ($education->getElementsByTagName('to')->item(0)->hasChildNodes()) {
                    $parent = $education->getElementsByTagName('to')->item(0);
                    $clone = $parent->cloneNode(true);
                    $end = array('year' => 0, 'month' => 0, 'day' => 0);
                    // Get year, if it exists...
                    if (is_object($clone->getElementsByTagName('year')->item(0))) {
                        $end['year'] = trim($clone->getElementsByTagName('year')->item(0)->nodeValue);
                    }
                    // Get month, if it exists...
                    if (is_object($clone->getElementsByTagName('month')->item(0))) {
                        $end['month'] = ltrim(trim($clone->getElementsByTagName('month')->item(0)->nodeValue), '-');
                    }
                    // Get day, if it exists...
                    if (is_object($clone->getElementsByTagName('day')->item(0))) {
                        $end['day'] = ltrim(trim($clone->getElementsByTagName('day')->item(0)->nodeValue), '-');
                    }
                    $enddate = mahara_date($end, $values['internaldate']);
                }
                // Get qualification type...
                $qualtype = null;
                if ($education->getElementsByTagName('level')->item(0)->hasChildNodes()) {
                    $parent = $education->getElementsByTagName('level')->item(0);
                    $clone = $parent->cloneNode(true);
                    // Get employer's name...
                    if (is_object($clone->getElementsByTagName('label')->item(0))) {
                        $qualtype = $clone->getElementsByTagName('label')->item(0)->nodeValue;
                    }
                }
                // Get qualification name...
                $qualname = null;
                if (is_object($education->getElementsByTagName('title')->item(0))) {
                    $qualname = $education->getElementsByTagName('title')->item(0)->nodeValue;
                }
                // Get qualification description...
                $qualdescription = null;
                if (is_object($education->getElementsByTagName('skills')->item(0))) {
                    $qualdescription = $education->getElementsByTagName('skills')->item(0)->nodeValue;
                }
                // Get insitution (name & address)...
                $institution = null;
                $institutionaddress = null;
                if ($education->getElementsByTagName('organisation')->item(0)->hasChildNodes()) {
                    $parent = $education->getElementsByTagName('organisation')->item(0);
                    $clone = $parent->cloneNode(true);
                    // Get institution's name...
                    if (is_object($clone->getElementsByTagName('name')->item(0))) {
                        $institution = $clone->getElementsByTagName('name')->item(0)->nodeValue;
                    }
                    // Get institution's address...
                    if (is_object($clone->getElementsByTagName('addressLine')->item(0))) {
                        $institutionaddress = $clone->getElementsByTagName('addressLine')->item(0)->nodeValue;
                    }
                    if (is_object($clone->getElementsByTagName('postalCode')->item(0))) {
                        $institutionaddress .= ', ' . $clone->getElementsByTagName('postalCode')->item(0)->nodeValue;
                    }
                    if (is_object($clone->getElementsByTagName('municipality')->item(0))) {
                        $institutionaddress .= ' ' . $clone->getElementsByTagName('municipality')->item(0)->nodeValue;
                    }
                    if ($clone->getElementsByTagName('country')->item(0)->hasChildNodes()) {
                        $country = $clone->getElementsByTagName('country')->item(0)->cloneNode(true);
                        if (is_object($country->getElementsByTagName('code')->item(0))) {
                            $countrycode = strtolower($country->getElementsByTagName('code')->item(0)->nodeValue);
                            $countryname = get_string_from_file('country.' . $countrycode, get_config('docroot') . 'artefact/europass/lang/' . get_config('lang') . '/artefact.europass.php');
                            $institutionaddress .= ', ' . $countryname;
                        } else {
                            if (is_object($country->getElementsByTagName('label')->item(0))) {
                                $institutionaddress .= ', ' . $country->getElementsByTagName('label')->item(0)->nodeValue;
                            }
                        }
                    }
                }
                // Import education history...
                $educationdata = array('artefact' => $artefactid, 'startdate' => $startdate, 'institution' => $institution);
                if ($enddate != null) {
                    $educationdata = array_merge($educationdata, array('enddate' => $enddate));
                }
                if ($qualtype != null) {
                    $educationdata = array_merge($educationdata, array('qualtype' => $qualtype));
                }
                if ($qualname != null) {
                    $educationdata = array_merge($educationdata, array('qualname' => $qualname));
                }
                if ($institutionaddress != null) {
                    $educationdata = array_merge($educationdata, array('institutionaddress' => $institutionaddress));
                }
                if ($qualdescription != null) {
                    $educationdata = array_merge($educationdata, array('qualdescription' => $qualdescription));
                }
                $id = get_field('artefact_resume_educationhistory', 'id', 'artefact', $artefactid, 'startdate', $startdate, 'institution', $institution);
                if ($id != false) {
                    update_record('artefact_resume_educationhistory', $educationdata, array('id' => $id));
                } else {
                    insert_record('artefact_resume_educationhistory', $educationdata);
                }
            }
            update_record('artefact', array('mtime' => $dbnow, 'atime' => $dbnow), array('id' => $artefactid));
        }
        // ===========================
        // Step 5: Import languages...
        // ===========================
        if (!empty($values['languages']) && is_object($xmlDoc->getElementsByTagName('languagelist')->item(0))) {
            $mothertongue = get_record('artefact', 'artefacttype', 'mothertongue', 'owner', $userid);
            if (!$mothertongue) {
                $mothertongueid = insert_record('artefact', array('artefacttype' => 'mothertongue', 'owner' => $userid, 'title' => get_string('mothertongue', 'artefact.europass'), 'author' => $userid, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow), 'id', true);
            } else {
                $mothertongueid = $mothertongue->id;
            }
            $otherlanguage = get_record('artefact', 'artefacttype', 'otherlanguage', 'owner', $userid);
            if (!$otherlanguage) {
                $otherlanguageid = insert_record('artefact', array('artefacttype' => 'otherlanguage', 'owner' => $userid, 'title' => get_string('otherlanguage', 'artefact.europass'), 'author' => $userid, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow), 'id', true);
            } else {
                $otherlanguageid = $otherlanguage->id;
            }
            $parent = $xmlDoc->getElementsByTagName('languagelist')->item(0);
            $clone = $parent->cloneNode(true);
            $children = $clone->getElementsByTagName('language');
            foreach ($children as $child) {
                // --------------------
                // Import mother tongue
                // --------------------
                if ($child->getAttribute('xsi:type') == 'europass:mother' && $child->hasChildNodes()) {
                    if (is_object($child->getElementsByTagName('code')->item(0))) {
                        $languagecode = strtolower($child->getElementsByTagName('code')->item(0)->nodeValue);
                        $id = get_field('artefact_europass_mothertongue', 'id', 'artefact', $mothertongueid, 'language', $languagecode);
                        if ($id != false) {
                            update_record('artefact_europass_mothertongue', array('artefact' => $mothertongueid, 'language' => $languagecode), array('id' => $id));
                        } else {
                            insert_record('artefact_europass_mothertongue', array('artefact' => $mothertongueid, 'language' => $languagecode));
                        }
                        update_record('artefact', array('mtime' => $dbnow, 'atime' => $dbnow), array('id' => $mothertongueid));
                    } else {
                        if (is_object($child->getElementsByTagName('label')->item(0))) {
                            $SESSION->add_info_msg(get_string('languagecodemissing', 'artefact.europass', 'mothertongue'));
                        }
                    }
                }
                // --------------------------
                // Import foreign language(s)
                // --------------------------
                if ($child->getAttribute('xsi:type') == 'europass:foreign' && $child->hasChildNodes()) {
                    $language = $child->cloneNode(true);
                    if (is_object($language->getElementsByTagName('code')->item(0))) {
                        $languagecode = strtolower($language->getElementsByTagName('code')->item(0)->nodeValue);
                        $level = array();
                        $level['listening'] = strtoupper($language->getElementsByTagName('listening')->item(0)->nodeValue);
                        $level['reading'] = strtoupper($language->getElementsByTagName('reading')->item(0)->nodeValue);
                        $level['spokeninteraction'] = strtoupper($language->getElementsByTagName('spokeninteraction')->item(0)->nodeValue);
                        $level['spokenproduction'] = strtoupper($language->getElementsByTagName('spokenproduction')->item(0)->nodeValue);
                        $level['writing'] = strtoupper($language->getElementsByTagName('writing')->item(0)->nodeValue);
                        $languagedata = array('artefact' => $otherlanguageid, 'language' => $languagecode, 'listening' => $level['listening'], 'reading' => $level['reading'], 'spokeninteraction' => $level['spokeninteraction'], 'spokenproduction' => $level['spokenproduction'], 'writing' => $level['writing']);
                        $languageid = get_field('artefact_europass_otherlanguage', 'id', 'artefact', $otherlanguageid, 'language', $languagecode);
                        if ($languageid != false) {
                            update_record('artefact_europass_otherlanguage', $languagedata, array('id' => $languageid));
                        } else {
                            $languageid = insert_record('artefact_europass_otherlanguage', $languagedata, 'id', true);
                        }
                        // Import language diploma(s)
                        // --------------------------
                        $diplomalist = $language->getElementsByTagName('diploma');
                        foreach ($diplomalist as $diploma) {
                            // Get certificate (title)...
                            $certificate = null;
                            if (is_object($diploma->getElementsByTagName('title')->item(0))) {
                                $certificate = $diploma->getElementsByTagName('title')->item(0)->nodeValue;
                            }
                            // Get awarding body...
                            $awardingbody = null;
                            if (is_object($diploma->getElementsByTagName('awardingBody')->item(0))) {
                                $awardingbody = $diploma->getElementsByTagName('awardingBody')->item(0)->nodeValue;
                            }
                            // Get certificate date...
                            $certificatedate = null;
                            if ($diploma->getElementsByTagName('date')->item(0)->hasChildNodes()) {
                                $parent = $diploma->getElementsByTagName('date')->item(0);
                                $clone = $parent->cloneNode(true);
                                $certdate = array('year' => 0, 'month' => 0, 'day' => 0);
                                // Get year, if it exists...
                                if (is_object($clone->getElementsByTagName('year')->item(0))) {
                                    $certdate['year'] = trim($clone->getElementsByTagName('year')->item(0)->nodeValue);
                                }
                                // Get month, if it exists...
                                if (is_object($clone->getElementsByTagName('month')->item(0))) {
                                    $certdate['month'] = ltrim(trim($clone->getElementsByTagName('month')->item(0)->nodeValue), '-');
                                }
                                // Get day, if it exists...
                                if (is_object($clone->getElementsByTagName('day')->item(0))) {
                                    $certdate['day'] = ltrim(trim($clone->getElementsByTagName('day')->item(0)->nodeValue), '-');
                                }
                                $certificatedate = mahara_date($certdate, $values['internaldate']);
                            }
                            // Get european level...
                            $europeanlevel = null;
                            if (is_object($diploma->getElementsByTagName('level')->item(0))) {
                                $europeanlevel = strtoupper($diploma->getElementsByTagName('level')->item(0)->nodeValue);
                            }
                            // Import language diploma...
                            $artefact = get_field('artefact', 'id', 'artefacttype', 'languagediploma', 'owner', $userid);
                            if (!$artefact) {
                                $artefact = insert_record('artefact', array('artefacttype' => 'languagediploma', 'owner' => $userid, 'title' => get_string('languagediploma', 'artefact.europass'), 'author' => $userid, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow), 'id', true);
                            }
                            $diplomadata = array('artefact' => $artefact, 'languageid' => $languageid, 'certificate' => $certificate, 'awardingbody' => $awardingbody, 'certificatedate' => $certificatedate);
                            if ($europeanlevel != null) {
                                $diplomadata = array_merge($diplomadata, array('europeanlevel' => $europeanlevel));
                            }
                            $id = get_field('artefact_europass_languagediploma', 'id', 'artefact', $otherlanguageid, 'languageid', $languageid);
                            if ($id != false) {
                                update_record('artefact_europass_languagediploma', $diplomadata, array('id' => $id));
                            } else {
                                insert_record('artefact_europass_languagediploma', $diplomadata);
                            }
                        }
                        // Import linguistic experience(s)
                        // -------------------------------
                        $experiencelist = $language->getElementsByTagName('experience');
                        foreach ($experiencelist as $experience) {
                            // Get startdate...
                            $startdate = null;
                            if ($experience->getElementsByTagName('from')->item(0)->hasChildNodes()) {
                                $parent = $experience->getElementsByTagName('from')->item(0);
                                $clone = $parent->cloneNode(true);
                                $start = array('year' => 0, 'month' => 0, 'day' => 0);
                                // Get year, if it exists...
                                if (is_object($clone->getElementsByTagName('year')->item(0))) {
                                    $start['year'] = trim($clone->getElementsByTagName('year')->item(0)->nodeValue);
                                }
                                // Get month, if it exists...
                                if (is_object($clone->getElementsByTagName('month')->item(0))) {
                                    $start['month'] = ltrim(trim($clone->getElementsByTagName('month')->item(0)->nodeValue), '-');
                                }
                                // Get day, if it exists...
                                if (is_object($clone->getElementsByTagName('day')->item(0))) {
                                    $start['day'] = ltrim(trim($clone->getElementsByTagName('day')->item(0)->nodeValue), '-');
                                }
                                $startdate = mahara_date($start, $values['internaldate']);
                            }
                            // Get enddate...
                            $enddate = null;
                            if ($experience->getElementsByTagName('to')->item(0)->hasChildNodes()) {
                                $parent = $experience->getElementsByTagName('to')->item(0);
                                $clone = $parent->cloneNode(true);
                                $end = array('year' => 0, 'month' => 0, 'day' => 0);
                                // Get year, if it exists...
                                if (is_object($clone->getElementsByTagName('year')->item(0))) {
                                    $end['year'] = trim($clone->getElementsByTagName('year')->item(0)->nodeValue);
                                }
                                // Get month, if it exists...
                                if (is_object($clone->getElementsByTagName('month')->item(0))) {
                                    $end['month'] = ltrim(trim($clone->getElementsByTagName('month')->item(0)->nodeValue), '-');
                                }
                                // Get day, if it exists...
                                if (is_object($clone->getElementsByTagName('day')->item(0))) {
                                    $end['day'] = ltrim(trim($clone->getElementsByTagName('day')->item(0)->nodeValue), '-');
                                }
                                $enddate = mahara_date($end, $values['internaldate']);
                            }
                            // Get qualification name...
                            $description = null;
                            if (is_object($experience->getElementsByTagName('description')->item(0))) {
                                $description = $experience->getElementsByTagName('description')->item(0)->nodeValue;
                            }
                            // Import linguistic experience...
                            $artefact = get_field('artefact', 'id', 'artefacttype', 'languageexperience', 'owner', $userid);
                            if (!$artefact) {
                                $artefact = insert_record('artefact', array('artefacttype' => 'languageexperience', 'owner' => $userid, 'title' => get_string('languageexperience', 'artefact.europass'), 'author' => $userid, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow), 'id', true);
                            }
                            $experiencedata = array('artefact' => $artefact, 'languageid' => $languageid, 'startdate' => $startdate, 'description' => $description);
                            if ($enddate != null) {
                                $experiencedata = array_merge($experiencedata, array('enddate' => $enddate));
                            }
                            $id = get_field('artefact_europass_languageexperience', 'id', 'artefact', $otherlanguageid, 'languageid', $languageid);
                            if ($id != false) {
                                update_record('artefact_europass_languageexperience', $experiencedata, array('id' => $id));
                            } else {
                                insert_record('artefact_europass_languageexperience', $experiencedata);
                            }
                        }
                        update_record('artefact', array('mtime' => $dbnow, 'atime' => $dbnow), array('id' => $otherlanguageid));
                    } else {
                        if (is_object($child->getElementsByTagName('label')->item(0))) {
                            $SESSION->add_info_msg(get_string('languagecodemissing', 'artefact.europass', 'otherlanguage'));
                        }
                    }
                }
            }
        }
        // ========================================
        // Step 6: Import skills and competences...
        // ========================================
        // Check if object exists - it only exists in Europass CV XML
        if (!empty($values['skills']) && is_object($xmlDoc->getElementsByTagName('skilllist')->item(0))) {
            $parent = $xmlDoc->getElementsByTagName('skilllist')->item(0);
            $clone = $parent->cloneNode(true);
            $children = $clone->getElementsByTagName('skill');
            foreach ($children as $child) {
                // Import social skills...
                if ($child->getAttribute('type') == 'social' && $child->nodeValue != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'socialskill', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('socialskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'socialskill', 'owner' => $userid, 'author' => $userid, 'title' => get_string('socialskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
                // Import organisatonal skills...
                if ($child->getAttribute('type') == 'organisational' && $child->nodeValue != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'organisationalskill', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('organisationalskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'organisationalskill', 'owner' => $userid, 'author' => $userid, 'title' => get_string('organisationalskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
                // Import technical skills...
                if ($child->getAttribute('type') == 'technical' && $child->nodeValue != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'technicalskill', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('technicalskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'technicalskill', 'owner' => $userid, 'author' => $userid, 'title' => get_string('technicalskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
                // Import computer skills...
                if ($child->getAttribute('type') == 'computer' && $child->nodeValue != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'computerskill', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('computerskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'computerskill', 'owner' => $userid, 'author' => $userid, 'title' => get_string('computerskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
                // Import artistic skills...
                if ($child->getAttribute('type') == 'artistic' && $child->nodeValue != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'artisticskill', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('artisticskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'artisticskill', 'owner' => $userid, 'author' => $userid, 'title' => get_string('artisticskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
                // Import other skills...
                if ($child->getAttribute('type') == 'other' && $child->nodeValue != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'otherskill', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('otherskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'otherskill', 'owner' => $userid, 'author' => $userid, 'title' => get_string('otherskill', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
            }
            // Import driving licences...
            $drivinglicence = array('AM' => false, 'A1' => false, 'A' => false, 'B' => false, 'BE' => false, 'B1' => false, 'C' => false, 'CE' => false, 'C1' => false, 'C1E' => false, 'D' => false, 'DE' => false, 'D1' => false, 'D1E' => false);
            $licences = $clone->getElementsByTagName('drivinglicence');
            foreach ($licences as $licence) {
                $drivinglicence[$licence->nodeValue] = true;
            }
            $drivinglicence = serialize($drivinglicence);
            $id = get_field('artefact', 'id', 'artefacttype', 'drivinglicence', 'owner', $userid);
            if ($id != false) {
                update_record('artefact', array('title' => get_string('drivinglicence', 'artefact.europass'), 'description' => $drivinglicence, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
            } else {
                insert_record('artefact', array('artefacttype' => 'drivinglicence', 'owner' => $userid, 'author' => $userid, 'title' => get_string('drivinglicence', 'artefact.europass'), 'description' => $drivinglicence, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
            }
        }
        // ========================================
        // Step 7: Import additional information...
        // ========================================
        // Check if object exists - it only exists in Europass CV XML
        if (!empty($values['additionalinfo']) && is_object($xmlDoc->getElementsByTagName('misclist')->item(0))) {
            $parent = $xmlDoc->getElementsByTagName('misclist')->item(0);
            $clone = $parent->cloneNode(true);
            $children = $clone->getElementsByTagName('misc');
            foreach ($children as $child) {
                // Import additional information...
                if ($child->getAttribute('type') == 'additional' && $child->nodeValue != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'additionalinfo', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('additionalinfo', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'additionalinfo', 'owner' => $userid, 'author' => $userid, 'title' => get_string('additionalinfo', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
                // Import annexes...
                if ($child->getAttribute('type') == 'annexes' && $child->nodeValue != null) {
                    $id = get_field('artefact', 'id', 'artefacttype', 'annexes', 'owner', $userid);
                    if ($id != false) {
                        update_record('artefact', array('title' => get_string('annexes', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow), array('id' => $id));
                    } else {
                        insert_record('artefact', array('artefacttype' => 'annexes', 'owner' => $userid, 'author' => $userid, 'title' => get_string('annexes', 'artefact.europass'), 'description' => $child->nodeValue, 'mtime' => $dbnow, 'atime' => $dbnow, 'ctime' => $dbnow));
                    }
                }
            }
        }
    }
    $SESSION->add_ok_msg(get_string('europassimportexecuted', 'artefact.europass'));
    redirect('/artefact/europass/');
}