You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
6.4 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <?php
  2. define('OBJECT_TYPE',0);
  3. define('OBJECT_PROP',1);
  4. define('OBJECT_VALUE',2);
  5. define('OBJECT_GROUP',3);
  6. define('TREE_NODE',0);
  7. define('TREE_LEAF',1);
  8. define('TREE_ANY',2);
  9. class VS_Property{
  10. var $name;
  11. var $id;
  12. var $type;
  13. var $value;
  14. var $defaults;
  15. function __construct($Name='Uninitialized Property',$Type='',$ID='00',$Value='',$Default=''){
  16. $this->name=$Name;
  17. $this->id=$ID;
  18. if ($Type!==''){
  19. $this->type=$Type;
  20. if (isset($Value)){
  21. $this->values=$Value;
  22. };
  23. if (isset($Default)){
  24. $this->defaults=$Default;
  25. };
  26. };
  27. }
  28. function SetVal($Val){
  29. $this->value=$Val;
  30. }
  31. function Set($Name='Uninitialized Property',$Type='',$ID ,$Value='',$Default=''){
  32. if ( $this->name=='' ) $this->name=$Name;
  33. if ( $this->type=='' ) $this->type=$Type;
  34. if ( $this->id=='00' ){
  35. $a=dechex($ID);
  36. if (strlen($a)<2) $a='0'.$a;
  37. $this->id=$a;
  38. };
  39. if (isset($Value)){
  40. $this->value=$Value;
  41. };
  42. if (isset($Default)){
  43. $this->defaults=$Default;
  44. };
  45. }
  46. }
  47. class VS_M_Tree{
  48. var $SubLeafs=array();
  49. var $SubTrees=array();
  50. var $name;
  51. var $value;
  52. var $id;
  53. var $DATABASE;
  54. function __construct($DB,$Name='Additional Parameters',$ID='00'){
  55. $this->name=$Name;
  56. $this->id=$ID;
  57. $this->value=0;
  58. $this->DATABASE=$DB;
  59. }
  60. function & Add($NodeType=TREE_NODE,$NodeID,$NodeName,$SubNode=null){
  61. switch ($NodeType){
  62. case TREE_NODE:{
  63. if (isset($SubNode)){
  64. $this->SubTrees[$NodeID]=$SubNode;
  65. } else {
  66. $this->SubTrees[$NodeID]=new VS_M_Tree($this->DATABASE,$NodeName,$NodeID);
  67. };
  68. return $this->SubTrees[$NodeID];
  69. break;
  70. }
  71. case TREE_LEAF:{
  72. if (isset($SubNode)){
  73. $this->SubLeafs[$NodeID]=$SubNode;
  74. } else {
  75. $this->SubLeafs[$NodeID]=new VS_Property($NodeName,'',$NodeID);
  76. };
  77. return $this->SubLeafs[$NodeID];
  78. break;
  79. }
  80. }
  81. }
  82. function & AddTo($ParentNodeID, $NodeType, $NodeID, $NodeName, $SubNode=null){
  83. $a=dechex($ParentNodeID);
  84. if (strlen($a)<2) $a='0'.$a;
  85. $b=dechex($NodeID);
  86. if (strlen($b)<2) $b='0'.$b;
  87. $T_Node = & $this->GetNode($a, TREE_NODE);
  88. if ($T_Node!==null){
  89. return $T_Node->Add( $NodeType, $b, $NodeName, $SubNode );
  90. } else {
  91. return $this->Add( $NodeType, $b, $NodeName, $SubNode ); // if we can't find node, new node will be attached to current
  92. }
  93. }
  94. function SetVal($Val){
  95. $this->value=$Val;
  96. }
  97. function SetPropertyValue($NodeType,$Prop_ID,$Value){
  98. $T_Node = & $this->GetNode($Prop_ID,$NodeType);
  99. if ($T_Node!==null){
  100. $T_Node->SetVal($Value);
  101. } else {
  102. echo "Node:{$Prop_ID} Was not found<br>\n";
  103. };
  104. }
  105. function FillFromString($Parameters){
  106. $array=preg_split('/#/',$Parameters,-1,PREG_SPLIT_NO_EMPTY);
  107. foreach ($array as $CP){
  108. $v_array=explode(':',$CP);
  109. if ($v_array[0]=='L') $this->SetPropertyValue(TREE_LEAF,$v_array[1],$v_array[2]);
  110. if ($v_array[0]=='T') $this->SetPropertyValue(TREE_NODE,$v_array[1],$v_array[2]);
  111. };
  112. }
  113. function FillFromSession($session_var){
  114. $array=preg_split('/#/',$_SESSION[$session_var],-1,PREG_SPLIT_NO_EMPTY);
  115. foreach ($array as $CP){
  116. $v_array=explode(':',$CP);
  117. if ($v_array[0]=='L') $this->SetPropertyValue(TREE_LEAF,$v_array[1],$v_array[2]);
  118. if ($v_array[0]=='T') $this->SetPropertyValue(TREE_NODE,$v_array[1],$v_array[2]);
  119. };
  120. }
  121. function LoadStructure($TypeID){
  122. global $Labels;
  123. // Get Structure Name
  124. $QS="SELECT name_id FROM object_types WHERE id='{$TypeID}'";
  125. $result = $this->DATABASE->Query($QS,false);
  126. $this->name=$Labels->GetLabel($result[0]['name_id']);
  127. // Creating Trees
  128. $QS="SELECT OG.id, OG.parent, OG.name_id FROM object_property_groups OG WHERE OG.object_types LIKE '% {$TypeID} %' ORDER BY OG.parent, OG.order";
  129. $result = $this->DATABASE->Query($QS,false);
  130. foreach($result as $array){
  131. $this->AddTo($array['parent'],TREE_NODE,$array['id'],$Labels->GetLabel($array['name_id']));
  132. };
  133. // Harvesting Leafs
  134. $QS="SELECT OP.id, OP.group, OP.type, OP.name_id, OP.defaults_id FROM object_property_types OP WHERE OP.object_types LIKE '% {$TypeID} %'";
  135. $result = $this->DATABASE->Query($QS,false);
  136. foreach($result as $array){
  137. $TN = & $this->AddTo($array['group'],TREE_LEAF, $array['id'], $Labels->GetLabel($array['name_id']));
  138. $QS="SELECT value FROM object_property_values WHERE property_id='{$array['defaults_id']}' ORDER BY position";
  139. $p_result=$this->DATABASE->Query($QS,false);
  140. $TN->Set($Labels->GetLabel($array['name_id']),$array['type'],'','',$p_result);
  141. };
  142. // NOW You may drink cup of tea!
  143. }
  144. function SetDataFromWeb(){
  145. foreach( $_POST as $CPK => $CPV ){
  146. if(is_array($CPV)){
  147. $array[]=$CPK . ':' . implode($CPV).'#';
  148. } else {
  149. if ($CPV!=''){
  150. $array[]=$CPK . ':' . $CPV.'#';
  151. };
  152. };
  153. };
  154. $VAL='#'.implode($array);
  155. $this->FillFromString( $VAL );
  156. }
  157. function LoadDataFromDB($id){
  158. }
  159. function LoadFromDB($Type,$id=0){ // if ID==0 will be loaded empty structure
  160. if(isset($Type)){
  161. if(!$this->LoadStructure($Type)) return false;
  162. if ($id) $this->LoadData($id); // if data is not found that's OK
  163. return true;
  164. } else return false;
  165. }
  166. function & GetNode($NodeID='',$NodeType=1){
  167. if (($NodeID=='' || $this->id==$NodeID ) && $NodeType != TREE_LEAF){
  168. return $this;
  169. } else {
  170. if ($NodeType==TREE_LEAF ){
  171. if (isset($this->SubLeafs[$NodeID])){
  172. return $this->SubLeafs[$NodeID];
  173. };
  174. };
  175. if ($NodeType==TREE_NODE){
  176. if (isset($this->SubTrees[$NodeID])){
  177. return $this->SubTrees[$NodeID];
  178. };
  179. };
  180. $RetVal=null;
  181. foreach ( $this->SubTrees as $CTree ) {
  182. $RetVal= & $CTree->GetNode($NodeID, $NodeType);
  183. if($RetVal!==null) break;
  184. }
  185. }
  186. return $RetVal;
  187. }
  188. }
  189. ?>