function generateFnImageAnnotationXmlV03()
 {
     // make sure <entry>...<entry> is clearly generated
     global $FN_FEED_PATH, $FN_FEED_STYLESHEET_PATH, $FN_FOTONOTES_DATA_PATH_PREFIX, $FILETYPES;
     global $ANNOTATIONS_ORIGINALS_FOLDER, $ANNOTATIONS_THUMBNAILS_FOLDER;
     $xml = null;
     // get unique uuid for feed
     $feed_uuid = getNewUUID();
     $this->param["feed_uuid"] = $feed_uuid;
     // get feed file destination based on today's date
     $createdtime = time();
     $year = gmdate("Y", $createdtime);
     $month = gmdate("m", $createdtime);
     $day = gmdate("d", $createdtime);
     $created = gmdate("Y-m-d\\TH:i:s\\Z", $createdtime);
     $storagepath = $FN_FEED_PATH . $year . "/" . $month . "/" . $day;
     $feed_file_path = $storagepath . "/" . $feed_uuid . ".xml";
     $this->param["feed_file_path"] = $feed_file_path;
     displayDebug("feed_file_path: {$feed_file_path}", 3);
     displayDebug("param[feed_file_path]: " . $this->param["feed_file_path"], 3);
     //make sure path exists
     createPath($storagepath);
     // parse incoming xml
     displayDebug("this->param[src_xml]", 2);
     displayDebugParam($this->param["src_xml"], 2);
     $entry_array = $this->parseEntryXML($this->param["src_xml"]);
     // ASSIGN *entry_array* values to *annotations* params
     foreach ($entry_array as $key => $value) {
         $this->setFnImageAnnotationParam($key, $value);
     }
     // fix uuid
     // first transform existing <id> in xml to <fn:id>
     //$xml = preg_replace("#<id>(.*)</id>#","<fn2:id>$1</fn2:id>",$xml);
     $this->param["src_xml"] = preg_replace("#<id>(.*)</id>#", "<fn:id>\$1</fn:id>", $this->param["src_xml"]);
     $entry_uuid = "<id>{$entry_array['id']}</id>\n";
     $parent_entry_id = $entry_array['parent_id'];
     $parent_entry_uuid = "<parent_uuid>" . $entry_array['parent_id'] . "</parent_uuid>";
     $parent_entry_array = null;
     //getEntriesXML2Array($parent_entry_id);
     //echo "\ngeom: ".$parent_entry_array['geometry']. "\n";
     $entry_geometry = "<geometry>" . $parent_entry_array['geometry'] . "</geometry>";
     // SET parent_image_link in fn_anntoation
     $this->param["parent_link_jpg"] = $parent_entry_array["link_jpg"];
     // PREPARE *make image* parameters
     displayDebug("<p>parent_entry_array: {$parent_entry_array}", 2);
     displayDebugParam($parent_entry_array, 2);
     $annotation_storagepath = $ANNOTATIONS_ORIGINALS_FOLDER . "/" . $year . "/" . $month . "/" . $day;
     displayDebug("annotation_storagepath: {$annotation_storagepath}", 1);
     // CHECK AND CREATE  *file path*
     createPath($annotation_storagepath);
     // PREPARE xml links for section of photo
     $entry_link_jpg = "http://" . $_SERVER['HTTP_HOST'] . preg_replace("#/fns/fotonotes.php#", "", $_SERVER['REQUEST_URI']) . $annotation_storagepath . '/' . $entry_array[id] . '.jpg';
     $entry_link_jpg = "http://" . $_SERVER['HTTP_HOST'] . preg_replace("#/fns/fotonotes2.php#", "", $_SERVER['REQUEST_URI']) . $annotation_storagepath . '/' . $entry_array[id] . '.jpg';
     displayDebug("\$entry_link_jpg: {$entry_link_jpg}", 3);
     // this won't always be jpg
     $entry_mimetype = "image/jpg";
     $entry_annotation_link = "<link href=\"{$entry_link_jpg}\" rel=\"annotated_region\" type=\"{$entry_mimetype}\" />";
     $entry_jpg_link = "<link href=\"{$entry_link_jpg}\" rel=\"jpg\" type=\"{$entry_mimetype}\" />";
     // WRITE annotated section of photo to file system
     displayDebug("\n fn_makeImage ({$parent_entry_array['link_jpg']}, " . str_replace(",", " ", $entry_array[boundingbox]) . ", 1,\n\t\t\tnull, null, {$annotation_storagepath}.'/'.{$entry_array['id']}.'.jpg')");
     fn_makeImage($parent_entry_array['link_jpg'], str_replace(",", " ", $entry_array[boundingbox]), 1, null, null, $annotation_storagepath . '/' . $entry_array[id] . '.jpg', 1);
     // PREPARE *make image* parameters for *thumbnail* of annotated region
     $annotation_thumbnail_storagepath = $ANNOTATIONS_THUMBNAILS_FOLDER . "/" . $year . "/" . $month . "/" . $day;
     displayDebug("annotation_storagepath: {$annotation_thumbnail_storagepath}", 3);
     // calculate thumbscale factor	- This needs to be better, to actually calculate scale!
     $thumbscale = 1;
     // CHECK AND CREATE  *file path* for *thumbnail* of annotated region
     createPath($annotation_thumbnail_storagepath);
     // PREPARE xml links for *thumbnail* of annotated region
     $entry_thumbnail_link_jpg = "http://" . $_SERVER['HTTP_HOST'] . preg_replace("#/fns/fotonotes.php#", "", $_SERVER['REQUEST_URI']) . $annotation_thumbnail_storagepath . '/' . $entry_array[id] . '.jpg';
     $entry_thumbnail_link_jpg = "http://" . $_SERVER['HTTP_HOST'] . preg_replace("#/fns/fotonotes2.php#", "", $_SERVER['REQUEST_URI']) . $annotation_thumbnail_storagepath . '/' . $entry_array[id] . '.jpg';
     // this won't always be jpg
     $entry_mimetype = "image/jpg";
     $entry_mimetype_thn = "image/thn-jpg";
     $entry_thumbnail_link = "<link href=\"{$entry_link_jpg}\" rel=\"annotated region image\" type=\"{$entry_mimetype}\" />";
     $entry_annotation_thumbnail_link = "<link href=\"{$entry_thumbnail_link_jpg}\" rel=\"thn\" type=\"{$entry_mimetype_thn}\" />";
     // this won't always be jpg
     $parent_entry_mimetype = "image/jpg";
     $parent_entry_url = "";
     $parent_entry_link = "<link href=\"\" rel=\"annotated image\" type=\"{$parent_entry_mimetype}\" />";
     // WRITE *thumbnail of annotated section of photo to file system
     fn_makeImage($parent_entry_array['link_jpg'], str_replace(",", " ", $entry_array[boundingbox]), $thumbscale, null, null, $annotation_thumbnail_storagepath . '/' . $entry_array[id] . '.jpg');
     // Almost done - just need to create annotation entry xml, store it properly, and put feed on file system.
     // BUILD *annotation entry xml*
     // this needs fixing - what should $xml be that is getting replaced?
     $xml_entryinfo = preg_replace("#<entry>#", "<entry title=\"FotoNotes Annotation\" type=\"fn\" " . " xmlns:fn=\"http://fotonotes.net/protocol/fotonotes_0.2\">" . $entry_uuid . $entry_geometry . $entry_jpg_link . $entry_annotation_link . $entry_annotation_thumbnail_link . $parent_entry_uuid, $this->param["src_xml"]);
     $xml_entryinfo = preg_replace("#<([a-zA-Z])#", "\n<\$1", $xml_entryinfo);
     $xml_entryinfo = preg_replace("#</fn:selection>#", "\n</fn:selection>", $xml_entryinfo);
     $xml_entryinfo = preg_replace("#</author>#", "\n</author>", $xml_entryinfo);
     $xml_entryinfo = preg_replace("#</entry>#", "\n</entry>", $xml_entryinfo);
     displayDebug("xml_entryinfo: ", 2);
     displayDebugParam($xml_entryinfo, 2);
     $this->param["xml_entryinfo"] = $xml_entryinfo;
     displayDebug("generateFnImageAnnotationXml xml_entryinfo:", 2);
     displayDebugParam($this->param["xml_entryinfo"]);
     return $this->param["xml_entryinfo"];
 }
 function doFnAction()
 {
     global $FNSAVESTRATEGY, $FNRETRIEVESTRATEGY, $FNANNOTATIONFEEDSAVESTRATEGY, $FN_FOTONOTES_DATA_PATH_PREFIX;
     displayDebugParam($this->param, 3);
     switch ($this->param["action"]) {
         case "display":
             // GET  annotations for this image
             // UPDATE DOM to include the modified image.
             displayDebug("action: display \n display image: " . $this->param["image"], 3);
             displayDebug("action: display \n display image_path: " . $this->param["image_path"], 3);
             // Get scaling information
             $this->getAnnotationScaling();
             $annotations = $this->getAnnotations();
             displayDebugParam($annotations, 5);
             $annotationsHTML = $this->getAnnotationsHTMLFromAnnotations($annotations);
             // PRINT annotationsHTML out to send back to client. This pushed back correct information.
             echo "displayHTML##{$annotationsHTML}##";
             break;
         case "add":
             // ADD annotation
             // prompt for password?
             if ($this->param['ADD'] == 'prompt' && $this->param['password'] != $this->param['PASSWORD']) {
                 die('success=denied');
             }
             // CREATE new FNAnnotation (FNImage)
             $fna = new FNImageAnnotation($this);
             // create a uuid for entry
             $id_number = getNewUUID();
             $this->setFnImageParam("annotationID", $id_number);
             $fna->setFnImageAnnotationParam("annotationID", $id_number);
             $id = preg_replace("#([^/]*\\.jpg)#Umsi", "{$id_number}@\$1", $this->param["image"]);
             displayDebug("id: {$id}", 3);
             displayDebug("annotationID: " . $this->param['annotationID'], 1);
             displayDebugParam($this->param['xml'], 1);
             $this->param["xml"] = preg_replace("#<issued>.*</issued>#Umsi", "", $this->param["xml"]);
             $this->param["xml"] = preg_replace("#<created>.*</created>#Umsi", "", $this->param["xml"]);
             $this->param["xml"] = preg_replace("#<modified>.*</modified>#Umsi", "", $this->param["xml"]);
             //$link_alt = "<link rel=\"alternate\" type=\"text/html\"><![CDATA[$FN_FOTONOTES_DISPLAY_SCRIPT"."&entry_ID=$id_number"."]]></link> ";
             //$link_alt = "<link rel=\"alternate\" type=\"text/html\" href=\"$FN_FOTONOTES_DISPLAY_SCRIPT&amp;entry_ID=$id_number\" /> ";
             $timestamp = $this->param["timestamp"];
             $this->param["xml"] = preg_replace("#<entry>#Umsi", "<entry><id>{$id}</id>{$link_alt}<issued>{$timestamp}</issued><created>{$timestamp}</created><modified>{$timestamp}</modified>", $this->param["xml"]);
             displayDebug("xml:", 3);
             displayDebugParam($this->param['xml'], 3);
             // SET annotation's xml parameter from image
             $fna->setFnImageAnnotationParam("src_xml", $this->param["xml"]);
             $fna_xml = $fna->generateFnImageAnnotationXml();
             // also creates thumbnails currently
             // PERFORM save
             $results = $this->saveNewAnnotation($fna);
             displayDebug("and results here are: {$results}", 4);
             if (!$results) {
                 echo "success=error";
                 break;
             }
             // SAVE *anotation feed file* in each place indicated by configuration settings
             if ($FNANNOTATIONFEEDSAVESTRATEGY["FNAnnotationFeedSaveXmlFile"]) {
                 $fnafsave = new FNAnnotationFeedSaveXmlFile();
                 $fnafsave->updateFNAnnotationFeed($this, $fna);
             }
             echo 'success=ok';
             break;
         case "modify":
             // UPDATE annotation
             // prompt for password?
             if ($this->param['MODIFY'] == 'prompt' && $this->param['password'] != $this->param['PASSWORD']) {
                 die('success=denied');
             }
             // CREATE new FNAnnotation (FNImage)
             displayDebug("action: modify", 2);
             $fna = new FNImageAnnotation($this);
             displayDebug("xml is: " . $this->param["xml"], 2);
             preg_match("#<id>(.*)</id>#", $this->param["xml"], $matches);
             displayDebug("annotation id to delete/update: " . $matches[1], 2);
             $fna->setFnImageAnnotationParam("id", $matches[1]);
             $this->setFnImageParam("annotationID", $matches[1]);
             $fna->setFnImageAnnotationParam("annotationID", $matches[1]);
             $id = preg_replace("#([^/]*\\.jpg)#Umsi", $matches[1] . "@\$1", $this->param["image"]);
             //displayDebug("id: $id", 3);
             displayDebug("annotationID: " . $this->param['annotationID'], 1);
             displayDebugParam($this->param['xml'], 1);
             // GET old date information
             $annotations = $this->getAnnotations();
             // LOOP through existing annotations to get old information
             for ($i = 0; $i < count($annotations); $i++) {
                 displayDebug("looking at id: " . $annotations[$i]['id'], 4);
                 if ($annotations[$i]['id'] == $this->param['annotationID']) {
                     // Found the correct annotation data
                     $originalcreated = $annotations[$i]['created'];
                     $originalissued = $annotations[$i]['issued'];
                 }
             }
             displayDebug("originalcreated: {$originalcreated}; originalissued: {$originalissued}", 4);
             $this->param["xml"] = preg_replace("#<issued>.*</issued>#Umsi", "", $this->param["xml"]);
             $this->param["xml"] = preg_replace("#<created>.*</created>#Umsi", "", $this->param["xml"]);
             $this->param["xml"] = preg_replace("#<modified>.*</modified>#Umsi", "", $this->param["xml"]);
             //$link_alt = "<link rel=\"alternate\" type=\"text/html\"><![CDATA[$FN_FOTONOTES_DISPLAY_SCRIPT"."&entry_ID=$id_number"."]]></link> ";
             //$link_alt = "<link rel=\"alternate\" type=\"text/html\" href=\"$FN_FOTONOTES_DISPLAY_SCRIPT&amp;entry_ID=$matches[1]\" /> ";
             $timestamp = $this->param["timestamp"];
             $this->param["xml"] = preg_replace("#<entry>#Umsi", "<entry><id>{$id}</id>{$link_alt}<issued>{$originalissued}</issued><created>{$originalcreated}</created><modified>{$timestamp}</modified>", $this->param["xml"]);
             displayDebugParam($this->param['xml'], 3);
             $fna->setFnImageAnnotationParam("src_xml", $this->param["xml"]);
             // UPDATE annotationXMLBlock
             $this->param['annotationXMLBlock'] = preg_replace("#(<entry><id>" . $this->param['annotationID'] . "</id>.*</entry>)#Umsi", $fna->param['src_xml'], $this->param['annotationXMLBlock']);
             $fna->param['annotationXMLBlock'] = preg_replace("#(<entry><id>" . $this->param['annotationID'] . "</id>.*</entry>)#Umsi", $fna->param['src_xml'], $this->param['annotationXMLBlock']);
             // UPDATE *existing annotation*
             $results = $this->updateExistingAnnotationByID($fna);
             if (!$results) {
                 echo "success=error";
                 break;
             }
             /*
             // SAVE *anotation feed file* in each place indicated by configuration settings
             if ($FNANNOTATIONFEEDSAVESTRATEGY["FNAnnotationFeedSaveXmlFile"]) {
             	$fnafsave = new FNAnnotationFeedSaveXmlFile;
             	$fnafsave->saveFNAnnotationFeed($this, $fna); 
             }
             */
             echo 'success=ok';
             break;
         case "delete":
             displayDebug("action: delete", 2);
             // prompt for password?
             if ($this->param['DELETE'] == 'prompt' && $this->param['password'] != $this->param['PASSWORD']) {
                 die('success=denied');
             }
             $fna = new FNImageAnnotation($this);
             displayDebug("xml is: " . $this->param["xml"], 2);
             preg_match("#<id>(.*)</id>#", $this->param["xml"], $matches);
             displayDebug("annotation id to delete: " . $matches[1], 2);
             $fna->setFnImageAnnotationParam("id", $matches[1]);
             // DELETE *existing annotation*
             $results = $this->deleteAnnotationByID($fna);
             echo 'success=ok';
             break;
         case "annotationfeed":
             displayDebug("action: annotationfeed", 2);
             break;
     }
 }