describeType(get_input('schema')); $new_sub_list = array(); $td = $fulltd->listFields(); $rawLangs = get_input('langs'); $rid = get_input('resourceid'); $suitable_for_student = get_input('suitable_for_student'); $suitable_for_student = $suitable_for_student[0]; if (!$suitable_for_student) $suitable_for_student = 0; $competition_resource = get_input('competition_resource'); $competition_resource = $competition_resource[0]; if (!$competition_resource) $competition_resource = 0; $tiger_leap_supported = get_input('tiger_leap_supported'); $tiger_leap_supported = $tiger_leap_supported[0]; if (!$tiger_leap_supported) $tiger_leap_supported = 0; $langs = array(); foreach($rawLangs as $lang) { foreach($td as $field) { $name = $field['@attributes']['name']; $multi = $field['@attributes']['multiLingual']; if ( $multi == '1' ) { $fval = get_input($lang.'_'.$name); if ( trim($fval) ) { if ( !in_array($lang, $langs) ) { $langs[] = $lang; } } } } } if ( count($langs) == 0 ) { // XXX: TODO: what should we do here? /*translation:You must provide a title in atleast on language for resource*/ system_messages(elgg_echo("koolielu:resource:must_have_title"), "errors"); $tourl = $CONFIG->wwwroot . "pg/waramu/edit"; if ( $rid ) $tourl .= "/".$rid; return forward($tourl); } function collect(&$doc, &$xml, $td, $langs=null, $sublist) { foreach($td as $field) { if ( $field['@attributes']['autovalue'] == '1') { continue; } $name = $field['@attributes']['name']; $multi = $field['@attributes']['multiLingual']; $ftype = $field['@attributes']['type']; if ( $multi != '1' ) { $fval = get_input($name); $el = $doc->createElement($name); $xml->appendChild($el); if ( $name == 'items' ) { foreach($fval as $fref) { $fre = trim($fref); if (!$fre) continue; $elval = $doc->createElement("value"); $elval->setAttribute("position", get_input('pos_'.$fre)); $elval->appendChild($doc->createTextNode($fre)); $el->appendChild($elval); } } else if ( $ftype == 'MultiString' || $ftype == 'MultiInteger' ) { if ( is_array($fval) ) { $fvs = $fval; } else { $fvs = split(',', $fval); } foreach($fvs as $fs) { $v = trim($fs); if (!$v) continue; if ($name == 'curriculumSubject') { $valns = split(',', $fs); $v = trim($valns[1]); $elval = $doc->createElementNS($valns[0], 'value'); } else { $elval = $doc->createElement("value"); } $elval->appendChild($doc->createTextNode($v)); $el->appendChild($elval); if ($name == 'curriculumSubject') { $sublist[] = $fs; } } } else { $el->appendChild($doc->createTextNode($fval)); } } else { foreach ($langs as $lang ) { $fval = get_input($lang.'_'.$name); $el = $doc->createElement($name); $el->setAttribute("lang", $lang); $xml->appendChild($el); if ( $name == "keywords" && !$fval) { $elval = $doc->createElement("value"); $elval->appendChild($doc->createTextNode($fval)); $el->appendChild($elval); } else if ( $ftype == 'MultiString' || $ftype == 'MultiInteger' ) { if ( is_array($fval) ) { $fvs = $fval; } else { $fvs = split(',', $fval); } foreach($fvs as $fs) { $v = trim($fs); if (!$v) continue; $elval = $doc->createElement("value"); $elval->appendChild($doc->createTextNode($v)); $el->appendChild($elval); } } else { $el->appendChild($doc->createTextNode($fval)); } } } } } $doc = new DOMDocument("1.0", "UTF-8"); $doc->formatOutput = true; $rootel = $doc->createElement("response"); $doc->appendChild($rootel); $data = $doc->createElementNS(get_input('schema'), "data"); $rootel->appendChild($data); $schem = $doc->createElement("schema"); $schemval = $doc->createTextNode(get_input('schema')); $schem->appendChild($schemval); $rootel->appendChild($schem); collect($doc, $data, $td, $langs, &$new_sub_list); $tinyxml = '<'.'?'.'xml version="1.0" encoding="UTF-8"'.'?'.'>' . $doc->saveXML($data); $xml = $doc->saveXML(); $sub_list = array(); foreach($new_sub_list as $nso) { $vals = split(',', $nso); $msid = getSubjectID(getCurriculumMainSubjectNS($vals[0], $vals[1])); //TODO: getSubjectID -> getSubjectIDNS if (!in_array($msid, $sub_list)) { $sub_list[] = $msid; } } $acl = buildACL($sub_list); if ( !$rid ) { /*translation:Learning resource is added but moderator has to approve it before publishing.*/ system_message(elgg_echo("koolielu:resource:added_and_pending")); $kk = $w->newResource($au, $tinyxml, get_input('reserved_id')); // TODO: check kk and possible errors // this doesn't work very well... if ( !is_int($kk) ) { // meaning we got uid. $rid = $kk; $aclstat = $w->setACL($au, $kk, $acl); } else { print "error:".$kk; } } else { $res = $w->updateResource($au, $rid, $tinyxml); // update collection tags $collections = get_entities_from_metadata("resources", $rid, "object", "collection"); foreach ($collections as $collection) { $collection->needs_update = 1; $collection->save(); //updateCollectionTags($collection); } // TODO: handle response here $qd = waramu_isInLocalQueue($rid); if ($qd) { $subs = ",".implode(',', $sub_list).","; update_data("UPDATE {$CONFIG->dbprefix}koolielu_waramu_queue SET subjects='$subs' WHERE waramu_id='$rid'"); } } if ( $rid ) { $aclstat = $w->setACL($au, $rid, $acl); $w->createOrUpdateAnnotation($au, $rid, array('name'=>'keecm', 'value'=>$competition_resource), $acl); $w->createOrUpdateAnnotation($au, $rid, array('name'=>'thsupport', 'value'=>$tiger_leap_supported), $acl); $w->createOrUpdateAnnotation($au, $rid, array('name'=>'indpwork', 'value'=>$suitable_for_student), $acl); } forward("pg/waramu/view/".$rid); ?>