= 1){ $moduleName = $modIdenArray[0]; // Lowercase the first letter for use in including the file. $moduleName = lcfirst( $moduleName ); if($type == "module"){ if( is_file( 'mod/'.$moduleName.'mod.php' ) ) { include_once( 'mod/'.$moduleName.'mod.php' ); } } else if($type == "item"){ if(is_file("item/$moduleName.php")){ include_once "item/$moduleName.php"; } } $moduleName = ucfirst($moduleName); if($type == "module"){ $moduleName .= "Module"; } $moduleId = getVal($modIdenArray, 1); $subItemId = getVal($modIdenArray, 2); if(class_exists($moduleName) && ($moduleName != "UserModule")){ $user_id = getVal($_POST, "user_id"); if($user_id == ""){ $user_id = getVal($_GET, $mode); } if($user_id == ""){ $user = getUser(); // if this is wrong, the items just won't load anyway. }else{ $user = new User(); $user->loadById( $user_id ); } try{ if($type == "module"){ eval("\$moduleObj = @new $moduleName(\$user, \$moduleId);"); } else if($type == "item"){ eval("\$moduleObj = @new $moduleName();"); $moduleObj->loadById($moduleId); } // Handlers for user-module operations (item-operations are below). //if(is_a($moduleObj, "UserModule") && (method_exists($moduleObj, "processEditForm"))){ if( $type == "module" && method_exists($moduleObj, "processEdit") ){ $worked = true; if($mode == "editMod"){ try{ $moduleObj->processEdit(); } catch(Exception $e){ dispMsg($e->getMessage()); } $moduleObj->LoadMod(); $moduleId = "module_".$moduleObj->getModuleClass().( ($moduleObj->getId() === "" ) ? "_" : "_".$moduleObj->getId() ); print ""; print $moduleObj->getContent(); } else if($mode == "addMod"){ $item_id = false; try{ $item_id = $moduleObj->processAdd(); } catch(Exception $e){ dispMsg($e->getMessage()); } //$moduleObj->LoadMod(); //print $moduleObj->getContent(); if( $item_id != false ){ print $moduleObj->getItemHTML( $item_id ); }else{ dispError("Error adding item, please try again."); } } else { // TODO: logEvent that the command is not recognized. //dispError(STR_ERR_UNAVAILABLE); dispError("Object instantiated was a UserModule, but mode \"$mode\" was not recognized."); $worked = false; } //} else if(is_a($moduleObj, "Item")){ }else if( $type == "item" ){ // Handlers for Item operations $worked = true; if($mode == "startEditItem"){ print $moduleObj->getEditItemForm(); } else if($mode == "getItem"){ print $moduleObj->getHTML(); } else if($mode == "editItem"){ $moduleObj->processEditItemForm(); print $moduleObj->getHTML(); } else if($mode == "deleteItem"){ print (($moduleObj->delete())?"1":"0"); // prints 1 on success, 0 on failure } else if($mode == "deleteSubItem"){ print (($moduleObj->deleteSubItem($subItemId))?"1":"0"); // prints 1 on success, 0 on failure } else if($mode == "addItem"){ $parentName = lcfirst( getPost('parentName') ); $parentId = getPost('parentId'); if(($parentName != "") && ($parentId != "")){ if(is_file("item/$parentName.php")){ include_once "item/$parentName.php"; $item_id = false; try{ $item_id = $moduleObj->processMake(); }catch(Exception $e){ dispMsg($e->getMessage()); } print $moduleObj->getSubItemHTML( $item_id, $parentName, $parentId ); } else { // print "Parent file not found\n"; // TODO: REMOVE } /*if($moduleObj->processMakeItemForm()){ if(is_file("item/$parentName.php")){ include_once "item/$parentName.php"; } else { // print "Parent file not found\n"; // TODO: REMOVE } if(class_exists($parentName)){ eval("\$parentObj = @new $parentName();"); $parentObj->setId($parentId); if(method_exists($parentObj, "getSubListContent")){ print $parentObj->getSubListContent($moduleName,$parentId); } else { // print "Method doesn't exist"; // TODO: REMOVE } } else { // print "Invalid parent: \"$parentName\""; // TODO:REMOVE } } else { // print "Couldn't create item"; // TODO: REMOVE }*/ } else { // print "Couldn't find parent name/id"; // TODO: REMOVE } } else { // TODO: logEvent that the command is not recognized and change the error to the default UNAVAILABLE message. //dispError(STR_ERR_UNAVAILABLE); dispError("Object instantiated was an item, but item mode \"$mode\" not recognized."); // STRINGTABLES $worked = false; } } } catch(Exception $e){ dispMsg($e->getMessage()); } } } if($worked === false){ // TODO: REINSTATE THE UNAVAIALBLE MESSAGE (a good default that will tide people over until we can fix the problem). //dispError(STR_ERR_UNAVAILALBE); dispError("Successful result not found"); } } //// // Takes a specific command and executes pre-defined functionality for it. // NOTE: If this grows rather large, it may be best to separate it into another file // to limit the amount of code included and to be less confusing. //// function ajaxCommand($cmd){ $db = dil_connect(); switch($cmd){ case "albumMaker_upload": include_once "includes/albumMaker_uploader.php"; break; default: print "Command not recognized: \"$cmd\"\n"; } } // end ajaxCommand ?>