<?php
// Include the CRC Object class that needs to
// extended by all classes. This is the super
// class.
include_once('crc_constants.mod.php');
include_once('crc_object.cls.php');
include_once('crc_mysql.cls.php');
//******************************************
// Name: crc_object
//******************************************
//
// Desc: The primary CRC Object
// Developer: Shaffin Bhanji
// Email: hide@address.com
// Date: March 10th, 2003
// Version: 1.0.0
//
// Copyright
// =========
// This code is copyright, use in part or
// whole is prohibited without a written
// concent to the developer.
//******************************************
class crc_evaluation extends crc_object {
var $m_sql;
var $m_categories;
var $m_questions;
var $m_data;
function crc_evaluation($debug) {
//******************************************
// Initialization by constructor
//******************************************
$this->classname = 'crc_evaluation';
$this->classdescription = 'Handle user feedback and evaluation.';
$this->classversion = '1.0.0';
$this->classdate = 'March 10th, 2003';
$this->classdevelopername = 'Shaffin Bhanji';
$this->classdeveloperemail = 'hide@address.com';
$this->_DEBUG = $debug;
if ($this->_DEBUG) {
echo "DEBUG {crc_evaluation::constructor}: The class \"crc_evaluation\" was successfuly created. <br>";
echo "DEBUG {crc_evaluation::constructor}: Running in debug mode. <br>";
}
}
function fn_getcategory($category) {
//******************************************
// Get the questions for a specific category
//******************************************
$result = false;
if ($this->_DEBUG) {
echo "DEBUG {crc_evaluation::fn_getsection}: Retreiving questions for category: '" . $category . "'. <br>";
}
$db = new crc_mysql($this->_DEBUG);
$dbhandle = $db->fn_connect();
if ($dbhandle != 0) {
$this->m_sql = 'select * ' .
'from ' . MYSQL_FEEDBACK_QUESTIONS_TBL .
' where (feedback_questions_active = 0) and ' .
'(feedback_questions_category = "' . $category . '") ' .
'order by feedback_questions_sequence asc';
$resource = $db->fn_runsql(MYSQL_DB, $this->m_sql);
if (mysql_num_rows($resource) > 0) {
$result = $resource;
} else {
$result = null;
}
//$db->fn_freesql($resource);
return $result;
}
}
function fn_getquestions() {
//******************************************
// Get the questions to generate the evaluation form
//******************************************
$result = false;
if ($this->_DEBUG) {
echo "DEBUG {crc_evaluation::fn_getquestions}: Retreiving feedback questions<br>";
}
$db = new crc_mysql($this->_DEBUG);
$dbhandle = $db->fn_connect();
if ($dbhandle != 0) {
$this->m_sql = 'select distinct feedback_questions_category ' .
'from ' . MYSQL_FEEDBACK_QUESTIONS_TBL .
' where (feedback_questions_active = 0)';
//echo $this->m_sql;
$categories = $db->fn_runsql(MYSQL_DB, $this->m_sql);
if (mysql_num_rows($categories) > 0) {
if ($this->_DEBUG) {
echo "DEBUG {crc_evaluation::fn_getquestions}: Number of sections found are: " . mysql_num_rows($categories) . ". <br>";
}
$index = 0;
while ($category = mysql_fetch_array($categories)) {
$questions = $this->fn_getcategory($category[0]);
while ($row = mysql_fetch_array($questions)) {
$this->m_data[$index] = $row;
if ($this->_DEBUG) {
switch($this->m_data[$index][3]) {
case "OPTION":
$form = '<input type="radio" name="' . $this->m_data[$index][0] . '" value="1">';
$form = $form . '<input type="radio" name="' . $this->m_data[$index][0] . '" value="2">';
$form = $form . '<input type="radio" name="' . $this->m_data[$index][0] . '" value="3">';
$form = $form . '<input type="radio" name="' . $this->m_data[$index][0] . '" value="4">';
$form = $form . '<input type="radio" name="' . $this->m_data[$index][0] . '" value="5">';
$form = $form . '<input name="' . $this->m_data[$index][0] . 'text" size="40" width="80">';
break;
case "COMMENT":
$form = '<textarea name="' . $this->m_data[$index][0] . '" col="40" row="3" wrap="soft"></textarea>';
break;
}
echo 'DEBUG {crc_evaluation::fn_getquestions}: Question found: "' . $this->m_data[$index][1] . '" ' . $form . '<br>';
}
$index = $index + 1;
}
$db->fn_freesql($questions);
}
if ($this->_DEBUG) {
echo 'DEBUG {crc_evaluation::fn_getquestions}: Total questions are: ' . count($this->m_data) . '<br>';
}
$db->fn_freesql($categories);
//$this->m_data = mysql_fetch_array($resource);
} else {
$this->m_data = null;
$this->lasterrnum = ERR_FEEDBACK_QUESTIONS_NOSECTIONS_NUM;
$this->lasterrmsg = ERR_FEEDBACK_QUESTIONS_NOSECTIONS_DESC;
if ($this->_DEBUG) {
echo 'ERROR {crc_evaluation::fn_getquestions}: The sql command returned nothing. <br>';
echo 'ERROR {crc_evaluation::fn_getquestions}: Error number: ' . $this->m_lasterrnum . '. <br>';
echo 'ERROR {crc_evaluation::fn_getquestions}: Error description: ' . $this->m_lasterrmsg . '. <br>';
}
}
$db->fn_disconnect();
return $this->m_data;
} else {
$db->fn_freesql($resource);
$db->fn_disconnect();
return null;
}
}
function fn_setquestions($profileid, $questions, $post) {
//******************************************
// Update the users evaluation information
//******************************************
$result = false;
if ($this->_DEBUG) {
echo "DEBUG {crc_evaluation::fn_setquestions}: Updating the user evaluation information.<br>";
}
$db = new crc_mysql($this->_DEBUG);
$dbhandle = $db->fn_connect();
if ($dbhandle != 0) {
$this->m_sql = 'insert into ' . MYSQL_FEEDBACK_TBL .
' (feedback_profile_id, feedback_session_id) ' .
' values (' . $profileid . ', ' . $post['schedule_id'] . ')';
//echo 'Running SQL: ' . $this->m_sql . '<br><br>';
//die();
$db->fn_runsql(MYSQL_DB, $this->m_sql);
if (mysql_affected_rows() > 0) {
$this->m_sql = 'update ' . MYSQL_STUDENT_SCHEDULE_TBL .
' SET student_schedule_questions = 0 ' .
'where (student_schedule_id = ' . $post['schedule_id'] . ')';
//echo 'Running SQL: ' . $this->m_sql . '<br><br>';
$db->fn_runsql(MYSQL_DB, $this->m_sql);
$this->m_sql = 'select * from ' . MYSQL_FEEDBACK_TBL .
' where (feedback_profile_id = ' . $profileid . ') and ' .
'(feedback_session_id = ' . $post['schedule_id'] . ')';
//echo 'Running SQL: ' . $this->m_sql . '<br><br>';
$feedback = mysql_fetch_array($db->fn_runsql(MYSQL_DB, $this->m_sql));
for ($i = 1; $i <= count($_SESSION['evaluation']); $i++) {
//print_r(array_keys ($post));
$question = $_SESSION['evaluation'][$i - 1];
$answers = $post;
$answeri = $question[0] . 'name';
$answer = $post[$answeri];
if (!isset($answer) or ($answer == "")) {
$answer = 0;
}
if ($question[3] == "OPTION") {
$commenti = $question[0] . 'comment';
$comment = $post[$commenti];
$this->m_sql = 'insert into ' . MYSQL_FEEDBACK_ANSWERS_TBL .
' (feedback_answers_feedback_id, feedback_answers_questions_id, ' .
' feedback_answers_answer, feedback_answers_comments) ' .
' values (' . $feedback[0] . ', ' . $question[0] . ', ' . $answer . ', "' . $comment . '")';
} else {
$this->m_sql = 'insert into ' . MYSQL_FEEDBACK_ANSWERS_TBL .
' (feedback_answers_feedback_id, feedback_answers_questions_id, ' .
' feedback_answers_answer) ' .
' values (' . $feedback[0] . ', ' . $question[0] . ', "' . $answer . '")';
}
//echo 'Running SQL: ' . $this->m_sql . '<br><br>';
$db->fn_runsql(MYSQL_DB, $this->m_sql);
}
$result = true;
} else {
$this->lasterrnum = ERR_FEEDBACK_ADD_NUM;
$this->lasterrmsg = ERR_FEEDBACK_ADD_DESC;
if ($this->_DEBUG) {
echo 'ERROR {crc_evaluation::fn_setquestions}: Could not add feedback information. <br>';
echo 'ERROR {crc_evaluation::fn_setquestions}: Error number: ' . $this->m_lasterrnum . '. <br>';
echo 'ERROR {crc_evaluation::fn_setquestions}: Error description: ' . $this->m_lasterrmsg . '. <br>';
}
$result = false;
}
//$db->fn_freesql($resource);
$db->fn_disconnect();
} else {
$db->fn_disconnect();
}
return $result;
}
}
?>
<?php
/*
//This will test the get_profile function.
//$test = new crc_evaluation(True);
//$data = $test->fn_getquestions();
*/
?>
<?php
/*
//This will test the set_profile function.
$profile = new crc_profile(True);
$data['profileid'] = '6';
$data['email'] = 'altaf';
$data['password'] = 'altaf';
$data['fname'] = 'altaf';
$data['lname'] = 'bhanji';
$data['year'] = '1969';
$data['month'] = '03';
$data['day'] = '24';
$data['gender'] = 'Male';
$data['add1'] = '28 Elson Street';
$data['add2'] = '';
$data['city'] = 'Markham';
$data['province'] = 'ON';
$data['pc'] = 'L3S2J5';
$data['country'] = 'Canada';
$data['lcode'] = '416';
$data['lprefix'] = '524';
$data['lpostfix'] = '9520';
$profile->fn_setprofile($data);
*/
?>