# Understanding Noah's Classifieds/Multiple Image Extension
## Problem

In Noah's classifieds an advert can only submit one image, we want to submit n images.
First you will need this new file, save it is image.php in your root folder of Noah. Image.php Source

## Target Functionality

Now let's first talk about our target. We want the following features:
* Obviously all created data must be deleted upon the removal of the advert
* Use HTML Text as a spacer between images
* Dynamically create the upload fields so submission is not cluttered
* Remove a single image without deleting the ad
* Allow for dynamic setting of maxImageCount, maxImageSize, maxImageThumb and whether single delete function is available
Here is a snapshot of the end result

## Modifying gorum/dbproperty.php

Because any and all object_vars are automatically saved to the database it is problematic to use $this->data to pass data from one function to the next. To get around this the following modification needs to be made to dbproperty.php

## Modifying gorum/object.php

Change the function getVisibility as shown

## Adding New Database Fields

Firstly we need to add 7 new rows to our category database (Table:classifieds_classifiedscategory)
These are the new rows that I added. From the information you can see that imagesAllowed will have a range of 0-16, thumbSize 0-1024 and imageSize 0-2048. If these are too little or too much adjust accordingly so that it doesn't hog database space.
Here is the SQL Script for adding these

## Modifying Category.php

Add these to the top of the file just below this one shown. These tell Noah that we have added new fields to the database

## Modify lang_en.php as to stay consistent with language scheme

Now we also need to add the following to lang_en.php (and all the other languages you plan on using). For consistency add it after the comment that says "Category"

## Consistency and Assumptions

Images are saved under "$adAttDir/$this->id".".".$ext and their thumbnails "$adAttDir/th_$this->id".".".$ext. This format is not a problem for storing single images but is for storing multiple images. So we will be modifying it.
First to maintain backward compatibility we will keep the current format for the first image in the sequence however the second, third and nth image will have this pattern.
Full Image:"$adAttDir/$this->id"."-$i.".$this->picture
Thumbnails:"$adAttDir/th_$this->id"."-$i.".$this->picture
Where $i is the image number starting from 0 so if a user had six jpeg images they will be named as follows:
The function extensions will be saved into the picture row of the advertisement in a comma separated format "jpg,gif,jpg" we will then split this format into an array like this one array("jpg","gif","jpg").
So we will need to modify these functions and some others:
* delete
    This function is called when you remove the advertisement
* showListVal
    This function is called for every piece of information that is shown both in the advert listing and in the advert's details itself. We need this function so that it now lists all the pictures when viewing the advert details
* activateVariableFields
    This function needs to be modified so that it displays options for uploading n amount of images
* storeAttatchment
    Modify so that it actually stores all incoming images
* showDetials
    Shows the detailed view of the advertisement

## delete in Advertisement.php

Replace everything inside
With this so that the entire block looks like (Now any1 just dare tell me this doesn't look cleaner!!!)

## showListVal in advertisement.php

Replace everything in
With.

## hiding the original PICTURE element, advertisement.php

At the top of advertisement.php is $item_typ["attributes"]["picture"] = {..}; Add this to the array "form invisible", this will make sure that it is not added to the form when modifying/creating adds. The above-mentioned declaration will now look like this.
// Fixed on 2007-01-16

## ActivateVariableFields in advertisement.php

Modify the function as shown

## valid, advertisement.php

This function validates the single image that is uploaded before the image is stored. The rest of the validation is done by the class this one inherits from. Delete it all.

## storeAttachment, advertisement.php

This function has been modified almost entirely, just copy over the new function.

## showDetails, advertisement.php

Change everything inside
To be

## advertisement.php include image.php

at the top of the file call include("./image.php");

## Finally More Functions, advertisement.php

Add these new functions to the top of the file (advertisement.php) This first set can go anywhere before the class declaration
These second functions must be placed within the class. Place them just after
Okay

## gorum/form.php

Open gorum/form.php and modify generForm(..) by adding this to the massive if branch.

## gorum/generformlib_filebutton.php

Open gorum/generformlib_filebutton.php and go to generFileField(..) and copy the changes (or replace the entire function)

## gorum/object.php

Modify it to this

## constants.php

Add this anywhere in constants.php

## gorum/init.php

Add this to the bottom of function showHtmlHead

## Source Code

Download here: http://www.noah.inv.pl/forum/index.php?topic=228.msg656#msg656

## Trouble Shooting

Having trouble copying source from wiki?
Wiki errs on some of the characters.. many ' have been changed to ' and should be reverted

## Italian Language

The Italian language file has been translated. Here it is: