Minor display cleanup
[mirrors/Kyberia-bloodline.git] / scripts / event2node.php
1 #!/usr/local/bin/php
2 <?php
3 require('../config/config.inc');
4 //connecting to database and creating universal $db object
5 require(SYSTEM_ROOT.'/inc/log.inc');
6 require(SYSTEM_ROOT.'/inc/database.inc');
7 require(SYSTEM_ROOT.'/inc/nodes.inc');
8 $db=new CLASS_DATABASE();
9
10 $dir=SYSTEM_ROOT.'/inc/eventz/';
11 $parent_node='1075292';
12 $creator_id='548';
13 $external_link='file://inc/eventz/';
14
15 function scandir($dir) {
16 $dir_open = @ opendir($dir);
17 if (! $dir_open)
18 return false;
19
20 while (($dir_content = readdir($dir_open)) !== false) {
21 if ($dir_content != "." OR $dir_content !=".." ) $files[] = $dir_content;
22 }
23 return($files);
24 }
25
26 $files=scandir($dir);
27
28 $set=$db->query("select node_vector from nodes where node_id='$parent_node'");
29 $set->next();
30 $parent_vector=$set->getString('node_vector');
31
32
33
34 foreach ($files as $file) {
35 // nacte obsah souboru do retezce
36 $filename = $dir.$file;
37 $fd = fopen ($filename, "r");
38 $file_content = fread ($fd, filesize ($filename));
39 fclose ($fd);
40 $node_content=addslashes($file_content);
41
42 $qh="select node_id from nodes where node_parent='$parent_node' and node_name='$file'";
43 $seth=$db->query($qh);
44 if ($seth->getNumRows()) {
45 echo "updatin $file\n";
46 $nh=$seth->getString('node_id');
47 $db->query("update node_content set node_content='$node_content' where node_id='$nh'");
48 }
49
50 else {
51 $q="insert into nodes set node_parent='$parent_node',node_name='$file',template_id='2',";
52 $q.="node_system_access='private',node_external_access='no',node_creator='$creator_id',external_link='$external_link'";
53 echo $q."\n";
54
55 $db->query("start transaction");
56 $db->query($q);
57 $id=$db->getLastInsertId();
58 $db->query("insert into node_content set node_id='$id',node_content='".$node_content."'");
59 $new_id=str_pad($id,VECTOR_CHARS,"0",STR_PAD_LEFT);
60 $new_vector=$parent_vector.$new_id;
61
62 $db->query("update nodes set node_vector='$new_vector' where node_id='$id'");
63 $db->query("update nodes set node_children_count=node_children_count+1 where node_id='$parent_id'");
64 }
65
66
67 }
68
69 ?>
This page took 0.465187 seconds and 4 git commands to generate.