function addSubTree($rows, $i, $left)
 {
     $nodeArray = array();
     $addNewNode = true;
     for ($j = $i; $j < count($rows); $j++) {
         $row = $rows[$j];
         $pos = intval($row["layer_pos"]);
         $parent = $row["layer_parent"] !== "" ? intval($row["layer_parent"]) : null;
         // first node of subtree
         if ($addNewNode) {
             $nodeArray[] = createNode($left, null, $row);
             $addNewNode = false;
         } else {
             // new sub tree
             if ($parent === $nodeArray[count($nodeArray) - 1]["pos"]) {
                 $addedNodeArray = addSubTree($rows, $j, ++$left);
                 $nodeArray[count($nodeArray) - 1]["right"] = $nodeArray[count($nodeArray) - 1]["left"] + 2 * count($addedNodeArray) + 1;
                 $left = $nodeArray[count($nodeArray) - 1]["right"] + 1;
                 $nodeArray = array_merge($nodeArray, $addedNodeArray);
                 $j += count($addedNodeArray) - 1;
                 $addNewNode = true;
             } elseif ($parent === $nodeArray[count($nodeArray) - 1]["parent"]) {
                 $nodeArray[count($nodeArray) - 1]["right"] = ++$left;
                 $nodeArray[] = createNode(++$left, null, $row);
             }
         }
     }
     if (is_null($nodeArray[count($nodeArray) - 1]["right"])) {
         $nodeArray[count($nodeArray) - 1]["right"] = ++$left;
     }
     return $nodeArray;
 }
Example #2
0
function generate_xml($real_id)
{
    $realty = new Realty();
    $realty->retrieve($real_id);
    $real_id_out = $realty->id;
    switch ($realty->type_of_realty) {
        case 'living':
            /// Россия
            if ($realty->address_country == 'Россия') {
                // Москва   //todo Новостройка, долей во вторичной недвижимости, гаражи
                if ($realty->kind_of_realty == 'flat' and ($realty->address_city == 'Москва г' or $realty->address_region == 'Московская обл')) {
                    if ($realty->operation == 'buying') {
                        $type_realty = 'flats';
                        $type_of_building = 'flats';
                    } elseif ($realty->operation == 'rent') {
                        $type_realty = 'rent';
                        $type_of_building = 'rent';
                    }
                } elseif ($realty->kind_of_realty == 'flat' and ($realty->address_city == 'Санкт-Петербург г' or $realty->address_region == 'Ленинградская обл')) {
                    if ($realty->operation == 'buying') {
                        $type_realty = 'flats_spb';
                        $type_of_building = 'flats';
                    } elseif ($realty->operation == 'rent') {
                        $type_realty = 'rent_spb';
                        $type_of_building = 'rent';
                    }
                } else {
                    $type_realty = 'region';
                    $type_of_building = 'flats';
                }
            } else {
                $type_realty = 'foreign';
                $type_of_building = 'foreign';
            }
            if ($type_realty == 'foreign') {
                $offer_text = 'obj';
            } else {
                $offer_text = 'flat';
            }
            if ($realty->kind_of_realty == 'house' and $realty->address_region == 'Московская обл') {
                $type_realty = 'country_house';
                $type_of_building = 'country_houses';
                $offer_text = 'country_house';
            } else {
                if ($realty->kind_of_realty == 'house' and $realty->address_region == 'Ленинградская обл') {
                    $type_realty = 'country_house_spb';
                    $type_of_building = 'country_houses';
                    $offer_text = 'country_house';
                } else {
                    if ($realty->kind_of_realty == 'house' and $realty->address_region != 'Ленинградская обл' and $realty->address_region != 'Московская обл') {
                        $type_realty = 'country_house_region';
                        $type_of_building = 'country_houses_region';
                        $offer_text = 'country_houses_region';
                    }
                }
            }
            break;
        case 'not_living':
            // Россия
            if ($realty->address_country == 'Россия') {
                // Москва
                if ($realty->address_city == 'Москва г' or $realty->address_region == 'Московская обл') {
                    $type_realty = 'commercial';
                    $offer_text = 'commercial';
                    $type_of_building = 'commercials';
                } elseif ($realty->address_city == 'Санкт-Петербург г' or $realty->address_region == 'Ленинградская обл') {
                    $type_realty = 'commercial_spb';
                    $offer_text = 'commercial';
                    $type_of_building = 'commercials';
                } else {
                    $type_realty = 'region_commercial';
                    $offer_text = 'region_commercial';
                    $type_of_building = 'region_commercial';
                }
            } else {
                $type_realty = 'foreign_commercial';
                $type_of_building = 'foreign_commercial';
                $offer_text = 'obj';
            }
            break;
        case 'parcel':
            // Россия
            if ($realty->address_country == 'Россия') {
                // Москва
                if ($realty->address_city == 'Москва г' or $realty->address_region == 'Московская обл') {
                    $type_realty = 'county_house';
                } elseif ($realty->address_city == 'Санкт-Петербург г' or $realty->address_region == 'Ленинградская обл') {
                    $type_realty = 'county_house_spb';
                } else {
                    $type_realty = 'county_house_region';
                }
            }
            $offer_text = 'county_house';
            $type_of_building = 'county_houses';
            break;
    }
    if (!file_exists("custom/kXML/xml/{$_REQUEST['module']}/baza/" . $type_realty . ".xml")) {
        //$dom = new DOMDocument('1.0', 'windows-1251');
        $dom = new DOMDocument('1.0', 'UTF-8');
        $root = $dom->appendChild($dom->createElement($type_of_building));
        $root->setAttribute('xsi:noNamespaceSchemaLocation', $type_realty . '.xsd');
        $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
        createNode($dom, $root, $realty, $real_id_out, $type_realty, $offer_text);
    } else {
        //  $dom = new DOMDocument('1.0', 'windows-1251');
        $dom = new DOMDocument('1.0', 'UTF-8');
        //$filestring = file_get_contents('modules/Realty/baza/baza.xml');
        $dom->load("custom/kXML/xml/{$_REQUEST['module']}/baza/" . $type_realty . ".xml", LIBXML_NOBLANKS);
        //$dom->loadXML($filestring);
        $commerce = $dom->documentElement;
        $xpath = new DOMXPath($dom);
        // We starts from the root element
        $query = '//commerce/offer/id[. = "' . $real_id_out . '"]';
        $entries = $xpath->query($query);
        foreach ($entries as $entry) {
            $old = $commerce->removeChild($entry->parentNode);
        }
        $root = $dom->getElementsByTagName($type_of_building)->item(0);
        $root->setAttribute('xsi:noNamespaceSchemaLocation', $type_realty . '.xsd');
        $root->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
        createNode($dom, $root, $realty, $real_id_out, $type_realty, $offer_text);
    }
    $dom->formatOutput = true;
    if ($dom->save("custom/kXML/xml/{$_REQUEST['module']}/baza/" . $type_realty . ".xml")) {
        echo "\n Файл custom/kXML/xml/{$_REQUEST['module']}/baza/" . $type_realty . ".xml успешно сохранён\n ";
    } else {
        echo "\n Ошибка при сохранении файла custom/kXML/xml/{$_REQUEST['module']}/baza/" . $type_realty . ".xml \n ";
    }
}
Example #3
0
 public function updateNodeXML($fileName, $arrInfoNode, $value, $key = 'id')
 {
     $xmlDoc = new DOMDocument();
     $xmlDoc->load($fileName);
     $nodes = $xmlDoc->getElementsByTagName($arrInfoNode['name']);
     if (!$nodes->item(0)) {
         // khong ton tai node nay
         return 0;
     }
     for ($i = $nodes->length - 1; $i >= 0; $i--) {
         if ($nodes->item($i)->getAttribute($key) == $value) {
             $newNode = createNode($xmlDoc, $arrInfoNode['name'], $arrInfoNode['attribute'], $arrInfoNode['value']);
             $nodes->item($i)->parentNode->replaceChild($newNode, $nodes->item($i));
             break;
         }
     }
     $xmlDoc->save($fileName);
     return 1;
 }
 function addSubTree($rows, $i, $left)
 {
     $nodeArray = array();
     $addNewNode = true;
     for ($j = $i; $j < count($rows); $j++) {
         $row = $rows[$j];
         $pos = $j;
         // first node of subtree
         if ($addNewNode) {
             $nodeArray[] = createNode($left, null, $row);
             $addNewNode = false;
         } else {
             $nodeArray[count($nodeArray) - 1]["right"] = ++$left;
             $nodeArray[] = createNode(++$left, null, $row);
         }
     }
     if (is_null($nodeArray[count($nodeArray) - 1]["right"])) {
         $nodeArray[count($nodeArray) - 1]["right"] = ++$left;
     }
     return $nodeArray;
 }
 $customerAddsNode = createNode($domtree, $customerNode, 'CUST_ADDRESSS');
 $customerAddNode = createNode($domtree, $customerAddsNode, 'CUST_ADDRESS');
 $customerSupplsNode = createNode($domtree, $customerNode, 'CUST_SUPPLS');
 for ($i = 1; $i <= 20; $i++) {
     $customerSupplNode = createNode($domtree, $customerSupplsNode, 'CUST_SUPPL');
     $udf_no = $domtree->createAttribute('udf_no');
     $customerSupplNode->appendChild($udf_no);
     $udf_noValue = $domtree->createTextNode($i);
     $udf_no->appendChild($udf_noValue);
     $udf_value = $domtree->createAttribute('udf_value');
     $customerSupplNode->appendChild($udf_value);
     $udf_valueValue = $domtree->createTextNode('');
     $udf_value->appendChild($udf_valueValue);
 }
 $customerCardsNode = createNode($domtree, $customerNode, 'CUST_CRDS');
 $customerTermsNode = createNode($domtree, $customerNode, 'CUST_TERMS');
 /*Customer Node Attributes Starts here*/
 $accept_checks = $domtree->createAttribute('accept_checks');
 $customerNode->appendChild($accept_checks);
 $active = $domtree->createAttribute('active');
 $customerNode->appendChild($active);
 $allow_email = $domtree->createAttribute('allow_email');
 $customerNode->appendChild($allow_email);
 $allow_phone = $domtree->createAttribute('allow_phone');
 $customerNode->appendChild($allow_phone);
 $allow_post = $domtree->createAttribute('allow_post');
 $customerNode->appendChild($allow_post);
 $alternate_id1 = $domtree->createAttribute('alternate_id1');
 $customerNode->appendChild($alternate_id1);
 $alternate_id2 = $domtree->createAttribute('alternate_id2');
 $customerNode->appendChild($alternate_id2);
 $soItem->appendChild($udf_value2);
 $udf_value2Value = $domtree->createTextNode('');
 $udf_value2->appendChild($udf_value2Value);
 $udf_value3 = $domtree->createAttribute('udf_value3');
 $soItem->appendChild($udf_value3);
 $udf_value3Value = $domtree->createTextNode('');
 $udf_value3->appendChild($udf_value3Value);
 $udf_value4 = $domtree->createAttribute('udf_value4');
 $soItem->appendChild($udf_value4);
 $udf_value4Value = $domtree->createTextNode('');
 $udf_value4->appendChild($udf_value4Value);
 $usr_disc_perc = $domtree->createAttribute('usr_disc_perc');
 $soItem->appendChild($usr_disc_perc);
 $usr_disc_percValue = $domtree->createTextNode('0');
 $usr_disc_perc->appendChild($usr_disc_percValue);
 $invnBaseItem = createNode($domtree, $soItem, 'INVN_BASE_ITEM');
 $alu = $domtree->createAttribute('alu');
 $invnBaseItem->appendChild($alu);
 $aluValue = $domtree->createTextNode('');
 $alu->appendChild($aluValue);
 $attr = $domtree->createAttribute('attr');
 $invnBaseItem->appendChild($attr);
 $attrValue = $domtree->createTextNode('RETAIL');
 $attr->appendChild($attrValue);
 $aux1_value = $domtree->createAttribute('aux1_value');
 $invnBaseItem->appendChild($aux1_value);
 $aux1_valueValue = $domtree->createTextNode('');
 $aux1_value->appendChild($aux1_valueValue);
 $aux2_value = $domtree->createAttribute('aux2_value');
 $invnBaseItem->appendChild($aux2_value);
 $aux2_valueValue = $domtree->createTextNode('');
Example #7
0
function addLink($from_struct, $from_object, $to_struct, $to_object)
{
    // <object name="Heater control" id="3" type="linkFrom">T24 45</object>
    global $error;
    // Not possible to link to smae structure
    if ($from_struct == $to_struct) {
        return;
    }
    //echo("Create link: $from_struct,$from_object,$to_struct,$to_object<br>");
    if ($from_struct && $from_object && $to_struct && $to_object) {
        $object_name_from = getObjectName($from_struct, $from_object);
        $object_name_to = getObjectName($to_struct, $to_object);
        //$lid = createNode('generate',$from_struct,$from_object,$object_name_from,$from_object,'linkFrom');
        createNode($from_struct, $from_object, $to_struct, $to_object, 'linkOut');
        $value = $to_struct . " " . $object_name_to . " " . $to_object;
        setNodeValue($from_struct, $from_object, 'type', 'linkFrom', $value);
        // echo("new lid = $lid<br>");
        createNode($to_struct, $to_object, $from_struct, $from_object, 'linkIn');
        $value = $from_struct . " " . $object_name_from . " " . $from_object;
        setNodeValue($to_struct, $to_object, 'type', 'linkTo', $value);
    } else {
        echo "Unable to create link: {$from_struct},{$from_object},{$to_struct},{$to_object}";
    }
}
Example #8
0
<?php

require_once './helper.php';
$template = new DOMDocument();
$template->loadHTMLFile('template.html');
$feed = new DOMDocument();
$feed->load('feed.xml');
$list = $template->getElementById('linklist');
$i = 0;
foreach ($feed->getElementsByTagname('entry') as $entry) {
    $li = $template->createElement('li');
    $list->appendChild($li);
    createNode($template, $li, $entry, !defined('EDIT') && $i++ < 15);
    if (defined('EDIT')) {
        $tags = '';
        $taglist = $entry->getElementsByTagname('category');
        foreach ($taglist as $tagtag) {
            $tags .= $tagtag->firstChild->nodeValue . ', ';
        }
        $div = $template->createElement('div');
        $form = $template->createElement('form');
        $input = $template->createElement('input');
        $input->setAttribute('style', 'width: 400px');
        $input->setAttribute('value', $tags);
        $form->appendChild($input);
        $div->appendChild($form);
        $li->appendChild($div);
    }
}
$container = $template->getElementById('tagcloud');
$list = $feed->getElementsByTagName('category');
Example #9
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
// Konfig laden
require_once 'config.php';
// Funktionen einbinden
require_once 'functions.php';
// Skript initialisieren
require_once 'init.php';
$c = 0;
$nodes = array();
$results = array();
$literals = array();
$nodesJSON = sparqlQuery($nodeQuery);
if ($linkQuery) {
    $linksJSON = sparqlQuery($linkQuery);
}
// Alle Knoten erzeugen
foreach ($nodesJSON['results']['bindings'] as $binding) {
    createNode($binding['nodeuri']['value'], getTitleByUri($binding['nodetitle']['value']), $binding['shape']['value'], $binding['color']['value']);
}
// Alle Links erzeugen
if ($linkQuery) {
    foreach ($linksJSON['results']['bindings'] as $binding) {
        createLink($binding['source']['value'], $binding['target']['value'], getTitleByUri($binding['linktitle']['value']), 10);
    }
}
$results['literals'] = $literals;
echo json_encode($results);