name=$Name; $this->id=$ID; if ($Type!==''){ $this->type=$Type; if (isset($Value)){ $this->values=$Value; }; if (isset($Default)){ $this->defaults=$Default; }; }; } function SetVal($Val){ $this->value=$Val; } function Set($Name='Uninitialized Property',$Type='',$ID ,$Value='',$Default=''){ if ( $this->name=='' ) $this->name=$Name; if ( $this->type=='' ) $this->type=$Type; if ( $this->id=='00' ){ $a=dechex($ID); if (strlen($a)<2) $a='0'.$a; $this->id=$a; }; if (isset($Value)){ $this->value=$Value; }; if (isset($Default)){ $this->defaults=$Default; }; } } class VS_M_Tree{ var $SubLeafs=array(); var $SubTrees=array(); var $name; var $value; var $id; var $DATABASE; function __construct($DB,$Name='Additional Parameters',$ID='00'){ $this->name=$Name; $this->id=$ID; $this->value=0; $this->DATABASE=$DB; } function & Add($NodeType=TREE_NODE,$NodeID,$NodeName,$SubNode=null){ switch ($NodeType){ case TREE_NODE:{ if (isset($SubNode)){ $this->SubTrees[$NodeID]=$SubNode; } else { $this->SubTrees[$NodeID]=new VS_M_Tree($this->DATABASE,$NodeName,$NodeID); }; return $this->SubTrees[$NodeID]; break; } case TREE_LEAF:{ if (isset($SubNode)){ $this->SubLeafs[$NodeID]=$SubNode; } else { $this->SubLeafs[$NodeID]=new VS_Property($NodeName,'',$NodeID); }; return $this->SubLeafs[$NodeID]; break; } } } function & AddTo($ParentNodeID, $NodeType, $NodeID, $NodeName, $SubNode=null){ $a=dechex($ParentNodeID); if (strlen($a)<2) $a='0'.$a; $b=dechex($NodeID); if (strlen($b)<2) $b='0'.$b; $T_Node = & $this->GetNode($a, TREE_NODE); if ($T_Node!==null){ return $T_Node->Add( $NodeType, $b, $NodeName, $SubNode ); } else { return $this->Add( $NodeType, $b, $NodeName, $SubNode ); // if we can't find node, new node will be attached to current } } function SetVal($Val){ $this->value=$Val; } function SetPropertyValue($NodeType,$Prop_ID,$Value){ $T_Node = & $this->GetNode($Prop_ID,$NodeType); if ($T_Node!==null){ $T_Node->SetVal($Value); } else { echo "Node:{$Prop_ID} Was not found
\n"; }; } function FillFromString($Parameters){ $array=preg_split('/#/',$Parameters,-1,PREG_SPLIT_NO_EMPTY); foreach ($array as $CP){ $v_array=explode(':',$CP); if ($v_array[0]=='L') $this->SetPropertyValue(TREE_LEAF,$v_array[1],$v_array[2]); if ($v_array[0]=='T') $this->SetPropertyValue(TREE_NODE,$v_array[1],$v_array[2]); }; } function FillFromSession($session_var){ $array=preg_split('/#/',$_SESSION[$session_var],-1,PREG_SPLIT_NO_EMPTY); foreach ($array as $CP){ $v_array=explode(':',$CP); if ($v_array[0]=='L') $this->SetPropertyValue(TREE_LEAF,$v_array[1],$v_array[2]); if ($v_array[0]=='T') $this->SetPropertyValue(TREE_NODE,$v_array[1],$v_array[2]); }; } function LoadStructure($TypeID){ global $Labels; // Get Structure Name $QS="SELECT name_id FROM object_types WHERE id='{$TypeID}'"; $result = $this->DATABASE->Query($QS,false); $this->name=$Labels->GetLabel($result[0]['name_id']); // Creating Trees $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"; $result = $this->DATABASE->Query($QS,false); foreach($result as $array){ $this->AddTo($array['parent'],TREE_NODE,$array['id'],$Labels->GetLabel($array['name_id'])); }; // Harvesting Leafs $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} %'"; $result = $this->DATABASE->Query($QS,false); foreach($result as $array){ $TN = & $this->AddTo($array['group'],TREE_LEAF, $array['id'], $Labels->GetLabel($array['name_id'])); $QS="SELECT value FROM object_property_values WHERE property_id='{$array['defaults_id']}' ORDER BY position"; $p_result=$this->DATABASE->Query($QS,false); $TN->Set($Labels->GetLabel($array['name_id']),$array['type'],'','',$p_result); }; // NOW You may drink cup of tea! } function SetDataFromWeb(){ foreach( $_POST as $CPK => $CPV ){ if(is_array($CPV)){ $array[]=$CPK . ':' . implode($CPV).'#'; } else { if ($CPV!=''){ $array[]=$CPK . ':' . $CPV.'#'; }; }; }; $VAL='#'.implode($array); $this->FillFromString( $VAL ); } function LoadDataFromDB($id){ } function LoadFromDB($Type,$id=0){ // if ID==0 will be loaded empty structure if(isset($Type)){ if(!$this->LoadStructure($Type)) return false; if ($id) $this->LoadData($id); // if data is not found that's OK return true; } else return false; } function & GetNode($NodeID='',$NodeType=1){ if (($NodeID=='' || $this->id==$NodeID ) && $NodeType != TREE_LEAF){ return $this; } else { if ($NodeType==TREE_LEAF ){ if (isset($this->SubLeafs[$NodeID])){ return $this->SubLeafs[$NodeID]; }; }; if ($NodeType==TREE_NODE){ if (isset($this->SubTrees[$NodeID])){ return $this->SubTrees[$NodeID]; }; }; $RetVal=null; foreach ( $this->SubTrees as $CTree ) { $RetVal= & $CTree->GetNode($NodeID, $NodeType); if($RetVal!==null) break; } } return $RetVal; } } ?>