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

In Noah's classifieds an advert can only submit one image, we want to submit n images.

## Solution

Modify the source as listed bellow

## Preliminary Coding

Before we do anything I would like to wrap Noah's image operations into a class or at least a bunch of functions. The person/people who coded it initially did not do this. This in my opinion is a big mistake as it greatly complicates the code.
The following is derived from the Noah source code and my own genius common sense. All of these will be placed in a new file which we will call image.php. The idea is to create an image management library that we can use with other projects without much recoding
Image.php Source

## Target Functionality

Now let's first talk about our target. We want the following features:
* Modify the maximum amount of images saved from the set category screen (so each category can allow for a variable number of images)
* Modify the Maximum Image Size and Thumb size from category screen
* The first image uploaded in the series will be used as the display image when listing all the adverts
* Images and their thumbs must be removed when an advertisement is removed
* Each different category must be able to insert custom html text which will be used as a spacer.
* Dynamically create the upload fields so submission is not cluttered

## 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

## Modifying Categories

Firstly we need to add 6 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 the Source of category.php
Because of the lovely framework the Noah uses we can easily just add more fields to the categories. Simply add these lines at the top of file.
Adding the new texts to the language file(s)
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"

## Modifying Advertisements

In table classifieds_advertisement we won't be adding any rows. Instead we will modify an existing row called picture.
Picture is a STRING (VARCHAR) of size 250. At the moment Noah stores the extension of the 1 image that is uploaded into picture. We will be doing something very similar, we will store the extensions of the files but have them comma separated. So the first extension is the first image and the second extension the second and so on.
Now we must modify the source of advertisements.php This is going to be heavy modification so lets first agree on the current functionality.
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 compatibality 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 6 jpeg images they will be named as follows:
We need a function that splits a string like "jpg,gif,jpg" into array("jpg","gif","jpg"). Such a function has been created in image.php called getImageExtensionsFromString($string)
So we will need to modify 4 functions I believe:
* 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

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

## showListVal

Replace everything in
$s is the output buffer of the function. All HTML must be written to it. The first thing we do is make $s equal to the default image icon. This is so that if no images were found at least the default icon is shown. Next we see if picture has any text inside it (remember in php "" or 0 or "0" are all considered 'false'). So if there are pictures in it we progress. Extracting the image extensions using getImageExtensions;. Then depending on the whether this is a listing or a detailed view we print either the first or all of the images to the buffer.

## activateVariableFields

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.
Now the next part will ensure that when the methods CREATE_FORM and MODIFY_FORM are called the image fields are added to the forms. Add this just after the global definitions.

## valid

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. Just delete the entire thing.

## storeAttachment

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

## showDetails

Change everything inside
To be

## Finally More Functions

Add these new functions to the top of the file
Notice one half above the class and the other inside the class.
Image.php Source