ID.'" AND meta_key="fbuid"') or die(mysql_error()); if(mysql_num_rows($queryifisconnected)!=0){ $row3 = mysql_fetch_array($queryifisconnected); $id = $row3['meta_value']; } /* end of checking if user has connected accounts */ /* check if user has a dog */ $querycheckcalc = mysql_query('SELECT * FROM wp_dog_base WHERE owners_id="'.$current_user->ID.'" LIMIT 1') or die(mysql_error()); if(mysql_num_rows($querycheckcalc)!=0 && $id!=''){ mysql_query('UPDATE wp_dog_base SET fbuid="'.$id.'" WHERE owners_id="'.$current_user->ID.'"') or die(mysql_error()); } /* end of checking if user has a dog */ /* check if user has calculator */ $querycheckcalc = mysql_query('SELECT * FROM wp_food_storage WHERE owner_id="'.$current_user->ID.'" LIMIT 1') or die(mysql_error()); if(mysql_num_rows($querycheckcalc)==0){ mysql_query('INSERT INTO wp_food_storage SET fbuid="'.$id.'", owner_id="'.$current_user->ID.'", quantity="0", last_check='.time().', orders_processed="", date_added="'.time().'"') or die(mysql_error()); } elseif($id!=''){ mysql_query('UPDATE wp_food_storage SET fbuid="'.$id.'" WHERE owner_id="'.$current_user->ID.'"') or die(mysql_error()); } /* end of checking if user has calculator */ /* check if user has ordered something and put into calculator */ $queryaddstorage = mysql_query('SELECT wfs.orders_processed, wwplo.id, wwplo.date, wwpli.weight, wwcc.quantity FROM wp_wpsc_purchase_logs AS wwplo INNER JOIN wp_wpsc_cart_contents AS wwcc ON wwplo.id=wwcc.purchaseid INNER JOIN wp_wpsc_product_list AS wwpli ON wwpli.id=wwcc.prodid INNER JOIN wp_food_storage AS wfs ON owner_id="'.$current_user->ID.'" WHERE wwplo.user_ID="'.$current_user->ID.'" AND wwplo.processed>=2 ORDER BY wwplo.date ASC') or die(mysql_error()); $querygetcurrentquantity = mysql_query('SELECT * FROM wp_food_storage WHERE owner_id="'.$current_user->ID.'" LIMIT 1') or die(mysql_error()); $row2 = mysql_fetch_array($querygetcurrentquantity); while($row = mysql_fetch_array($queryaddstorage)){ if(!preg_match('/\{'.$row['id'].'\}/i', $row2['orders_processed'])){ $quantityafterorder = $quantityafterorder+($row['weight']*$row['quantity']); $orders .= $row2['orders_processed'].'{'.$row['id'].'}'; } } if($orders!=''){ $quantityafterorder = $quantityafterorder + $row2['quantity']; mysql_query('UPDATE wp_food_storage SET quantity='.$quantityafterorder.', orders_processed="'.$orders.'" WHERE owner_id="'.$current_user->ID.'"') or die(mysql_error()); } /* end of checking if user has ordered something and put into calculator */ /* add food into storage */ if($_POST['add-kilo']){ $queryaddstorage = mysql_query('SELECT * FROM wp_food_storage WHERE owner_id="'.$current_user->ID.'" LIMIT 1') or die(mysql_error()); $row = mysql_fetch_array($queryaddstorage); $totalstorage = $row['quantity']; if(mysql_num_rows($queryaddstorage)==0){ mysql_query('INSERT INTO wp_food_storage SET owner_id="'.$current_user->ID.'", quantity="1", date_added="'.time().'"') or die(mysql_error()); } else { $totalstorage=$totalstorage+1; mysql_query('UPDATE wp_food_storage SET last_check='.time().', quantity='.$totalstorage.' WHERE owner_id="'.$current_user->ID.'"') or die(mysql_error()); } } /* end of adding food into storage */ /* subtract food from storage */ if($_POST['subtract-kilo']){ $queryaddstorage = mysql_query('SELECT * FROM wp_food_storage WHERE owner_id="'.$current_user->ID.'" LIMIT 1') or die(mysql_error()); $row = mysql_fetch_array($queryaddstorage); $totalstorage = $row['quantity']; $totalstorage=$totalstorage-1; mysql_query('UPDATE wp_food_storage SET last_check='.time().', quantity='.$totalstorage.' WHERE owner_id="'.$current_user->ID.'"') or die(mysql_error()); } /* end of subtracting food from storage */ /* add custom food storage */ if($_POST['save-custom-storage']){ $queryaddstorage = mysql_query('SELECT * FROM wp_food_storage WHERE owner_id="'.$current_user->ID.'" LIMIT 1'); if(mysql_num_rows($queryaddstorage)==0){ $customstorage = str_replace(',','.',$_POST['custom-storage']); mysql_query('INSERT INTO wp_food_storage SET owner_id="'.$current_user->ID.'", quantity="'.$customstorage.'", date_added="'.time().'"') or die(mysql_error()); } else { $customstorage = str_replace(',','.',$_POST['custom-storage']); mysql_query('UPDATE wp_food_storage SET last_check='.time().', quantity='.$customstorage.' WHERE owner_id="'.$current_user->ID.'"') or die(mysql_error()); } } $pageURL = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; $url = explode("/", $pageURL); $serverurl = $url[0].'/'.$url[1]; /* end of adding custom food storage */ get_header(); ?>
nickname!=''){ ?> ID.' ja minu FB id on '.$current_user->fbuid.'


'; echo '

Kalkulaator

'; $ifdogquery = mysql_query('SELECT * FROM wp_dog_base WHERE owners_id="'.$current_user->ID.'"'); $ifhasdogs = mysql_num_rows($ifdogquery); if($ifhasdogs!=0){ $query = mysql_query('SELECT wfs.quantity, wfs.last_check, wdb.dog_weight, wdb.dog_name, wdb.dog_pregnant, wdb.dog_age, wdbr.breed FROM wp_dog_base AS wdb INNER JOIN wp_dog_breed AS wdbr ON wdb.dog_breed=wdbr.id INNER JOIN wp_food_storage AS wfs ON wdb.owners_id=wfs.owner_id WHERE owners_id='.$current_user->ID.'') or die(mysql_error()); echo '

Hinnanguline toiduvajadus teie koertel ühes kuus

'; while($row = mysql_fetch_array($query)){ $birthdate = $row['dog_age']; $agestamp = time()-$birthdate; $age = ceil($agestamp/60/60/24/365); $weight=$row['dog_weight']; if($weight<=3){$foodstorage=33;$needsinahour=33/24;} elseif($weight<=5){$foodstorage=56;$needsinahour=56/24;} elseif($weight<=10){$foodstorage=120;$needsinahour=120/24;} elseif($weight<=15){$foodstorage=195;$needsinahour=195/24;} elseif($weight<=20){$foodstorage=270;$needsinahour=270/24;} elseif($weight<=25){$foodstorage=337;$needsinahour=337/24;} elseif($weight<=30){$foodstorage=405;$needsinahour=405/24;} elseif($weight<=35){$foodstorage=472;$needsinahour=472/24;} elseif($weight<=45){$foodstorage=562;$needsinahour=562/24;} elseif($weight<=55){$foodstorage=632;$needsinahour=632/24;} elseif($weight<=65){$foodstorage=647;$needsinahour=647/24;} elseif($weight<=75){$foodstorage=862;$needsinahour=862/24;} elseif($weight<=85){$foodstorage=955;$needsinahour=995/24;} elseif($weight<=95){$foodstorage=1050;$needsinahour=1050/24;} $needsinahourtotal=$needsinahourtotal+$needsinahour; //echo $row['dog_name'].' vajab tunnis '.$needsinahourtotal; if($age<2){ if($row['dog_pregnant']==1){ $puppy .= $row['dog_name'].', '.$row['breed'].' '.$age.'a (tiine) - (~'.number_format((($needsinahour*24*30)/1000), 1, ',', ' ').' kg)
'; } else { $puppy .= $row['dog_name'].', '.$row['breed'].' '.$age.'a - (~'.number_format((($needsinahour*24*30)/1000), 1, ',', ' ').' kg)
'; } } else { if($row['dog_pregnant']==1){ $adult .= $row['dog_name'].', '.$row['breed'].' '.$age.'a (tiine) - (~'.number_format((($needsinahour*24*30)/1000), 1, ',', ' ').' kg)
'; } else { $adult .= $row['dog_name'].', '.$row['breed'].' '.$age.'a - (~'.number_format((($needsinahour*24*30)/1000), 1, ',', ' ').' kg)
'; } } } ?>
'.$puppy; } ?>
'.$adult; } ?>
Arvestuslikult on toitu veel alles ID.' LIMIT 1') or die(mysql_error()); $row = mysql_fetch_array($querystorage); $lastcheck=$row['last_check']; $quantity=$row['quantity']; if($quantity>0){ $timesincelastvisit = (time()-$lastcheck); $timesincelastvisitinhours = ($timesincelastvisit/60/60); $quantitytosubtract=($quantity*1000)-($timesincelastvisitinhours*$needsinahourtotal); $quantitytosubtract=$quantitytosubtract/1000; mysql_query('UPDATE wp_food_storage SET last_check='.time().', quantity='.$quantitytosubtract.' WHERE owner_id="'.$current_user->ID.'"') or die(mysql_error()); $querystorage = mysql_query('SELECT last_check, quantity FROM wp_food_storage WHERE owner_id='.$current_user->ID.' LIMIT 1') or die(mysql_error()); } $row = mysql_fetch_array($querystorage); if($row['quantity']>0){ echo ''; } else { $row['quantity']=0; } echo ' kilogrammi
*täpsemalt '.$quantitytosubtract.' kg, seisuga '.date('d.m.y \k\e\l\l H:i:s',$lastcheck); ?>

Kalkulaatori nägemiseks peate koeri lisama, tehke seda SIIN!'; } } else { if($_POST['calculate-storage']){ $validate=1; $dogname=$_POST['dog-name']; $dogweight=$_POST['dog-weight']; $dogage=$_POST['dog-age']; if($dogname==''){$echo .= '
Nime väli tühi!
'; $validate=0;} $dogweight = str_replace(',','.',$dogweight); if($dogweight=='' || !is_numeric($dogweight)){$echo .= '
Kaalu väli on tühi või ei koosne numbritest!
'; $validate=0;} if($dogage=='' || !preg_match("/([0-2][0-9]|[0-3][0-1])\/([1][0-2]|[0][0-9])\/([0-9][0-9][0-9][0-9])/i", $dogage)){$echo .= '
Koera sünnipäev valimata või vale formaat!
'; $validate=0;} if($validate==1){ $birthdate = $_POST['dog-age']; $agestamp = time()-$birthdate; $age = ceil($agestamp/60/60/24/365); $weight=$_POST['dog-weight']; if($weight<=3){$foodstorage=33;$needsinahour=33/24;} elseif($weight<=5){$foodstorage=56;$needsinahour=56/24;} elseif($weight<=10){$foodstorage=120;$needsinahour=120/24;} elseif($weight<=15){$foodstorage=195;$needsinahour=195/24;} elseif($weight<=20){$foodstorage=270;$needsinahour=270/24;} elseif($weight<=25){$foodstorage=337;$needsinahour=337/24;} elseif($weight<=30){$foodstorage=405;$needsinahour=405/24;} elseif($weight<=35){$foodstorage=472;$needsinahour=472/24;} elseif($weight<=45){$foodstorage=562;$needsinahour=562/24;} elseif($weight<=55){$foodstorage=632;$needsinahour=632/24;} elseif($weight<=65){$foodstorage=647;$needsinahour=647/24;} elseif($weight<=75){$foodstorage=862;$needsinahour=862/24;} elseif($weight<=85){$foodstorage=955;$needsinahour=995/24;} elseif($weight<=95){$foodstorage=1050;$needsinahour=1050/24;} $echo = $_POST['dog-name'].' vajab kuus ~'.number_format((($needsinahour*24*30)/1000), 1, ',', ' ').' kg'; } } ?>

Kalkulaator




'; } else { echo ' '; } ?>