Exemplo n.º 1
0
function dbInsert($data, $table)
{
    if ($table == 'keywordgroup') {
        $sql = "insert into `keywordgroup`(`id`,`description`,`keywords`) values('" . $data['_attr_id'] . "', '" . mysql_escape_string($data['Description']) . "', '" . mysql_escape_string(json_encode(Web_Common_XMLTools::getXMLTreeArray($data, "Keyword"))) . "')";
    } else {
        if ($table == 'indexgroup') {
            $sql = "insert into `indexgroup`(`id`,`description`,`indexs`) values('" . $data['_attr_id'] . "', '" . mysql_escape_string($data['Description']) . "', '" . mysql_escape_string(json_encode($data['Index'])) . "')";
        } else {
            if ($table == 'syntactic') {
                $syntacticElement = json_encode($data['SyntacticElement']);
                $semanticArgument = isset($data['SemanticBind']['SemanticArgumenmt']) ? json_encode($data['SemanticBind']['SemanticArgument']) : "[]";
                $semanticArgumentDependency = isset($data['SemanticBind']['SemanticArgumentDependency']) ? json_encode($data['SemanticBind']['SemanticArgumentDependency']) : "[]";
                $modifier = isset($data['modifiler']) ? json_encode($data['moidifiler']) : "[]";
                $syntacticElement = json_encode($data['SyntacticElement']);
                $sql = "insert into `syntactic`(`id`,`semanticId`,`syntacticElement`,`semanticArgument`,`semanticArgumentDependency`,`modifier`,`description`) " . "values('" . $data['id'] . "','" . $data['SemanticBind']['BindTo'] . "','" . mysql_escape_string($syntacticElement) . "','" . mysql_escape_string($semanticArgument) . "','" . mysql_escape_string($semanticArgumentDependency) . "','" . mysql_escape_string($modifier) . "','" . mysql_escape_string($data['Description']) . "')";
                //die("$sql\n");
            } else {
                if ($table == 'semantic') {
                    $dependencyArgument = "[]";
                    $independencyArgument = "[]";
                    $argument = "[]";
                    $isKeyValue = "";
                    $internalRepresentation = "[]";
                    $uiRepresentation = "";
                    $chineseRepresentation = "";
                    $argument = json_encode($data['Argument']);
                    if (isset($data['ArgumenmtDependency'])) {
                        $ad = $data['ArgumentDependency'];
                        $dependencyArgument = isset($ad['DependencyArgumenmt']) ? json_encode($ad['DependencyArgument']) : "[]";
                        $independencyArgument = isset($ad['IndependencyArgumenmt']) ? json_encode($ad['IndependencyArgument']) : "[]";
                    }
                    if (isset($data['IsKeyValue'])) {
                        $isKeyValue = $data['IsKeyValue'];
                    }
                    if (isset($data['InternalRepresentation'])) {
                        $internalRepresentation = json_encode($data['InternalRepresentation']);
                    }
                    if (isset($data['UIRepresentation'])) {
                        $uiRepresentation = $data['UIRepresentation'];
                    }
                    if (isset($data['ChineseRepresentation'])) {
                        $chineseRepresentation = $data['ChineseRepresentation'];
                    }
                    $sql = "insert into `semantic`(`id`,`argument`,`argumentDependency`,`argumentIndependency`,`isKeyValue`,`internalRepresentation`, `uiRepresentation`,`chineseRepresentation`,`description`) " . "values('" . $data['id'] . "','" . mysql_escape_string($argument) . "','" . mysql_escape_string($argumentDependency) . "','" . mysql_escape_string($argumentIndependency) . "','" . mysql_escape_string($isKeyValue) . "','" . mysql_escape_string($internalRepresentation) . "','" . mysql_escape_string($uiRepresentation) . "','" . mysql_escape_string($chineseRepresentation) . "','" . mysql_escape_string($data['Description']) . "')";
                    //die("$sql\n");
                } else {
                    echo "not insert\n";
                    return false;
                }
            }
        }
    }
    echo "{$sql}\n";
    if (!mysql_query($sql)) {
        echo mysql_error();
        echo "\n";
    }
}
Exemplo n.º 2
0
 public static function DomToArray($root, $compat = false)
 {
     $result = array();
     if ($root->hasAttributes()) {
         $attrs = $root->attributes;
         foreach ($attrs as $i => $attr) {
             $result["_attr_" . $attr->name] = $attr->value;
         }
     }
     $children = $root->childNodes;
     $childtype = array();
     for ($i = 0; $i < $children->length; $i++) {
         $child = $children->item($i);
         if ($child->nodeType == XML_TEXT_NODE) {
             if (isset($result['_value'])) {
                 $result['_value'] .= $child->nodeValue;
             } else {
                 $result['_value'] = $child->nodeValue;
             }
         } else {
             if (!isset($result[$child->nodeName])) {
                 $childtype[$child->nodeName] = 1;
                 $result[$child->nodeName] = Web_Common_XMLTools::DomToArray($child, $compat);
             } else {
                 if ($childtype[$child->nodeName] == 1) {
                     $tmp = $result[$child->nodeName];
                     $result[$child->nodeName] = array($tmp);
                     $childtype[$child->nodeName] = 2;
                     $result['__xml_array__items__'][$child->nodeName] = 1;
                 }
                 $result[$child->nodeName][] = Web_Common_XMLTools::DomToArray($child, $compat);
             }
         }
     }
     if ($compat === true) {
         if (count($result) == 1 && isset($result['_value'])) {
             $result = $result['_value'];
         }
         if (count($result) == 0) {
             $result = "";
         }
     }
     return $result;
 }