_mCityId = (int)$_GET['CityId']; } // Need to have the AreaId in the query string if (!isset($_GET['AreaId'])){ trigger_error('AreaId not set'); }else{ $this->_mAreaId = (int)$_GET['AreaId']; } // Need to have the PropertyId in the query string if (!isset($_GET['PropertyId'])){ trigger_error('PropertyId not set'); }else{ $this->_mPropertyId = (int)$_GET['PropertyId']; } $this->mPropertyDisplayOptions = Listings::$mPropertyDisplayOptions; $this->mLinkToAreaPropertiesAdmin = Link::ToAreaPropertiesAdmin($this->_mCityId, $this->_mAreaId); $this->mLinkToPropertyDetailsAdmin = Link::ToPropertyAdmin($this->_mCityId, $this->_mAreaId, $this->_mPropertyId); // Parse the list with posted variables foreach ($_POST as $key => $value){ // If a submit button was clicked if (substr($key, 0, 6) == 'submit'){ /* Get the position of the last '_' underscore from the submit * button name e.g. strrpos('submit_edit_attr_1', '_') is 17 */ $last_underscore = strrpos($key, '_'); /* Get the scope of the submit button (e.g. 'edit_dep' from * 'submit_edit_attr_1') */ $this->_mAction = substr($key, strlen('submit_'), $last_underscore - strlen('submit_')); /* Get the attribute id targeted by the submit button (the * number at the end of the submit button name e.g. '1' from * 'submit_edit_attr_1' */ $this->_mActionedImageId = substr($key, $last_underscore + 1); break; } } } public function init(){ // If uploading a property picture... if (isset($_POST['Upload'])){ /* Check wheather we have write permission on the * property_images folder */ if (!is_writable(SITE_ROOT . '/' . IMAGE_DIR)){ echo "Can't write to the " . IMAGE_DIR . " folder"; exit(); } foreach ($_FILES as $file){ if(is_array($file['name'])){ for ($count = 0; $count < count($file['name']); $count++){ $filename = $file['name'][$count]; $fileerror = $file['error'][$count]; $filetmp_name = $file['tmp_name'][$count]; // If the error code is 0, the file was uploaded ok if ($fileerror == 0){ /* Use the move_uploaded_file PHP function to move the file from * its temporary location to the property images folder */ move_uploaded_file($filetmp_name, SITE_ROOT . '/' . IMAGE_DIR . $filename); // Update the property's information in the database Listings::AddImage($this->_mPropertyId, $filename, $_POST['caption'.$count]); $temp = $this->_mPropertyId." - ".$filename." - ".$_POST['caption'.$count]; } } } } // If the error code is 0, the file was uploaded ok if ($_FILES['ThumbnailUpload']['error'] == 0){ /* Use the move_uploaded_file PHP function to move the file from * its temporary location to the property images folder */ move_uploaded_file($_FILES['ThumbnailUpload']['tmp_name'], SITE_ROOT . '/' . IMAGE_DIR . $_FILES['ThumbnailUpload']['name']); // Update the property's information in the database Listings::SetThumbnail($this->_mPropertyId, $_FILES['ThumbnailUpload']['name']); } } if ($this->_mAction == 'delete_image'){ Listings::DeleteImage($this->_mActionedImageId); } // If updating property info... if (isset ($_POST['UpdatePropertyInfo'])){ $property_address = $_POST['address']; $property_zipcode = $_POST['zipcode']; $property_description = $_POST['description']; $property_price = $_POST['price']; $property_price_reduction = $_POST['price_reduction']; if ($property_address == null){ $this->mErrorMessage = 'Property address is empty'; } if ($property_zipcode == null){ $this->mErrorMessage = 'Property zipcode is empty'; } if ($property_description == null){ $this->mErrorMessage = 'Property description is emtpy'; } if ($property_price == null || !is_numeric($property_price)){ $this->mErrorMessage = 'Property price must be a number'; } if ($property_price_reduction == null || !is_numeric($property_price_reduction)){ $this->mErrorMessage = 'Property price reduction must be a number'; } if ($this->mErrorMessage == null){ Listings::UpdateProperty($this->_mPropertyId, $property_address, $property_zipcode, $property_description, $property_price, $property_price_reduction); } } // If removing the property from a area... if (isset ($_POST['RemoveFromArea'])){ $target_area_id = $_POST['TargetAreaIdRemove']; $still_exists = Listings::RemovePropertyFromArea($this->_mPropertyId, $target_area_id); if ($still_exists == 0){ header('Location: ' . htmlspecialchars_decode($this->mLinkToAreaPropertiesAdmin)); exit(); } } // If setting property display option... if (isset ($_POST['SetPropertyDisplayOption'])){ $property_display = $_POST['PropertyDisplay']; Listings::SetPropertyDisplayOption($this->_mPropertyId, $property_display); } // If removing the property from the listings... if (isset($_POST['RemoveFromListings'])){ Listings::DeleteProperty($this->_mPropertyId); header('Location: ' . htmlspecialchars_decode($this->mLinkToAreaPropertiesAdmin)); exit(); } // If assigning the property to another area... if (isset($_POST['Assign'])){ $target_area_id = $_POST['TargetAreaIdAssign']; Listings::AssignPropertyToArea($this->_mPropertyId, $target_area_id); } // If moving the property to another area... if (isset ($_POST['Move'])){ $target_area_id = $_POST['TargetAreaIdMove']; Listings::MovePropertyToArea($this->_mPropertyId, $this->_mAreaId, $target_area_id); header('Location: ' . htmlspecialchars_decode( Link::ToPropertyAdmin($this->_mCityId, $this->_mAreaId, $this->_mPropertyId))); exit(); } // If assigning an attribute value to the property... if (isset($_POST['AssignAttributeValue'])){ $target_attribute_value_id = $_POST['TargetAttributeValueIdAssign']; Listings::AssignAttributeValueToProperty($this->_mPropertyId, $target_attribute_value_id); } // If removing an attribute value from the property... if (isset($_POST['RemoveAttributeValue'])){ $target_attribute_value_id = $_POST['TargetAttributeValueIdRemove']; Listings::RemovePropertyAttributeValue($this->_mPropertyId, $target_attribute_value_id); } // Get property info $this->mProperty = Listings::GetPropertyInfo($this->_mPropertyId); $property_areas = Listings::GetAreasForProperty($this->_mPropertyId); $property_attributes = Listings::GetPropertyAttributesList($this->_mPropertyId); /* create the mPropertyAttributes array...for listing the current property's * attributes to see what it has */ for ($i = 0; $i < count($property_attributes); $i++){ $this->mPropertyAttributes[$property_attributes[$i]['attribute_value_id']] = $property_attributes[$i]['attribute_name'] . ': ' . $property_attributes[$i]['attribute_value']; } $listings_attributes = Listings::GetAttributesNotAssignedToProperty($this->_mPropertyId); /* create the mListingsAttributes array...this is for listing the attributes * not associated with the current property but are available to the property */ for ($i = 0; $i < count($listings_attributes); $i++){ $this->mListingsAttributes[$listings_attributes[$i]['attribute_value_id']] = $listings_attributes[$i]['attribute_name'] . ': ' . $listings_attributes[$i]['attribute_value']; } /* If the property has one area, then you cannot remove it from any more * areas or else the entire property will be removed from the database */ if (count($property_areas) == 1){ $this->mRemoveFromAreaButtonDisabled = true; } // Show the areas the property belongs to... for ($i = 0; $i < count($property_areas); $i++){ $temp1[$property_areas[$i]['area_id']] = $property_areas[$i]['name']; } $this->mRemoveFromAreas = $temp1; $this->mPropertyAreasString = implode(', ', $temp1); $all_areas = Listings::GetAreas(); for ($i = 0; $i < count($all_areas); $i++){ $temp2[$all_areas[$i]['area_id']] = $all_areas[$i]['name']; } $this->mAssignOrMoveTo = array_diff($temp2, $temp1); $this->mImages = Listings::GetPropertyImages($this->_mPropertyId); $this->mImagesCount = count($this->mImages); // Build the links for the images associated with a property for ($i = 0; $i < $this->mImagesCount; $i++){ $this->mImages[$i]['image_url'] = Link::Build(IMAGE_DIR . $this->mImages[$i]['image_name']); } } }