function generate_europasslp_xml($userid, $showHTML = false, $locale = 'en_GB', $internaldateformat = 'dmy11', $externaldateformat = '/numeric/long', $convert = false) { // ================================ // Load values from Mahara database // ================================ // load user's existing contact information $element_list = array('firstname' => 'text', 'lastname' => 'text'); $contactinfo = array('firstname' => null, 'lastname' => 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) { } // 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(); } // ====================== // Dinamically create XML // ====================== $xmlDoc = new DOMDocument('1.0', 'UTF-8'); // We want a nice output //$xmlDoc->formatOutput = true; $styleSheet = $xmlDoc->createProcessingInstruction('xml-stylesheet', 'href="http://europass.cedefop.europa.eu/xml/lp_' . $locale . '_V2.0.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', 'languagelist'); foreach ($children as $child) { $childRoot = $xmlDoc->getElementsByTagName('europass:learnerinfo')->item(0); $childElement = $xmlDoc->createElement($child); $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 Language Passport 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', 'personal.lastName'); $childElement->setAttribute('before', 'personal.firstName'); $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 demographics // ---------------------------- $childRoot = $xmlDoc->getElementsByTagName('identification')->item(0); $childElement = $xmlDoc->createElement('demographics'); $childRoot->appendChild($childElement); // Dinamically set birthdate $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0); $childElement = $xmlDoc->createElement('field'); $childElement->setAttribute('name', 'personal.birthDate'); $childElement->setAttribute('keep', !empty($demographics) ? 'false' : 'true'); $childElement->setAttribute('format', $externaldateformat); $childRoot->appendChild($childElement); $childRoot = $xmlDoc->getElementsByTagName('demographics')->item(0); $childElement = $xmlDoc->createElement('birthdate'); $childElement->nodeValue = !empty($demographics) ? strftime('%Y-%m-%d', $demographics->get_composite('dateofbirth') + 3600) : null; $childRoot->appendChild($childElement); // ======================================= // Dinamically set prefs and language list // ======================================= // Dinamically add mother tongue(s) $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) $l = 0; if (!empty($otherlanguage_list)) { foreach ($otherlanguage_list as $otherlanguage) { // Get otherlanguage's diploma list if ($otherlanguage->id !== false) { $diploma_list = get_records_select_array('artefact_europass_languagediploma', "languageid=?", array($otherlanguage->id)); } else { $diploma_list = array(); } // Get otherlanguage's experience list if ($otherlanguage->id !== false) { $experience_list = get_records_select_array('artefact_europass_languageexperience', "languageid=?", array($otherlanguage->id)); } else { $experience_list = array(); } $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0); // Set foreign language $childElement = $xmlDoc->createElement('field'); $childElement->setAttribute('name', 'foreignLanguageList[' . $l . '].ass'); $childElement->setAttribute('keep', $otherlanguage->language == null ? 'false' : 'true'); $childRoot->appendChild($childElement); // Set foreign language diploma(s) if (!empty($diploma_list)) { for ($d = 0; $d < count($diploma_list); $d++) { $childElement = $xmlDoc->createElement('field'); $childElement->setAttribute('name', 'foreignLanguageList[' . $l . '].diplomaList[' . $d . ']'); $childElement->setAttribute('keep', 'true'); $childRoot->appendChild($childElement); } } // Set foreign language experience(s) if (!empty($experience_list)) { for ($e = 0; $e < count($experience_list); $e++) { $childElement = $xmlDoc->createElement('field'); $childElement->setAttribute('name', 'foreignLanguageList[' . $l . '].experienceList[' . $e . ']'); $childElement->setAttribute('keep', 'true'); $childRoot->appendChild($childElement); $childElement = $xmlDoc->createElement('field'); $childElement->setAttribute('name', 'foreignLanguageList[' . $l . '].experienceList[' . $e . '].period'); $childElement->setAttribute('format', $externaldateformat); $childRoot->appendChild($childElement); } } // Dinamically set data for each foreign language $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); // language levels $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); } // language diploma list $childElement = $xmlDoc->createElement('diplomalist'); $childRoot->appendChild($childElement); //language experience list $childElement = $xmlDoc->createElement('experiencelist'); $childRoot->appendChild($childElement); // ----------------------------- // language diploma list entries // ----------------------------- $parentRoot = $xmlDoc->getElementsByTagName('diplomalist')->item($l); if (!empty($diploma_list)) { foreach ($diploma_list as $diploma) { $parentElement = $xmlDoc->createElement('diploma'); $parentRoot->appendChild($parentElement); $childRoot = $parentRoot->lastChild; // diploma title $childElement = $xmlDoc->createElement('title'); $childElement->nodeValue = valid_xml_string($diploma->certificate); $childRoot->appendChild($childElement); // diploma awarding body $childElement = $xmlDoc->createElement('awardingBody'); $childElement->nodeValue = $showHTML ? replacehtmlchars(nl2br($diploma->awardingbody)) : valid_xml_string($diploma->awardingbody); // Execute nl2br transformation for HTML display... $childRoot->appendChild($childElement); // diploma date $childElement = $xmlDoc->createElement('date'); $childRoot->appendChild($childElement); $grandchildRoot = $childRoot->firstChild->nextSibling->nextSibling; if ($diploma->certificatedate != null) { if (date('Y', strtotime($diploma->certificatedate)) != null) { $grandchildElement = $xmlDoc->createElement('year'); $grandchildElement->nodeValue = date('Y', strtotime($diploma->certificatedate)); $grandchildRoot->appendChild($grandchildElement); } if (date('m', strtotime($diploma->certificatedate)) != null) { $grandchildElement = $xmlDoc->createElement('month'); $grandchildElement->nodeValue = '--' . date('m', strtotime($diploma->certificatedate)); $grandchildRoot->appendChild($grandchildElement); } if (date('d', strtotime($diploma->certificatedate)) != null) { $grandchildElement = $xmlDoc->createElement('day'); $grandchildElement->nodeValue = '---' . date('d', strtotime($diploma->certificatedate)); $grandchildRoot->appendChild($grandchildElement); } } // diploma level $childElement = $xmlDoc->createElement('level'); $childElement->nodeValue = strtolower($diploma->europeanlevel); $childRoot->appendChild($childElement); } } // -------------------------------- // language experience list entries // -------------------------------- $parentRoot = $xmlDoc->getElementsByTagName('experiencelist')->item($l); if (!empty($experience_list)) { foreach ($experience_list as $experience) { $parentElement = $xmlDoc->createElement('experience'); $parentRoot->appendChild($parentElement); $childRoot = $parentRoot->lastChild; // experience period $childElement = $xmlDoc->createElement('period'); $childRoot->appendChild($childElement); // experience period - from $grandchildRoot = $childRoot->firstChild; $grandchildElement = $xmlDoc->createElement('from'); $grandchildRoot->appendChild($grandchildElement); $grandgrandchildRoot = $grandchildRoot->firstChild; if ($experience->startdate != null) { if (date('Y', strtotime($experience->startdate)) != null) { $grandgrandchildElement = $xmlDoc->createElement('year'); $grandgrandchildElement->nodeValue = date('Y', strtotime($experience->startdate)); $grandgrandchildRoot->appendChild($grandgrandchildElement); } if (date('m', strtotime($experience->startdate)) != null) { $grandgrandchildElement = $xmlDoc->createElement('month'); $grandgrandchildElement->nodeValue = '--' . date('m', strtotime($experience->startdate)); $grandgrandchildRoot->appendChild($grandgrandchildElement); } if (date('d', strtotime($experience->startdate)) != null) { $grandgrandchildElement = $xmlDoc->createElement('day'); $grandgrandchildElement->nodeValue = '---' . date('d', strtotime($experience->startdate)); $grandgrandchildRoot->appendChild($grandgrandchildElement); } } // experience period - to $grandchildElement = $xmlDoc->createElement('to'); $grandchildRoot->appendChild($grandchildElement); $grandgrandchildRoot = $grandchildRoot->firstChild->nextSibling; if ($experience->enddate != null) { if (date('Y', strtotime($experience->enddate)) != null) { $grandgrandchildElement = $xmlDoc->createElement('year'); $grandgrandchildElement->nodeValue = date('Y', strtotime($experience->enddate)); $grandgrandchildRoot->appendChild($grandgrandchildElement); } if (date('m', strtotime($experience->enddate)) != null) { $grandgrandchildElement = $xmlDoc->createElement('month'); $grandgrandchildElement->nodeValue = '--' . date('m', strtotime($experience->enddate)); $grandgrandchildRoot->appendChild($grandgrandchildElement); } if (date('d', strtotime($experience->enddate)) != null) { $grandgrandchildElement = $xmlDoc->createElement('day'); $grandgrandchildElement->nodeValue = '---' . date('d', strtotime($experience->enddate)); $grandgrandchildRoot->appendChild($grandgrandchildElement); } } // experience description $childElement = $xmlDoc->createElement('description'); $childElement->nodeValue = $showHTML ? replacehtmlchars(nl2br($experience->description)) : valid_xml_string($experience->description); $childRoot->appendChild($childElement); } } $l++; } } // =================================== // Dinamically set prefs (grid option) // =================================== $childRoot = $xmlDoc->getElementsByTagName('prefs')->item(0); $childElement = $xmlDoc->createElement('field'); $childElement->setAttribute('name', 'grid'); $childElement->setAttribute('keep', 'true'); $childRoot->appendChild($childElement); // ================================ // Return dinamically generated XML // ================================ return $xmlDoc->saveXML(); }
/** * Return a list of available languages * */ function get_languages() { static $langs = array(); if (!$langs) { foreach (language_get_searchpaths() as $searchpath) { $langbase = $searchpath . 'lang/'; if ($langdir = @opendir($langbase)) { while (false !== ($subdir = readdir($langdir))) { if (preg_match('/\\.utf8$/', $subdir) && is_dir($langbase . $subdir)) { $langfile = $langbase . $subdir . '/langconfig.php'; if (is_readable($langfile)) { if ($langname = get_string_from_file('thislanguage', $langfile)) { $langs[$subdir] = $langname; } } } } closedir($langdir); asort($langs); } else { log_warn('Unable to read language directory ' . $langbase); } } } return $langs; }
/** * Returns a localized string. * * Returns the translated string specified by $identifier as * for $module. Uses the same format files as STphp. * $a is an object, string or number that can be used * within translation strings * * eg "hello \$a->firstname \$a->lastname" * or "hello \$a" * * If you would like to directly echo the localized string use * the function {@link print_string()} * * Example usage of this function involves finding the string you would * like a local equivalent of and using its identifier and module information * to retrive it.<br/> * If you open moodle/lang/en/moodle.php and look near line 1031 * you will find a string to prompt a user for their word for student * <code> * $string['wordforstudent'] = 'Your word for Student'; * </code> * So if you want to display the string 'Your word for student' * in any language that supports it on your site * you just need to use the identifier 'wordforstudent' * <code> * $mystring = '<strong>'. get_string('wordforstudent') .'</strong>'; or * </code> * If the string you want is in another file you'd take a slightly * different approach. Looking in moodle/lang/en/calendar.php you find * around line 75: * <code> * $string['typecourse'] = 'Course event'; * </code> * If you want to display the string "Course event" in any language * supported you would use the identifier 'typecourse' and the module 'calendar' * (because it is in the file calendar.php): * <code> * $mystring = '<h1>'. get_string('typecourse', 'calendar') .'</h1>'; * </code> * * As a last resort, should the identifier fail to map to a string * the returned string will be [[ $identifier ]] * * @uses $CFG * @param string $identifier The key identifier for the localized string * @param string $module The module where the key identifier is stored, usually expressed as the filename in the language pack without the .php on the end but can also be written as mod/forum or grade/export/xls. If none is specified then moodle.php is used. * @param mixed $a An object, string or number that can be used * within translation strings * @param array $extralocations An array of strings with other locations to look for string files * @return string The localized string. */ function get_string($identifier, $module = '', $a = NULL, $extralocations = NULL) { global $CFG; /// originally these special strings were stored in moodle.php now we are only in langconfig.php $langconfigstrs = array('alphabet', 'backupnameformat', 'decsep', 'firstdayofweek', 'listsep', 'locale', 'localewin', 'localewincharset', 'oldcharset', 'parentlanguage', 'strftimedate', 'strftimedateshort', 'strftimedatetime', 'strftimedaydate', 'strftimedaydatetime', 'strftimedayshort', 'strftimedaytime', 'strftimemonthyear', 'strftimerecent', 'strftimerecentfull', 'strftimetime', 'thischarset', 'thisdirection', 'thislanguage', 'strftimedatetimeshort', 'thousandssep'); $filetocheck = 'langconfig.php'; $defaultlang = 'en_utf8'; if (in_array($identifier, $langconfigstrs)) { $module = 'langconfig'; //This strings are under langconfig.php for 1.6 lang packs } $lang = current_language(); if ($module == '') { $module = 'moodle'; } /// If the "module" is actually a pathname, then automatically derive the proper module name if (strpos($module, '/') !== false) { $modulepath = split('/', $module); switch ($modulepath[0]) { case 'mod': $module = $modulepath[1]; break; case 'blocks': case 'block': $module = 'block_' . $modulepath[1]; break; case 'enrol': $module = 'enrol_' . $modulepath[1]; break; case 'format': $module = 'format_' . $modulepath[1]; break; case 'grade': $module = 'grade' . $modulepath[1] . '_' . $modulepath[2]; break; } } /// if $a happens to have % in it, double it so sprintf() doesn't break if ($a) { $a = clean_getstring_data($a); } /// Define the two or three major locations of language strings for this module $locations = array(); if (!empty($extralocations)) { // Calling code has a good idea where to look if (is_array($extralocations)) { $locations += $extralocations; } else { if (is_string($extralocations)) { $locations[] = $extralocations; } else { debugging('Bad lang path provided'); } } } if (isset($CFG->running_installer)) { $module = 'installer'; $filetocheck = 'installer.php'; $locations[] = $CFG->dirroot . '/install/lang/'; $locations[] = $CFG->dataroot . '/lang/'; $locations[] = $CFG->dirroot . '/lang/'; $defaultlang = 'en_utf8'; } else { $locations[] = $CFG->dataroot . '/lang/'; $locations[] = $CFG->dirroot . '/lang/'; } /// Add extra places to look for strings for particular plugin types. $rules = places_to_search_for_lang_strings(); $exceptions = $rules['__exceptions']; unset($rules['__exceptions']); if (!in_array($module, $exceptions)) { $dividerpos = strpos($module, '_'); if ($dividerpos === false) { $type = ''; $plugin = $module; } else { $type = substr($module, 0, $dividerpos + 1); $plugin = substr($module, $dividerpos + 1); } if ($module == 'local') { $locations[] = $CFG->dirroot . '/local/lang/'; } if (!empty($rules[$type])) { foreach ($rules[$type] as $location) { $locations[] = $CFG->dirroot . "/{$location}/{$plugin}/lang/"; } } } /// First check all the normal locations for the string in the current language $resultstring = ''; foreach ($locations as $location) { $locallangfile = $location . $lang . '_local' . '/' . $module . '.php'; //first, see if there's a local file if (file_exists($locallangfile)) { if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { if (eval($result) === FALSE) { trigger_error('Lang error: ' . $identifier . ':' . $locallangfile, E_USER_NOTICE); } return $resultstring; } } //if local directory not found, or particular string does not exist in local direcotry $langfile = $location . $lang . '/' . $module . '.php'; if (file_exists($langfile)) { if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { if (eval($result) === FALSE) { trigger_error('Lang error: ' . $identifier . ':' . $langfile, E_USER_NOTICE); } return $resultstring; } } } /// If the preferred language was English (utf8) we can abort now /// saving some checks beacuse it's the only "root" lang if ($lang == 'en_utf8') { return '[[' . $identifier . ']]'; } /// Is a parent language defined? If so, try to find this string in a parent language file foreach ($locations as $location) { $langfile = $location . $lang . '/' . $filetocheck; if (file_exists($langfile)) { if ($result = get_string_from_file('parentlanguage', $langfile, "\$parentlang")) { if (eval($result) === FALSE) { trigger_error('Lang error: ' . $identifier . ':' . $langfile, E_USER_NOTICE); } if (!empty($parentlang)) { // found it! //first, see if there's a local file for parent $locallangfile = $location . $parentlang . '_local' . '/' . $module . '.php'; if (file_exists($locallangfile)) { if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { if (eval($result) === FALSE) { trigger_error('Lang error: ' . $identifier . ':' . $locallangfile, E_USER_NOTICE); } return $resultstring; } } //if local directory not found, or particular string does not exist in local direcotry $langfile = $location . $parentlang . '/' . $module . '.php'; if (file_exists($langfile)) { if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { eval($result); return $resultstring; } } } } } } /// Our only remaining option is to try English foreach ($locations as $location) { $locallangfile = $location . $defaultlang . '_local/' . $module . '.php'; //first, see if there's a local file if (file_exists($locallangfile)) { if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { eval($result); return $resultstring; } } //if local_en not found, or string not found in local_en $langfile = $location . $defaultlang . '/' . $module . '.php'; if (file_exists($langfile)) { if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { eval($result); return $resultstring; } } } /// And, because under 1.6 en is defined as en_utf8 child, me must try /// if it hasn't been queried before. if ($defaultlang == 'en') { $defaultlang = 'en_utf8'; foreach ($locations as $location) { $locallangfile = $location . $defaultlang . '_local/' . $module . '.php'; //first, see if there's a local file if (file_exists($locallangfile)) { if ($result = get_string_from_file($identifier, $locallangfile, "\$resultstring")) { eval($result); return $resultstring; } } //if local_en not found, or string not found in local_en $langfile = $location . $defaultlang . '/' . $module . '.php'; if (file_exists($langfile)) { if ($result = get_string_from_file($identifier, $langfile, "\$resultstring")) { eval($result); return $resultstring; } } } } return '[[' . $identifier . ']]'; // Last resort }
function game_get_string_lang($identifier, $module, $lang) { global $CFG; $langfile = "{$CFG->dirroot}/mod/game/lang/{$lang}/game.php"; if ($result = get_string_from_file($identifier, $langfile, "\$ret")) { eval($result); if ($ret != '') { return $ret; } } return get_string($identifier, $module); }
function game_get_string_lang($identifier, $module, $lang) { global $CFG; $langfile = "{$CFG->dirroot}/mod/game/lang/{$lang}/game.php"; $result = get_string_from_file($identifier, $langfile, "\$ret"); if ($result != '') { $pos = strpos($result, '='); if ($pos > 0) { $result = substr($result, $pos + 1); $pos = strpos($result, "'"); if ($pos > 0) { $result = substr($result, $pos + 1); $pos = strpos($result, "'"); if ($pos > 0) { $result = substr($result, 0, $pos); } } } } if ($result != '') { return $result; } else { return get_string($identifier, $module); } }
function tao_header_image_location($image) { global $CFG; $dirbase = $CFG->dirroot . '/theme/' . current_theme() . '/pix/headers/'; $urlbase = $CFG->wwwroot . '/theme/' . current_theme() . '/pix/headers/'; $datarootbase = $CFG->dataroot . '/' . SITEID . '/pix/headers/'; $datarootfilebase = SITEID . '/pix/headers/'; $lang = current_language(); // check dataroot first... if (file_exists($datarootbase . $lang . '/' . $image)) { require_once $CFG->libdir . '/filelib.php'; return get_file_url($datarootfilebase . $lang . '/' . $image); } if (file_exists($dirbase . $lang . '/' . $image)) { return $urlbase . $lang . '/' . $image; } // go walking language tree to find one while (true) { $parent = false; $langconfig = $CFG->dataroot . '/lang/' . $lang . '/langconfig.php'; if (!file_exists($langconfig)) { $langconfig = $CFG->dirroot . '/lang/' . $lang . '/langconfig.php'; if (!file_exists($langfile)) { return false; // nothing we can do } } get_string_from_file('parentlanguage', $langconfig, "\$parent"); if ($parent) { // check dataroot first... if (file_exists($datarootbase . $parent . '/' . $image)) { require_once $CFG->libdir . '/filelib.php'; return get_file_url($datarootfilebase . $parent . '/' . $images); } if (file_exists($dirbase . $parent . '/' . $image)) { return $urlbase . $parent . '/' . $image; } else { // loop through again and look for another parent } } else { return $urlbase . 'en_utf8/' . $image; } } }
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/'); }
public function get_survey_info_from_xml($filename = null) { if ($filename == null) { $filename = $this->get('title'); } $xmlDoc = new DOMDocument('1.0', 'UTF-8'); // 'title' field in 'artefact' table contains the survey xml filename... $ch = curl_init(get_config('wwwroot') . 'artefact/survey/surveys/' . $filename); # Return http response in string curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $loaded = $xmlDoc->loadXML(curl_exec($ch)); // Get survey copyright if ($xmlDoc->getElementsByTagName('copyright')->item(0) != null) { $copyright = $xmlDoc->getElementsByTagName('copyright')->item(0)->getAttribute(self::get_default_lang($filename)); } else { $copyright = ''; } // Get survey description if ($xmlDoc->getElementsByTagName('description')->item(0) != null) { $description = $xmlDoc->getElementsByTagName('description')->item(0)->getAttribute(self::get_default_lang($filename)); // Replace {image:pict.jpg} in responses with proper <img src="pict.jpg"> tag... $description = preg_replace('#{image:([a-zA-Z0-9\\.\\_\\-\\~]+)}#', '<img src="' . get_config('wwwroot') . 'artefact/survey/surveys/' . substr($filename, 0, -4) . '/$1">', $description); } else { $description = ''; } // Get survey instructions if ($xmlDoc->getElementsByTagName('instructions')->item(0) != null) { $instructions = $xmlDoc->getElementsByTagName('instructions')->item(0)->getAttribute(self::get_default_lang($filename)); } else { $instructions = ''; } // Get survey url $surveyurl = $xmlDoc->getElementsByTagName('survey')->item(0)->getAttribute('url'); $instructions_title = ''; $lang = self::get_default_lang($filename); if ($lang == 'en.utf8') { $instructions_title = get_string_from_file('instructions', get_config('docroot') . 'artefact/survey/lang/en.utf8/artefact.survey.php'); } else { if (file_exists(get_config('dataroot') . 'langpacks/' . $lang . '/artefact/survey/lang/' . $lang . '/artefact.survey.php')) { $instructions_title = get_string_from_file('instructions', get_config('dataroot') . 'langpacks/' . $lang . '/artefact/survey/lang/' . $lang . '/artefact.survey.php'); } else { $instructions_title = get_string_from_file('instructions', get_config('docroot') . 'artefact/survey/lang/' . $lang . '/artefact.survey.php'); } } $html = ''; if (!empty($description)) { $html .= '<div class="description">' . html_entity_decode($copyright) . '</div>'; } if (!empty($surveyurl)) { $html .= '<div class="description"><a href="' . $surveyurl . '" target="_blank">' . $surveyurl . '</a></div>'; } $html .= '<p>' . html_entity_decode($description) . '</p>'; $html .= '<h3>' . $instructions_title . '</h3>'; $html .= '<p>' . html_entity_decode($instructions) . '</p>'; return $html; }