Here's a few recommendations:
* You need to make sure to sanitize any data before you attempt to put it into the database.
* Pay close attention to camelcase when creating/using class names.
NOTE: The code below has not been tested so you might find some syntax errors, etc. but I think it should work pretty much 'as is'.
in ./modules/tutorial/capture.php
//Capture Softwares
require('../../mainfile.php');
require(XOOPS_ROOT_PATH.'/header.php');
global $xoopsTpl, $xoopsOption, $xoopsUser;
$myts =& MyTextSanitizer::getInstance();
if(!(is_object($xoopsUser))){
echo('you need to be logged in to Capture Softwares.');
}
$op ='';
if(isset($_POST['op'])) {
$op = $_POST['op'];
}
switch($op) {
case 'post':
$SoftwaresSoftwareHandler =& xoops_getModuleHandler('software','tutorial');
$software_id = (!empty($_POST['software_id'])) ? (int) $_POST['software_id'] : 0 ;
$software_title = (isset($_POST['software_title'])) ? $myts->addSlashes($_POST['software_title'] : '';
$publisher = (isset($_POST['publisher'])) ? $myts->addSlashes($_POST['publisher'] : '';
$license_key = (isset($_POST['license_key'])) ? $myts->addSlashes($_POST['license_key'] : '';
$total_no_licenses = (isset($_POST['total_no_licenses']) && ((int)$_POST['total_no_licenses'] > 0)) ? (int)($_POST['total_no_licenses']) : 0;
$Softwareobj->setVar('software_title') = $software_title;
$Softwareobj->setVar('publisher') = $publisher;
$Softwareobj->setVar('total_no_licenses') = $total_no_licenses;
$Softwareobj->setVar("S_Date", time());
$Softwareobj->setVar("userid", $GLOBALS['xoopsUser']->getVar("uid"));
if (0 >= $software_id) {
$Softwareobj = $SoftwaresSoftwareHandler->create();
} else {
$Softwareobj = $SoftwaresSoftwareHandler->get($software_id);
}
}
if(!($SoftwaresSoftwareHandler->insert($Softwareobj))){
echo "Error";
} else {
echo "successful";
}
if($SoftwareObj->isNew() && (is_object($xoopsUser))) { //update User posts
$uid = $xoopsUser->getVar('uid');
if ($uid > 0) {
$member_handler =& xoops_gethandler('member');
$poster =& $member_handler->getUser($uid);
if (is_object($poster)) {
$member_handler->updateUserByField($poster, 'posts', $poster->getVar('posts') + 1);
}
}
}
//return true;
require(XOOPS_ROOT_PATH.'/footer.php');
?>
in ./modules/tutorial/class/software.php
if (!defined("XOOPS_ROOT_PATH")) { die('root path not defined');
}
class tutorialSoftware extends XoopsObject {
var $_groups_read = null;
function tutorialSoftware()
{
$this->__construct();
}
function __construct()
{
// $this->XoopsObject();
$this->initVar('software_id', XOBJ_DTYPE_INT);
$this->initVar('software_title', XOBJ_DTYPE_TXTBOX,null,255);
$this->initVar('publisher', XOBJ_DTYPE_TXTBOX,null,255);
$this->initVar('license_key', XOBJ_DTYPE_TXTBOX,null,255);
$this->initVar('total_no_licenses', XOBJ_DTYPE_INT);
$this->initVar('S_Date', XOBJ_DTYPE_INT);
$this->initVar('userid', XOBJ_DTYPE_INT);
}
}
class tutorialSoftwareHandler extends XoopsPersistableObjectHandler
{
function SoftwaresSoftwareHandler(&$db)
{
$this->__construct($db);
}
function __construct(&$db)
{
parent::__construct($db,'software_myform','tutorialSoftware', 'software_id');
}
}
?>
Your form file should be okay. Although the way it's implemented will only let you add new objects to the database, you will need to modify the form to allow you to edit existing objects.
Hope this helps you get started...