setDBO(VoxelCareDB::getDatabase()); }//function function Delete($id) { if (!$id) return; $db =& $this->_db; $sql = "DELETE FROM #__vxc_attribute WHERE id = $id"; $db->Execute($sql); $this->GetFilenames($id,$fileLeft,$fileRight,$fileExtra); $this->GetThumbs($id,$thumbLeft,$thumbRight); @unlink($fileLeft); @unlink($fileRight); @unlink($fileExtra); @unlink($thumbLeft); @unlink($thumbRight); } function SetId($id) { $this->_id = $id; $this->_item =null; } function GetId() { return $this->_id; } function getData() { if (empty($this->_item)) { if (!$this->_id) $this->_id =0; $newFields = ''; if (LegacyHelper::getNewMode()) $newFields = "at.value value,at.name dbname,"; $sql = "SELECT at.id id, ty.name name, at.value_left valueleft, $newFields at.value_right valueright, ty.name type,at.type typeid, at.orderid orderid,at.product product,at.memo_left memoleft, at.memo_right memoright, dt.name datatype FROM #__vxc_attribute at LEFT JOIN #__vxc_attributetype ty on ty.id = at.type LEFT JOIN #__vxc_datatype dt on dt.id = ty.datatype where at.id = ".$this->_id; $db =& $this->_db; $db->setQuery($sql); $this->_item = $db->loadObject(); } return $this->_item; } function saveNewAttInfo($atname,$atUpdateUUID,$atValue=null) { if (!$this->_id) return; if ($atValue!==null) $extraSet = ", `value` = " . $this->_db->Quote($atValue).' '; else $extraSet = ''; $sql = "UPDATE #__vxc_attribute SET `name` = ". $this->_db->Quote($atname) . ", update_uuid = ". $this->_db->Quote($atUpdateUUID)." $extraSet WHERE id = " . $this->_id; //$debugFile = 'c:\\newattinfo.txt'; //file_put_contents($debugFile,$sql."\n",FILE_APPEND); $this->_db->Execute($sql); } function getIdFromDBName($orderGuid, $atname) { if (!$orderGuid || !$atname) return ''; $sql = "SELECT at.id FROM #__vxc_attribute at LEFT JOIN #__vxc_order o ON o.id = at.orderid WHERE o.uuid = ". $this->_db->Quote($orderGuid) ." AND at.name = " . $this->_db->Quote($atname); $this->_db->setQuery($sql); $res = $this->_db->loadResult(); return $res; } function store(&$post) { $db =& $this->_db; $valueLeft = $db->Quote($post['value_left']); $valueRight = $db->Quote($post['value_right']); $typeId = $post['type']; if ($post['id']) { $typeIdSql =''; if ($typeId !==null) $typeIdSql = ", type = ". $typeId; $sql = "UPDATE #__vxc_attribute SET value_left = $valueLeft , value_right = $valueRight $typeIdSql WHERE id = ".$post['id']; $db->Execute($sql); } else { $orderId = $post['orderid']; if (!$orderId) $orderId ='NULL'; $sql = "INSERT INTO #__vxc_attribute(type,orderid,value_left,value_right) VALUES ($typeId,$orderId,$valueLeft,$valueRight)"; $db->Execute($sql); $this->SetId($db->insertid()); } } static function GetFolder($atId) { $folder = vxcModelOrderAttribute::GetRelativeFolder($atId); $dir = LegacyHelper::getFilesRoot(). $folder; @mkdir($dir,0777,true); return $dir; } static function GetRelativeFolder($atId) { $folder = ((int)$atId)%NUM_ATTRIBUTE_FOLDERS; $dir = LegacyHelper::getAttributesRDir().'/'. $folder; return $dir; } static function GetFolderFilename($atId,$name,&$folderfilename,$create=false) { $folder = vxcModelOrderAttribute::GetFolder($atId); $folder .='/'.$atId; if ($create) @mkdir($folder,0777,true); $folderfilename = $folder.'/'.$name; } static function GetRelativeFolderFilename($atId,$name,&$folderfilename) { $folder = vxcModelOrderAttribute::GetRelativeFolder($atId); $folder .='/'.$atId; $folderfilename = $folder.'/'.$name; } static function GetFilenames($atId,&$fileLeft,&$fileRight,&$fileExtra) { $folder = vxcModelOrderAttribute::GetFolder($atId); $fileLeft = $folder.'/'.$atId.'_L'; $fileRight = $folder.'/'.$atId.'_R'; $fileExtra = $folder.'/'.$atId.'extra'; } static function GetRelativeFilenames($atId,&$fileLeft,&$fileRight,&$fileExtra) { $folder = vxcModelOrderAttribute::GetRelativeFolder($atId); $fileLeft = $folder.'/'.$atId.'_L'; $fileRight = $folder.'/'.$atId.'_R'; $fileExtra = $folder.'/'.$atId.'extra'; } static function GetThumbs($atId,&$thumbLeft,&$thumbRight) { vxcModelOrderAttribute::GetRelativeThumbs($atId,$thumbLeft,$thumbRight); $rootDir = LegacyHelper::getFilesRoot(); $thumbLeft = $rootDir.$thumbLeft; $thumbRight = $rootDir.$thumbRight; } static function GetRelativeThumbs($atId,&$thumbLeft,&$thumbRight) { $folder = vxcModelOrderAttribute::GetRelativeFolder($atId); $thumbLeft = $folder.'/'.$atId.'_L_th'; $thumbRight = $folder.'/'.$atId.'_R_th'; } static function GetExtras($atId,&$extraLeft,&$extraRight) { vxcModelOrderAttribute::GetRelativeExtras($atId,$extraLeft,$extraRight); $rootDir = LegacyHelper::getFilesRoot(); $extraLeft = $rootDir.$extraLeft; $extraRight = $rootDir.$extraRight; } static function GetRelativeExtras($atId,&$extraLeft,&$extraRight) { $folder = vxcModelOrderAttribute::GetRelativeFolder($atId); $extraLeft = $folder.'/'.$atId.'extra_L'; $extraRight = $folder.'/'.$atId.'extra_R'; } function getOrderAttributes($orderId) { $db =& $this->_db; $sql ="SELECT at.id id, ty.name tyname ,dt.name dtname FROM #__vxc_order o LEFT JOIN #__vxc_attribute at on at.orderid = o.id LEFT JOIN #__vxc_attributetype ty ON ty.id = at.type LEFT JOIN #__vxc_datatype dt ON dt.id = ty.datatype WHERE o.id = $orderId"; $db->setQuery($sql); $rows =& $db->loadObjectList(); return $rows; } function DoClone() { $oldData =& $this->getData(); $newData = array(); $newData['id'] = null; $newData['type'] = $oldData->typeid; $newData['orderid'] = $oldData->orderid; $newData['product'] = $oldData->product; $newData['value_left'] = $oldData->valueleft; $newData['value_right'] = $oldData->valueright; $newData['memo_left'] = $oldData->memoleft; $newData['memo_right'] = $oldData->memoright; $oldId = $oldData->id; $this->store($newData); $newId = $this->_id; if ($oldData->datatype == "IMAGE" || $oldData->datatype == "FILE") { vxcModelOrderAttribute::GetFilenames($oldId,$oldFileLeft,$oldFileRight,$oldFileExtra); vxcModelOrderAttribute::GetThumbs($oldId,$oldThumbLeft,$oldThumbRight); vxcModelOrderAttribute::GetFilenames($newId ,$fileLeft,$fileRight,$fileExtra); vxcModelOrderAttribute::GetThumbs($newId,$thumbLeft,$thumbRight); @copy($oldFileLeft,$fileLeft); @copy($oldFileRight,$fileRight); @copy($oldFileExtra,$fileExtra); @copy($oldThumbLeft,$thumbLeft); @copy($oldThumbRight,$thumbRight); } } } ?>