<p>
<br />
<?php
if(!user_access('toponimo admin')){
drupal_access_denied();
exit;
}
if(isset($_GET['ekin'])){
// doit();
$output .= '<p>Partzelak inportatu dira.</p>';
} else {
print '<p>Partzelak nodo bihurtu: '.l('ekin', $_GET['q'], array('query' => 'ekin=1')).'</p>';
}
function doit(){
$tree = taxonomy_get_tree(5);
foreach($tree as $term){
$auzo[$term->name] = $term->tid;
}
$node = node_load(arg(1));
$file = array_pop($node->files);
$src = file_get_contents($file->filepath);
$rows = explode("\n", $src);
// $rows = array_slice($rows, 0, 1);
foreach($rows as $row){
$f = explode("\t", $row);
$node = (object) array('status' => 1, 'type' => 'partzela', 'promote' => 0, 'sticky' => 0, 'uid' => 1, 'comment' => 2, 'title' => $f[2], 'body' => $row);
$extra = db_fetch_object(db_query('SELECT vertex, erreziboa FROM topo_katastroa WHERE ref = "%s"', $f[0]));
$node->field_ref = array(array('value' => $f[0]));
$node->field_lekuizen = array(array('value' => $f[3]));
$node->field_lursail = array(array('value' => $f[4]));
$node->field_azalera = array(array('value' => $f[5]));
$node->field_koordenatu = array(array('value' => $extra->vertex));
$node->field_errezibo = array(array('value' => empty($extra->erreziboa) ? $f[1] : $extra->erreziboa));
$node->field_finka = array(array('value' => $f[7]));
$node->taxonomy = isset($auzo[$f[6]]) ? array($auzo[$f[6]]) : array();
node_save($node);
print l($node->title, "node/$node->nid") . '<br />';
}
}
?></p>