Location: PHPKode > projects > Epiware Document Management > Epiware_4.8.6/epi/forms_class.inc.php
<?
/******************************************************************************
Epiware: Project and Document Management
http://www.epiware.com
Copyright (C) 2006 James Kern

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. 

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details. 

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Epiware, Inc. and Praxis Inc, hereby disclaims all copyright
interest in the program 'Epiware' written
by James Kern, Edward Kline, Ryan Gilfether, Ray Gorospe, Patrick Waddingham

06 September 2006
James Kern, President of Epiware 
Jack Chapman, President of Praxis
*****************************************************************************/ 
/**
*	@package forms
*/
/**#@+
*	Database table name constants
*
*	Constant used for database table name so that table may be kept either in the same database as EPIware or in
*	a seperate database.
*/
define("DB_TABLE_FORMS","forms");
define("DB_TABLE_FORMS_ANSWERS","forms_answers");
define("DB_TABLE_FORMS_QUESTIONS","forms_questions");
define("DB_TABLE_FORMS_SECTIONS","forms_sections");
define("DB_TABLE_FORMS_COMPLETED","forms_completed");
define("DB_TABLE_FORMS_QUESTIONS_TYPES","forms_questions_types");

/**#@-*/
//################################################################################################
/**
*	Database interaction class for forms.
*
*	@package forms
*/
class forms
{

	function forms()
	{
	}
	/**#@+
	*
	*	@param object $db instance of the database class object
	*	@param boolean $mq status of magic quotes as it pertains to the values of $obj properties
	*/

	/**
	*	Select all fields for a given record
	*	@param	int	$form_id
	*	@return resource database result resource
	*/
	function &get(&$db,$form_id="")
	{
		$sql= "select form_id,title,description ";
		$sql.= "from ".DB_TABLE_FORMS." ";
		if($form_id!="")
			$sql.= "where form_id=".$db->qstr($form_id);

		return($result = $db->perform_looping_query($sql));
	}//end of function get

	/**
	*	Insert one record into the database
	*	@param	object	$obj object with the following properties: form_id,title
	*	@return boolean database result or false
	*/
	function insert(&$obj,&$db,$mq=false)
	{
		//increment table used
		$next_id = $db->get_next_id(DB_TABLE_FORMS);
		$obj->form_id = $next_id;

//		$aaa = forms_sections::get_all_by_form($);

		if($obj->form_id > 0)
		{
			$sql= "insert into ".DB_TABLE_FORMS." (";
			$sql.= "form_id,title,description) ";
			$sql.= "values (";
			$sql.= $obj->form_id.",";
			$sql.= $db->qstr($obj->title,$mq).",";
			$sql.= $db->qstr($obj->description,$mq).")";

			$section->title = "Section # 1";
			$section->description = "This is the first, default section. Unless new sections are created all questions will go here.";
			$section->form_id = $obj->form_id;
			$aaa = forms_sections::insert($section,$db,true);

			return ($db->perform_action_query($sql));
		}//end of if a new key was returned
		else
		{
			return false;
		}
	}//end of function insert

	/**
	*	Update one record into the database
	*	@param	object	$obj object with the following properties: form_id,title
	*	@return boolean database result or false
	*/
	function update(&$obj,&$db,$mq=false)
	{
		$sql= "update ".DB_TABLE_FORMS." set ";
		$sql.= "form_id=".$obj->form_id.",";
		$sql.= "title=".$db->qstr($obj->title,$mq).",";
		$sql.= "description=".$db->qstr($obj->description,$mq)." ";
		$sql.= "where form_id=".$obj->form_id."";

		return ($db->perform_action_query($sql));
	}//end of function update

	/**
	*	Delete one record into the database
	*	@param	object	$obj object with the following properties: form_id
	*	@return boolean database result or false
	*/
	function delete($obj,&$db)
	{
		$sql= "delete from ".DB_TABLE_FORMS." ";
		$sql.= "where form_id=".$obj->form_id."";

		return ($db->perform_action_query($sql));
	}//end of function delete
/**#@-*/

	/**
	*	Initializes an object to default values
	*	@param	object 	object to be initialized
	*/
	function init_object(&$obj)
	{
		$obj->form_id = 0;
		$obj->title = "";
	}//end of init_object 
}//end of class forms
//################################################################################################
/**
*	Database interaction class for forms_answers.
*
*	@package forms
*/
class forms_answers
{

	function forms_answers()
	{
	}
	/**#@+
	*
	*	@param object $db instance of the database class object
	*	@param boolean $mq status of magic quotes as it pertains to the values of $obj properties
	*/

	/**
	*	Select all fields for a given record
	*	@param	int	$form_id
	*	@param	int	$section_id
	*	@param	int	$question_id
	*	@param	int	$answer_id
	*	@return resource database result resource
	*/
	function &get($form_id,$section_id,$question_id,$answer_id,&$db)
	{
		$sql= "select form_id,section_id,question_id,answer_id,answer,value ";
		$sql.= "from ".DB_TABLE_FORMS_ANSWERS." ";
		$sql.= "where form_id=$form_id and section_id=$section_id and question_id=$question_id and answer_id=$answer_id";

		return($result = $db->perform_looping_query($sql));
	}//end of function get

	function get_answers($form_id,$section_id,$question_id,&$db)
	{
		$sql= "select form_id,section_id,question_id,answer_id,answer,value ";
		$sql.= "from ".DB_TABLE_FORMS_ANSWERS." ";
		$sql.= "where form_id=$form_id and section_id=$section_id and question_id=$question_id";

		return($result = $db->perform_looping_query($sql));
	}//end of function get



	/**
	*	Insert one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id,question_id,answer_id,answer
	*	@return boolean database result or false
	*/
	function insert(&$obj,&$db,$mq=false)
	{
		//increment table used
		$fields["form_id"] = $obj->form_id;
		$fields["section_id"] = $obj->section_id;
		$fields["question_id"] = $obj->question_id;
		$next_id = $db->get_next_complex_id($fields,"forms_answers");
		$obj->answer_id = $next_id;

		if($obj->answer_id > 0)
		{
			$sql= "insert into ".DB_TABLE_FORMS_ANSWERS." (";
			$sql.= "form_id,section_id,question_id,answer_id,answer) ";
			$sql.= "values (";
			$sql.= $obj->form_id.",";
			$sql.= $obj->section_id.",";
			$sql.= $obj->question_id.",";
			$sql.= $obj->answer_id.",";
			$sql.= $db->qstr($obj->answer,$mq).")";

			return ($db->perform_action_query($sql));
		}//end of if a new key was returned
		else
		{
			return false;
		}
	}//end of function insert

	/**
	*	Update one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id,question_id,answer_id,answer
	*	@return boolean database result or false
	*/
	function update(&$obj,&$db,$mq=false)
	{
		$sql= "update ".DB_TABLE_FORMS_ANSWERS." set ";
		$sql.= "form_id=".$obj->form_id.",";
		$sql.= "section_id=".$obj->section_id.",";
		$sql.= "question_id=".$obj->question_id.",";
		$sql.= "answer_id=".$obj->answer_id.",";
		$sql.= "answer=".$db->qstr($obj->answer,$mq)." ";
		$sql.= "where form_id=".$obj->form_id." and section_id=".$obj->section_id." and question_id=".$obj->question_id." and answer_id=".$obj->answer_id."";

		return ($db->perform_action_query($sql));
	}//end of function update

	/**
	*	Delete one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id,question_id,answer_id
	*	@return boolean database result or false
	*/
	function delete($obj,&$db)
	{
		$sql= "delete from ".DB_TABLE_FORMS_ANSWERS." ";
		$sql.= "where form_id=".$obj->form_id." and section_id=".$obj->section_id." and question_id=".$obj->question_id." and answer_id=".$obj->answer_id."";

		return ($db->perform_action_query($sql));
	}//end of function delete
/**#@-*/

	/**
	*	Initializes an object to default values
	*	@param	object 	object to be initialized
	*/
	function init_object(&$obj)
	{
		$obj->form_id = 0;
		$obj->section_id = 0;
		$obj->question_id = 0;
		$obj->answer_id = 0;
		$obj->answer = "";
	}//end of init_object 
}//end of class forms_answers

//################################################################################################
/**
*	Database interaction class for forms_questions.
*
*	@package forms
*/
class forms_questions
{

	function forms_questions()
	{
	}
	/**#@+
	*
	*	@param object $db instance of the database class object
	*	@param boolean $mq status of magic quotes as it pertains to the values of $obj properties
	*/

	/**
	*	Select all fields for a given record
	*	@param	int	$form_id
	*	@param	int	$section_id
	*	@param	int	$question_id
	*	@return resource database result resource
	*/
	function &get($form_id,$section_id,$question_id,&$db)
	{
		$sql= "select form_id,section_id,question_id,question_number,question_text,question_type,question_output ";
		$sql.= "from ".DB_TABLE_FORMS_QUESTIONS." ";
		$sql.= "where form_id=$form_id and section_id=$section_id and question_id=$question_id";

		return($result = $db->perform_looping_query($sql));
	}//end of function get


	function get_all_by_section($form_id,$section_id,&$db)
	{
		$sql= "select form_id,section_id,question_id,question_number,question_text,question_type,question_output  ";
		$sql.= "from ".DB_TABLE_FORMS_QUESTIONS." ";
		$sql.= "where form_id=".$db->qstr($form_id)." and section_id=".$db->qstr($section_id);

		return($result = $db->perform_looping_query($sql));
	}

	/**
	*	Insert one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id,question_id,question_number,question_text,question_type
	*	@return boolean database result or false
	*/
	function insert(&$obj,&$db,$mq=false)
	{
		//increment table used
		$fields["form_id"] = $obj->form_id;
		$fields["section_id"] = $obj->section_id;
		$next_id = $db->get_next_complex_id($fields,"forms_questions");
		$obj->question_id = $next_id;

		if($obj->question_id > 0)
		{
			switch($obj->question_type)
			{
				case 0:
					$sql= "insert into ".DB_TABLE_FORMS_QUESTIONS." (";
					$sql.= "form_id,section_id,question_id,question_number,question_text,question_type,question_output) ";
					$sql.= "values (";
					$sql.= $db->qstr($obj->form_id).",";
					$sql.= $db->qstr($obj->section_id).",";
					$sql.= $db->qstr($obj->question_id).",";
					$sql.= $db->qstr($obj->question_number).",";
					$sql.= $db->qstr($obj->question_text,$mq).",";
					$sql.= $db->qstr($obj->question_type).",";
					$sql.= $db->qstr($obj->question_output).")";
					break;
			}


			return ($db->perform_action_query($sql));
		}//end of if a new key was returned
		else
		{
			return false;
		}
	}//end of function insert

	/**
	*	Update one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id,question_id,question_number,question_text,question_type
	*	@return boolean database result or false
	*/
	function update(&$obj,&$db,$mq=false)
	{
		$sql= "update ".DB_TABLE_FORMS_QUESTIONS." set ";
		$sql.= "form_id=".$obj->form_id.",";
		$sql.= "section_id=".$obj->section_id.",";
		$sql.= "question_id=".$obj->question_id.",";
		$sql.= "question_number=".$obj->question_number.",";
		$sql.= "question_text=".$db->qstr($obj->question_text,$mq).",";
		$sql.= "question_type=".$obj->question_type." ";
		$sql.= "where form_id=".$obj->form_id." and section_id=".$obj->section_id." and question_id=".$obj->question_id."";

		return ($db->perform_action_query($sql));
	}//end of function update

	/**
	*	Delete one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id,question_id
	*	@return boolean database result or false
	*/
	function delete($obj,&$db)
	{
		$sql= "delete from ".DB_TABLE_FORMS_QUESTIONS." ";
		$sql.= "where form_id=".$obj->form_id." and section_id=".$obj->section_id." and question_id=".$obj->question_id."";

		return ($db->perform_action_query($sql));
	}//end of function delete
/**#@-*/

	/**
	*	Initializes an object to default values
	*	@param	object 	object to be initialized
	*/
	function init_object(&$obj)
	{
		$obj->form_id = 0;
		$obj->section_id = 0;
		$obj->question_id = 0;
		$obj->question_number = 0;
		$obj->question_text = "";
		$obj->question_type = 0;
	}//end of init_object 
}//end of class forms_questions
//################################################################################################
/**
*	Database interaction class for forms_sections.
*
*	@package forms
*/
class forms_sections
{

	function forms_sections()
	{
	}
	/**#@+
	*
	*	@param object $db instance of the database class object
	*	@param boolean $mq status of magic quotes as it pertains to the values of $obj properties
	*/

	/**
	*	Select all fields for a given record
	*	@param	int	$form_id
	*	@param	int	$section_id
	*	@return resource database result resource
	*/
	function &get($form_id,$section_id,&$db)
	{
		$sql= "select form_id,section_id,title,description ";
		$sql.= "from ".DB_TABLE_FORMS_SECTIONS." ";
		$sql.= "where form_id=$form_id and section_id=$section_id";

		return($result = $db->perform_looping_query($sql));
	}//end of function get

	function get_all_by_form($form_id,&$db)
	{
		$sql= "select form_id,section_id,title,description ";
		$sql.= "from ".DB_TABLE_FORMS_SECTIONS." ";
		$sql.= "where form_id=".$db->qstr($form_id);

		return($result = $db->perform_looping_query($sql));
	}//end of function get

	/**
	*	Insert one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id,title
	*	@return boolean database result or false
	*/
	function insert(&$obj,&$db,$mq=false)
	{
		//increment table used
		$fields["form_id"] = $obj->form_id;
		$next_id = $db->get_next_complex_id($fields,"forms_sections");
		$obj->section_id = $next_id;

		if($obj->section_id > 0)
		{
			$sql= "insert into ".DB_TABLE_FORMS_SECTIONS." (";
			$sql.= "form_id,section_id,title,description) ";
			$sql.= "values (";
			$sql.= $obj->form_id.",";
			$sql.= $obj->section_id.",";
			$sql.= $db->qstr($obj->title,$mq).",";
			$sql.= $db->qstr($obj->description,$mq).")";

			return ($db->perform_action_query($sql));
		}//end of if a new key was returned
		else
		{
			return false;
		}
	}//end of function insert

	/**
	*	Update one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id,title
	*	@return boolean database result or false
	*/
	function update(&$obj,&$db,$mq=false)
	{
		$sql= "update ".DB_TABLE_FORMS_SECTIONS." set ";
		$sql.= "form_id=".$obj->form_id.",";
		$sql.= "section_id=".$obj->section_id.",";
		$sql.= "title=".$db->qstr($obj->title,$mq).",";
		$sql.= "description=".$db->qstr($obj->description,$mq)." ";
		$sql.= "where form_id=".$obj->form_id." and section_id=".$obj->section_id."";

		return ($db->perform_action_query($sql));
	}//end of function update

	/**
	*	Delete one record into the database
	*	@param	object	$obj object with the following properties: form_id,section_id
	*	@return boolean database result or false
	*/
	function delete($obj,&$db)
	{
		$sql= "delete from ".DB_TABLE_FORMS_SECTIONS." ";
		$sql.= "where form_id=".$obj->form_id." and section_id=".$obj->section_id."";

		return ($db->perform_action_query($sql));
	}//end of function delete
/**#@-*/

	/**
	*	Initializes an object to default values
	*	@param	object 	object to be initialized
	*/
	function init_object(&$obj)
	{
		$obj->form_id = 0;
		$obj->section_id = 0;
		$obj->title = "";
	}//end of init_object 
}//end of class forms_sections

//################################################################################################
/**
*	Database interaction class for forms_completed.
*
*	@package forms
*/
class forms_completed
{

	function forms_completed()
	{
	}
	/**#@+
	*
	*	@param object $db instance of the database class object
	*	@param boolean $mq status of magic quotes as it pertains to the values of $obj properties
	*/

	/**
	*	Select all fields for a given record
	*	@param	int	$id
	*	@return resource database result resource
	*/
/*	function &get($id,&$db)
	{
		$sql= "select id,form_id,user_id,completed_form ";
		$sql.= "from ".DB_TABLE_FORMS_COMPLETED." ";
		$sql.= "where id=$id";

		return($result = $db->perform_looping_query($sql));
	}//end of function get*/
	function get($user_id,$db,$id="")
	{
		$sql = "SELECT id,form_id,user_id,completed_form,datestamp";
		$sql.= " FROM ".DB_TABLE_FORMS_COMPLETED;
		$sql.= " WHERE user_id=".$db->qstr($user_id);
		if($id!="")
			$sql.= " AND id=".$db->qstr($id);
		$sql.= " ORDER BY datestamp";
		
		return ($db->perform_looping_query($sql));
	}

	/**
	*	Insert one record into the database
	*	@param	object	$obj object with the following properties: id,form_id,user_id,completed_form
	*	@return boolean database result or false
	*/
	function insert(&$obj,&$db,$mq=false)
	{
		//increment table used
		$next_id = $db->get_next_id(DB_TABLE_FORMS_COMPLETED);
		$obj->id = $next_id;


		if($obj->id > 0)
		{
			$sql= "insert into ".DB_TABLE_FORMS_COMPLETED." (";
			$sql.= "id,form_id,user_id,completed_form,datestamp) ";
			$sql.= "values (";
			$sql.= $db->qstr($obj->id).",";
			$sql.= $db->qstr($obj->form_id).",";
			$sql.= $db->qstr($obj->user_id).",";
			$sql.= $db->qstr($obj->completed_form,true).",";
			$sql.= "NOW())";

			return ($db->perform_action_query($sql));
		}//end of if a new key was returned
		else
		{
			return false;
		}
	}//end of function insert

	/**
	*	Update one record into the database
	*	@param	object	$obj object with the following properties: id,form_id,user_id,completed_form
	*	@return boolean database result or false
	*/
	function update(&$obj,&$db,$mq=false)
	{
		$sql= "update ".DB_TABLE_FORMS_COMPLETED." set ";
		$sql.= "id=".$obj->id.",";
		$sql.= "form_id=".$obj->form_id.",";
		$sql.= "user_id=".$obj->user_id.",";
		$sql.= "completed_form=".$db->qstr($obj->completed_form,$mq)." ";
		$sql.= "where id=".$obj->id."";

		return ($db->perform_action_query($sql));
	}//end of function update

	/**
	*	Delete one record into the database
	*	@param	object	$obj object with the following properties: id
	*	@return boolean database result or false
	*/
	function delete($obj,&$db)
	{
		$sql= "delete from ".DB_TABLE_FORMS_COMPLETED." ";
		$sql.= "where id=".$obj->id."";

		return ($db->perform_action_query($sql));
	}//end of function delete
/**#@-*/

	/**
	*	Initializes an object to default values
	*	@param	object 	object to be initialized
	*/
	function init_object(&$obj)
	{
		$obj->id = 0;
		$obj->form_id = 0;
		$obj->user_id = 0;
		$obj->completed_form = "";
	}//end of init_object 


/*
	function insert($obj,$db,$mq=false)
	{
		$sql= "insert into ".DB_TABLE_FORMS_COMPLETED." (";
		$sql.= "form_id,user_id,completed_form) ";
		$sql.= "values (";
		$sql.= $db->qstr($obj->form_id).",";
		$sql.= $db->qstr($obj->user_id).",";
		$sql.= $db->qstr($obj->completed_form,true).")";
		
		return ($db->perform_looping_query($sql));
	}
*/
}//end of class forms_completed

class questions_types
{
	function get($db)
	{
		$sql = "SELECT id,question_type";
		$sql.= " FROM ".DB_TABLE_FORMS_QUESTIONS_TYPES;
	
		return ($db->perform_looping_query($sql));
	}
}
?>
Return current item: Epiware Document Management