Current File : /home/inlingua/public_html/sensoriumpsychologists.com/diagnostics/franchise_between/admin.php |
<?php
class admin extends database
{
private $validate_obj;
private $ip,$browser,$my_table_id;
function __construct()
{
$this->ip=htmlspecialchars($_SERVER['REMOTE_ADDR']);
$this->browser=htmlspecialchars($_SERVER['HTTP_USER_AGENT']);
$this->my_table_id=$GLOBALS['my_table_id'];
$this->validate_obj=new validate;
set_error_handler(array($this, 'myErrorHandler'));
}
// A user-defined error handler function
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
echo "<b>Error:</b> [$errno] $errstr<br>";
echo " Error on line $errline in $errfile<br>";
echo("Error : Unidentified error...Please contact your administrator...!!!");
exit();
}
function all_treatment_codes($page_no,&$pages_return)
{
try
{
if($this->validate_obj->is_set($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($page_no))
{
if($this->validate_obj->is_num($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
}
$statement="SELECT SQL_CALC_FOUND_ROWS DISTINCT(a.code) FROM shristi_treatments a WHERE a.for_std!='' AND a.for_month!='' AND a.for_week!='' AND a.for_day!='' ORDER BY a.code ";
$start=PER_PAGE_TREATMENT_CODES*$page_no;
$statement.=" LIMIT $start,50";
$this->open_connection();
$sql = $this->simply_run_statement_passed($statement);
$res_rows=$this->simply_run_statement_passed("SELECT FOUND_ROWS() as total_rows");
$this->close_connection();
$detail_rows=$res_rows->fetch_assoc();
$rows_found=$detail_rows['total_rows'];
$left=$rows_found%PER_PAGE_TREATMENT_CODES;
$pages_return=(int)($rows_found/PER_PAGE_TREATMENT_CODES);
if($left>0)$pages_return++;
return $sql;
}
catch(Exception $e)
{
echo($e->getMessage());
exit();
}
}
function all_treatment_stds($code,$page_no,&$pages_return)
{
try
{
$code=trim($code);
$code=htmlspecialchars($code);
if($this->validate_obj->is_set($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_char($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_set($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($page_no))
{
if($this->validate_obj->is_num($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
}
$this->open_connection();
$code=$this->real_escape($code);
$statement="SELECT SQL_CALC_FOUND_ROWS DISTINCT(a.for_std) FROM shristi_treatments a WHERE a.code='$code' AND a.for_std!='' AND a.for_month!='' AND a.for_week!='' AND a.for_day!='' ORDER BY a.for_std ";
$start=PER_PAGE_TREATMENT_CODES*$page_no;
$statement.=" LIMIT $start,50";
$sql = $this->simply_run_statement_passed($statement);
$res_rows=$this->simply_run_statement_passed("SELECT FOUND_ROWS() as total_rows");
$this->close_connection();
$detail_rows=$res_rows->fetch_assoc();
$rows_found=$detail_rows['total_rows'];
$left=$rows_found%PER_PAGE_TREATMENT_CODES;
$pages_return=(int)($rows_found/PER_PAGE_TREATMENT_CODES);
if($left>0)$pages_return++;
return $sql;
}
catch(Exception $e)
{
echo($e->getMessage());
exit();
}
}
function all_treatment_months($code,$std,$page_no,&$pages_return)
{
try
{
$code=trim($code);
$code=htmlspecialchars($code);
$std=trim($std);
if($this->validate_obj->is_set($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_char($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_set($std)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($std)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_num($std)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_set($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($page_no))
{
if($this->validate_obj->is_num($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
}
$this->open_connection();
$code=$this->real_escape($code);
$statement="SELECT SQL_CALC_FOUND_ROWS DISTINCT(a.for_month) FROM shristi_treatments a WHERE a.code='$code' AND a.for_std='$std' AND a.for_month!='' AND a.for_week!='' AND a.for_day!='' ORDER BY a.for_month ";
$start=PER_PAGE_TREATMENT_CODES*$page_no;
$statement.=" LIMIT $start,50";
$sql = $this->simply_run_statement_passed($statement);
$res_rows=$this->simply_run_statement_passed("SELECT FOUND_ROWS() as total_rows");
$this->close_connection();
$detail_rows=$res_rows->fetch_assoc();
$rows_found=$detail_rows['total_rows'];
$left=$rows_found%PER_PAGE_TREATMENT_CODES;
$pages_return=(int)($rows_found/PER_PAGE_TREATMENT_CODES);
if($left>0)$pages_return++;
return $sql;
}
catch(Exception $e)
{
echo($e->getMessage());
exit();
}
}
function all_treatment_week_day($code,$std,$month,$page_no,&$pages_return)
{
try
{
$code=trim($code);
$code=htmlspecialchars($code);
$std=trim($std);
$month=trim($month);
if($this->validate_obj->is_set($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_char($code)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_set($std)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($std)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_num($std)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_set($month)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($month)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_num($month)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_set($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($page_no))
{
if($this->validate_obj->is_num($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
}
$this->open_connection();
$code=$this->real_escape($code);
$statement="SELECT SQL_CALC_FOUND_ROWS a.table_id,a.for_week,a.for_day FROM shristi_treatments a WHERE a.code='$code' AND a.for_std='$std' AND a.for_month='$month' AND a.for_week!='' AND a.for_day!='' ORDER BY a.for_week,a.for_day ";
$start=PER_PAGE_TREATMENT_CODES*$page_no;
$statement.=" LIMIT $start,50";
$sql = $this->simply_run_statement_passed($statement);
$res_rows=$this->simply_run_statement_passed("SELECT FOUND_ROWS() as total_rows");
$this->close_connection();
$detail_rows=$res_rows->fetch_assoc();
$rows_found=$detail_rows['total_rows'];
$left=$rows_found%PER_PAGE_TREATMENT_CODES;
$pages_return=(int)($rows_found/PER_PAGE_TREATMENT_CODES);
if($left>0)$pages_return++;
return $sql;
}
catch(Exception $e)
{
echo($e->getMessage());
exit();
}
}
function add_treatment_type_1($code,$std,$month,$week,$day,$paragraph_1,$one_word_title_1,$blanks_title_1,$true_false_title_1,$question_1_1,$question_1_2,$question_1_3)
{
try
{
$paragraph_1=trim($paragraph_1);
$one_word_title_1=trim($one_word_title_1);
$question_1_1=array_filter($question_1_1);
$question_1_2=array_filter($question_1_2);
$question_1_3=array_filter($question_1_3);
$question_1_1=array_values($question_1_1);
$question_1_2=array_values($question_1_2);
$question_1_3=array_values($question_1_3);
if($this->validate_obj->is_set($code)){throw new Exception(ERROR_INVALID_REQUEST."1");}
if($this->validate_obj->is_empty($code)){throw new Exception(ERROR_INVALID_REQUEST."2");}
if($this->validate_obj->is_char($code)){throw new Exception(ERROR_INVALID_REQUEST."3");}
if($this->validate_obj->is_set($std)){throw new Exception(ERROR_INVALID_REQUEST."4");}
if($this->validate_obj->is_empty($std)){throw new Exception(ERROR_INVALID_REQUEST."5");}
if($this->validate_obj->is_num($std)){throw new Exception(ERROR_INVALID_REQUEST."6");}
if($this->validate_obj->is_set($month)){throw new Exception(ERROR_INVALID_REQUEST."7");}
if($this->validate_obj->is_empty($month)){throw new Exception(ERROR_INVALID_REQUEST."8");}
if($this->validate_obj->is_num($month)){throw new Exception(ERROR_INVALID_REQUEST."9");}
if($this->validate_obj->is_set($week)){throw new Exception(ERROR_INVALID_REQUEST."10");}
if($this->validate_obj->is_empty($week)){throw new Exception("Error : Please select week...");}
if($this->validate_obj->is_num($week)){throw new Exception(ERROR_INVALID_REQUEST."11");}
if($this->validate_obj->is_set($day)){throw new Exception(ERROR_INVALID_REQUEST."12");}
if($this->validate_obj->is_empty($day)){throw new Exception("Error : Please select day...");}
if($this->validate_obj->is_num($day)){throw new Exception(ERROR_INVALID_REQUEST."13");}
if($this->validate_obj->is_set($paragraph_1)){throw new Exception(ERROR_INVALID_REQUEST."13");}
if($this->validate_obj->is_empty($paragraph_1)){throw new Exception("Error : Please enter paragraph...");}
if($this->validate_obj->is_set($one_word_title_1)){throw new Exception(ERROR_INVALID_REQUEST."14");}
if($this->validate_obj->is_set($blanks_title_1)){throw new Exception(ERROR_INVALID_REQUEST."14");}
if($this->validate_obj->is_set($true_false_title_1)){throw new Exception(ERROR_INVALID_REQUEST."14");}
$this->open_connection();
$this->START_TRANSACTION();
$paragraph_1=$this->real_escape($paragraph_1);
$one_word_title_1=$this->real_escape($one_word_title_1);
$blanks_title_1=$this->real_escape($blanks_title_1);
$true_false_title_1=$this->real_escape($true_false_title_1);
for($i=0;$i<count($question_1_1);$i++)
{
$question_1_1[$i]=trim($question_1_1[$i]);
$question_1_1[$i]=$this->real_escape($question_1_1[$i]);
}
for($i=0;$i<count($question_1_2);$i++)
{
$question_1_2[$i]=trim($question_1_2[$i]);
$question_1_2[$i]=$this->real_escape($question_1_2[$i]);
}
for($i=0;$i<count($question_1_3);$i++)
{
$question_1_3[$i]=trim($question_1_3[$i]);
$question_1_3[$i]=$this->real_escape($question_1_3[$i]);
}
$statement="INSERT INTO shristi_treatments(for_std,for_month,code,for_week,for_day,created_by,created_browser,created_ip) VALUES('$std','$month','$code','$week','$day','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 1...!!!");
}
$generated_id=$this->insert_id();
$statement="INSERT INTO shristi_treatments_main_questions(treatment_code,question_paragraph,created_by,created_browser,created_ip) VALUES('$generated_id','$paragraph_1','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 8...!!!");
}
$generated_id_2=$this->insert_id();
if(count($question_1_1)>0)
{
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','$one_word_title_1','questions_category','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
for($i=0;$i<count($question_1_1);$i++)
{
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','$question_1_1[$i]','9','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 2..loop ".$i."...!!!");
}
}
}
if(count($question_1_2)>0)
{
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','$blanks_title_1','questions_category','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
for($i=0;$i<count($question_1_2);$i++)
{
$no_of_blanks=substr_count($question_1_2[$i],"blank_here");
if($no_of_blanks==0)
{
throw new Exception("Error : blank_here must be present in all fill in the blanks questions...loop:".$i);
}
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,no_of_blanks,type,created_by,created_ip) VALUES('$generated_id_2','$question_1_2[$i]','$no_of_blanks','10','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 2..loop ".$i."...!!!");
}
}
}
if(count($question_1_3)>0)
{
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','$true_false_title_1','questions_category','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
for($i=0;$i<count($question_1_3);$i++)
{
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,options,type,created_by,created_ip) VALUES('$generated_id_2','$question_1_3[$i]','True!@!@False','3','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 4..loop ".$i."...!!!");
}
}
}
$this->commit();
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function add_treatment_type_2($code,$std,$month,$week,$day,$question_heading,$sound,$words,$sentences,$blanks,$true_false)
{
try
{
$sound=trim($sound);
$words=trim($words);
$question_heading=trim($question_heading);
$sentences=array_filter($sentences);
$blanks=array_filter($blanks);
$true_false=array_filter($true_false);
$sentences=array_values($sentences);
$blanks=array_values($blanks);
$true_false=array_values($true_false);
if($this->validate_obj->is_set($code)){throw new Exception(ERROR_INVALID_REQUEST."1");}
if($this->validate_obj->is_empty($code)){throw new Exception(ERROR_INVALID_REQUEST."2");}
if($this->validate_obj->is_char($code)){throw new Exception(ERROR_INVALID_REQUEST."3");}
if($this->validate_obj->is_set($std)){throw new Exception(ERROR_INVALID_REQUEST."4");}
if($this->validate_obj->is_empty($std)){throw new Exception(ERROR_INVALID_REQUEST."5");}
if($this->validate_obj->is_num($std)){throw new Exception(ERROR_INVALID_REQUEST."6");}
if($this->validate_obj->is_set($month)){throw new Exception(ERROR_INVALID_REQUEST."7");}
if($this->validate_obj->is_empty($month)){throw new Exception(ERROR_INVALID_REQUEST."8");}
if($this->validate_obj->is_num($month)){throw new Exception(ERROR_INVALID_REQUEST."9");}
if($this->validate_obj->is_set($week)){throw new Exception(ERROR_INVALID_REQUEST."10");}
if($this->validate_obj->is_empty($week)){throw new Exception("Error : Please select week...");}
if($this->validate_obj->is_num($week)){throw new Exception(ERROR_INVALID_REQUEST."11");}
if($this->validate_obj->is_set($day)){throw new Exception(ERROR_INVALID_REQUEST."12");}
if($this->validate_obj->is_empty($day)){throw new Exception("Error : Please select day...");}
if($this->validate_obj->is_num($day)){throw new Exception(ERROR_INVALID_REQUEST."13");}
if($this->validate_obj->is_empty($question_heading)){throw new Exception("Error : Please enter Question's Main Title");}
$this->open_connection();
$this->START_TRANSACTION();
$sound=$this->real_escape($sound);
$words=$this->real_escape($words);
$question_heading=$this->real_escape($question_heading);
for($i=0;$i<count($sentences);$i++)
{
$sentences[$i]=trim($sentences[$i]);
$sentences[$i]=$this->real_escape($sentences[$i]);
}
for($i=0;$i<count($blanks);$i++)
{
$blanks[$i]=trim($blanks[$i]);
$blanks[$i]=$this->real_escape($blanks[$i]);
}
for($i=0;$i<count($true_false);$i++)
{
$true_false[$i]=trim($true_false[$i]);
$true_false[$i]=$this->real_escape($true_false[$i]);
}
$statement="INSERT INTO shristi_treatments(for_std,for_month,code,for_week,for_day,created_by,created_browser,created_ip) VALUES('$std','$month','$code','$week','$day','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 1...!!!");
}
$generated_id=$this->insert_id();
$statement="INSERT INTO shristi_treatments_main_questions(treatment_code,question_paragraph,created_by,created_browser,created_ip) VALUES('$generated_id','$question_heading','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 4...!!!");
}
$generated_id_2=$this->insert_id();
if($sound!="")
{
$sound=$this->real_escape($sound);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','$sound','20','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 5...!!!");
}
}
if($words!="")
{
$words_array=explode(",",$words);
$temp_str="<span class=\"ad_page_2_span\">Read</span><br /><br /><div class=\"ad_page_2_options\">";
$words_final=implode("<br />",$words_array);
$temp_str.=$words_final;
$temp_str.="</div>";
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','21','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($sentences)>0)
{
$temp_str="<span class=\"ad_page_2_span\">Read & Copy</span><br /><br /><div class=\"ad_page_2_options\">";
$sentences_final=implode("<br />",$sentences);
$temp_str.=$sentences_final;
$temp_str.="</div>";
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','21','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 9...!!!");
}
}
if(count($blanks)>0)
{
$temp_str="<span class=\"ad_page_2_span\">Exercise</span><br /><br /><div class=\"ad_page_2_options\">";
$blanks_final=implode("<br />",$blanks);
$temp_str.=$blanks_final;
$temp_str.="</div>";
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','21','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 10...!!!");
}
}
if(count($true_false)>0)
{
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,type,created_by,created_ip) VALUES('$generated_id_2','Select True or False','questions_category','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 11...!!!");
}
for($i=0;$i<count($true_false);$i++)
{
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,question,options,type,created_by,created_ip) VALUES('$generated_id_2','$true_false[$i]','True!@!@False','3','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 12..loop ".$i."...!!!");
}
}
}
for($i=0;$i<count($_FILES['upload_files']['name']);$i++)
{
if($_FILES["upload_files"]["error"][$i]!=UPLOAD_ERR_NO_FILE)
{
// file upload
$allowedExts = array("png", "jpg", "jpeg", "jpe","doc","docx","xls","xlsx","pdf","ppt", "PNG", "JPG", "JPEG", "JPE","DOC","DOCX","XLS","XLSX","PDF","PPT");
$month_year=date("m_Y");
$upload_directory="../franchise/images/".$month_year;
if (!is_dir($upload_directory))
{
mkdir($upload_directory, 0777, true);
}
$upload_directory_to_write="images/".$month_year;
if($_FILES["upload_files"]["error"][$i]>1)
{
throw new Exception("Error : Error in file...".$_FILES["upload_files"]["error"][$i]);
}
if($_FILES["upload_files"]["size"][$i]>MAX_IMAGE_SIZE)
{
throw new Exception("Error : File size must not exceed ".MAX_IMAGE_SIZE_ERROR."...");
}
$temp = explode(".", $_FILES["upload_files"]["name"][$i]);
$extension = end($temp);
if(!in_array($extension, $allowedExts))
{
throw new Exception("Error : This type of file is not allowed...");
}
$target_filename=$_FILES["upload_files"]["tmp_name"][$i];
$unique="no";
while($unique=="no")
{
$new_file_name=time().str_shuffle("ABCDEFGHIJKLMNOPQRSTUPWXYZ").rand(1000,9999).".".$extension;
if(!file_exists($upload_directory."/".$new_file_name))
{
$unique="yes";
}
}
if(!move_uploaded_file($_FILES["upload_files"]["tmp_name"][$i], $upload_directory."/".$new_file_name))
{
throw new Exception("Error : Couldn't save file on server...");
}
$to_write="<h3><a href=\"".$upload_directory."/".$new_file_name."\" target=\"_blank\">Link</a></h3>";
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$to_write','25','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 333...!!!");
}
}
}
$this->commit();
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function add_treatment_type_3($code,$std,$month,$week,$day,$title,$question_1,$question_2,$question_3,$question_4,$question_5,$question_6,$question_7,$question_8,$question_9,$question_10,$question_11,$question_12,$question_13,$question_14,$question_15)
{
try
{
$title=trim($title);
$question_1=array_filter($question_1);
$question_2=array_filter($question_2);
$question_3=array_filter($question_3);
$question_4=array_filter($question_4);
$question_5=array_filter($question_5);
$question_6=array_filter($question_6);
$question_7=array_filter($question_7);
$question_8=array_filter($question_8);
$question_9=array_filter($question_9);
$question_10=array_filter($question_10);
$question_11=array_filter($question_11);
$question_12=array_filter($question_12);
$question_13=array_filter($question_13);
$question_14=array_filter($question_14);
$question_15=array_filter($question_15);
$question_1=array_values($question_1);
$question_2=array_values($question_2);
$question_3=array_values($question_3);
$question_4=array_values($question_4);
$question_5=array_values($question_5);
$question_6=array_values($question_6);
$question_7=array_values($question_7);
$question_8=array_values($question_8);
$question_9=array_values($question_9);
$question_10=array_values($question_10);
$question_11=array_values($question_11);
$question_12=array_values($question_12);
$question_13=array_values($question_13);
$question_14=array_values($question_14);
$question_15=array_values($question_15);
if($this->validate_obj->is_set($code)){throw new Exception(ERROR_INVALID_REQUEST."1");}
if($this->validate_obj->is_empty($code)){throw new Exception(ERROR_INVALID_REQUEST."2");}
if($this->validate_obj->is_char($code)){throw new Exception(ERROR_INVALID_REQUEST."3");}
if($this->validate_obj->is_set($std)){throw new Exception(ERROR_INVALID_REQUEST."4");}
if($this->validate_obj->is_empty($std)){throw new Exception(ERROR_INVALID_REQUEST."5");}
if($this->validate_obj->is_num($std)){throw new Exception(ERROR_INVALID_REQUEST."6");}
if($this->validate_obj->is_set($month)){throw new Exception(ERROR_INVALID_REQUEST."7");}
if($this->validate_obj->is_empty($month)){throw new Exception(ERROR_INVALID_REQUEST."8");}
if($this->validate_obj->is_num($month)){throw new Exception(ERROR_INVALID_REQUEST."9");}
if($this->validate_obj->is_set($week)){throw new Exception(ERROR_INVALID_REQUEST."10");}
if($this->validate_obj->is_empty($week)){throw new Exception("Error : Please select week...");}
if($this->validate_obj->is_num($week)){throw new Exception(ERROR_INVALID_REQUEST."11");}
if($this->validate_obj->is_set($day)){throw new Exception(ERROR_INVALID_REQUEST."12");}
if($this->validate_obj->is_empty($day)){throw new Exception("Error : Please select day...");}
if($this->validate_obj->is_num($day)){throw new Exception(ERROR_INVALID_REQUEST."13");}
$this->open_connection();
$this->START_TRANSACTION();
$title=$this->real_escape($title);
for($i=0;$i<count($question_1);$i++)
{
$question_1[$i]=trim($question_1[$i]);
$question_1[$i]=$this->real_escape($question_1[$i]);
}
for($i=0;$i<count($question_2);$i++)
{
$question_2[$i]=trim($question_2[$i]);
$question_2[$i]=$this->real_escape($question_2[$i]);
}
for($i=0;$i<count($question_3);$i++)
{
$question_3[$i]=trim($question_3[$i]);
$question_3[$i]=$this->real_escape($question_3[$i]);
}
for($i=0;$i<count($question_4);$i++)
{
$question_4[$i]=trim($question_4[$i]);
$question_4[$i]=$this->real_escape($question_4[$i]);
}
for($i=0;$i<count($question_5);$i++)
{
$question_5[$i]=trim($question_5[$i]);
$question_5[$i]=$this->real_escape($question_5[$i]);
}
for($i=0;$i<count($question_6);$i++)
{
$question_6[$i]=trim($question_6[$i]);
$question_6[$i]=$this->real_escape($question_6[$i]);
}
for($i=0;$i<count($question_7);$i++)
{
$question_7[$i]=trim($question_7[$i]);
$question_7[$i]=$this->real_escape($question_7[$i]);
}
for($i=0;$i<count($question_8);$i++)
{
$question_8[$i]=trim($question_8[$i]);
$question_8[$i]=$this->real_escape($question_8[$i]);
}
for($i=0;$i<count($question_9);$i++)
{
$question_9[$i]=trim($question_9[$i]);
$question_9[$i]=$this->real_escape($question_9[$i]);
}
for($i=0;$i<count($question_10);$i++)
{
$question_10[$i]=trim($question_10[$i]);
$question_10[$i]=$this->real_escape($question_10[$i]);
}
for($i=0;$i<count($question_11);$i++)
{
$question_11[$i]=trim($question_11[$i]);
$question_11[$i]=$this->real_escape($question_11[$i]);
}
for($i=0;$i<count($question_12);$i++)
{
$question_12[$i]=trim($question_12[$i]);
$question_12[$i]=$this->real_escape($question_12[$i]);
}
for($i=0;$i<count($question_13);$i++)
{
$question_13[$i]=trim($question_13[$i]);
$question_13[$i]=$this->real_escape($question_13[$i]);
}
for($i=0;$i<count($question_14);$i++)
{
$question_14[$i]=trim($question_14[$i]);
$question_14[$i]=$this->real_escape($question_14[$i]);
}
for($i=0;$i<count($question_15);$i++)
{
$question_15[$i]=trim($question_15[$i]);
$question_15[$i]=$this->real_escape($question_15[$i]);
}
$statement="INSERT INTO shristi_treatments(for_std,for_month,code,for_week,for_day,created_by,created_browser,created_ip) VALUES('$std','$month','$code','$week','$day','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 1...!!!");
}
$generated_id=$this->insert_id();
$title="<P>".$title."</P>";
$title=$this->real_escape($title);
$statement="INSERT INTO shristi_treatments_main_questions(treatment_code,question_paragraph,created_by,created_browser,created_ip) VALUES('$generated_id','$title','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 6...!!!");
}
$generated_id_2=$this->insert_id();
if(count($question_1)>0)
{
$temp_str=implode("!@!@",$question_1);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_2)>0)
{
$temp_str=implode("!@!@",$question_2);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_3)>0)
{
$temp_str=implode("!@!@",$question_3);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_4)>0)
{
$temp_str=implode("!@!@",$question_4);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_5)>0)
{
$temp_str=implode("!@!@",$question_5);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_6)>0)
{
$temp_str=implode("!@!@",$question_6);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_7)>0)
{
$temp_str=implode("!@!@",$question_7);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_8)>0)
{
$temp_str=implode("!@!@",$question_8);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_9)>0)
{
$temp_str=implode("!@!@",$question_9);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_10)>0)
{
$temp_str=implode("!@!@",$question_10);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_11)>0)
{
$temp_str=implode("!@!@",$question_11);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_12)>0)
{
$temp_str=implode("!@!@",$question_12);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_13)>0)
{
$temp_str=implode("!@!@",$question_13);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_14)>0)
{
$temp_str=implode("!@!@",$question_14);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_15)>0)
{
$temp_str=implode("!@!@",$question_15);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','8','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
$this->commit();
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function add_treatment_type_4($code,$std,$month,$week,$day,$title,$answer_1,$answer_2,$answer_3,$answer_4,$answer_5,$answer_6,$answer_7,$answer_8,$answer_9,$answer_10,$answer_11,$answer_12,$answer_13,$answer_14,$answer_15,$question_1,$question_2,$question_3,$question_4,$question_5,$question_6,$question_7,$question_8,$question_9,$question_10,$question_11,$question_12,$question_13,$question_14,$question_15)
{
try
{
$title=trim($title);
$answer_1=trim($answer_1);
$answer_2=trim($answer_2);
$answer_3=trim($answer_3);
$answer_4=trim($answer_4);
$answer_5=trim($answer_5);
$answer_6=trim($answer_6);
$answer_7=trim($answer_7);
$answer_8=trim($answer_8);
$answer_9=trim($answer_9);
$answer_10=trim($answer_10);
$answer_11=trim($answer_11);
$answer_12=trim($answer_12);
$answer_13=trim($answer_13);
$answer_14=trim($answer_14);
$answer_15=trim($answer_15);
$question_1=array_filter($question_1);
$question_2=array_filter($question_2);
$question_3=array_filter($question_3);
$question_4=array_filter($question_4);
$question_5=array_filter($question_5);
$question_6=array_filter($question_6);
$question_7=array_filter($question_7);
$question_8=array_filter($question_8);
$question_9=array_filter($question_9);
$question_10=array_filter($question_10);
$question_11=array_filter($question_11);
$question_12=array_filter($question_12);
$question_13=array_filter($question_13);
$question_14=array_filter($question_14);
$question_15=array_filter($question_15);
$question_1=array_values($question_1);
$question_2=array_values($question_2);
$question_3=array_values($question_3);
$question_4=array_values($question_4);
$question_5=array_values($question_5);
$question_6=array_values($question_6);
$question_7=array_values($question_7);
$question_8=array_values($question_8);
$question_9=array_values($question_9);
$question_10=array_values($question_10);
$question_11=array_values($question_11);
$question_12=array_values($question_12);
$question_13=array_values($question_13);
$question_14=array_values($question_14);
$question_15=array_values($question_15);
if($this->validate_obj->is_set($code)){throw new Exception(ERROR_INVALID_REQUEST."1");}
if($this->validate_obj->is_empty($code)){throw new Exception(ERROR_INVALID_REQUEST."2");}
if($this->validate_obj->is_char($code)){throw new Exception(ERROR_INVALID_REQUEST."3");}
if($this->validate_obj->is_set($std)){throw new Exception(ERROR_INVALID_REQUEST."4");}
if($this->validate_obj->is_empty($std)){throw new Exception(ERROR_INVALID_REQUEST."5");}
if($this->validate_obj->is_num($std)){throw new Exception(ERROR_INVALID_REQUEST."6");}
if($this->validate_obj->is_set($month)){throw new Exception(ERROR_INVALID_REQUEST."7");}
if($this->validate_obj->is_empty($month)){throw new Exception(ERROR_INVALID_REQUEST."8");}
if($this->validate_obj->is_num($month)){throw new Exception(ERROR_INVALID_REQUEST."9");}
if($this->validate_obj->is_set($week)){throw new Exception(ERROR_INVALID_REQUEST."10");}
if($this->validate_obj->is_empty($week)){throw new Exception("Error : Please select week...");}
if($this->validate_obj->is_num($week)){throw new Exception(ERROR_INVALID_REQUEST."11");}
if($this->validate_obj->is_set($day)){throw new Exception(ERROR_INVALID_REQUEST."12");}
if($this->validate_obj->is_empty($day)){throw new Exception("Error : Please select day...");}
if($this->validate_obj->is_num($day)){throw new Exception(ERROR_INVALID_REQUEST."13");}
$this->open_connection();
$this->START_TRANSACTION();
$title=$this->real_escape($title);
for($i=0;$i<count($question_1);$i++)
{
$question_1[$i]=trim($question_1[$i]);
$question_1[$i]=$this->real_escape($question_1[$i]);
}
for($i=0;$i<count($question_2);$i++)
{
$question_2[$i]=trim($question_2[$i]);
$question_2[$i]=$this->real_escape($question_2[$i]);
}
for($i=0;$i<count($question_3);$i++)
{
$question_3[$i]=trim($question_3[$i]);
$question_3[$i]=$this->real_escape($question_3[$i]);
}
for($i=0;$i<count($question_4);$i++)
{
$question_4[$i]=trim($question_4[$i]);
$question_4[$i]=$this->real_escape($question_4[$i]);
}
for($i=0;$i<count($question_5);$i++)
{
$question_5[$i]=trim($question_5[$i]);
$question_5[$i]=$this->real_escape($question_5[$i]);
}
for($i=0;$i<count($question_6);$i++)
{
$question_6[$i]=trim($question_6[$i]);
$question_6[$i]=$this->real_escape($question_6[$i]);
}
for($i=0;$i<count($question_7);$i++)
{
$question_7[$i]=trim($question_7[$i]);
$question_7[$i]=$this->real_escape($question_7[$i]);
}
for($i=0;$i<count($question_8);$i++)
{
$question_8[$i]=trim($question_8[$i]);
$question_8[$i]=$this->real_escape($question_8[$i]);
}
for($i=0;$i<count($question_9);$i++)
{
$question_9[$i]=trim($question_9[$i]);
$question_9[$i]=$this->real_escape($question_9[$i]);
}
for($i=0;$i<count($question_10);$i++)
{
$question_10[$i]=trim($question_10[$i]);
$question_10[$i]=$this->real_escape($question_10[$i]);
}
for($i=0;$i<count($question_11);$i++)
{
$question_11[$i]=trim($question_11[$i]);
$question_11[$i]=$this->real_escape($question_11[$i]);
}
for($i=0;$i<count($question_12);$i++)
{
$question_12[$i]=trim($question_12[$i]);
$question_12[$i]=$this->real_escape($question_12[$i]);
}
for($i=0;$i<count($question_13);$i++)
{
$question_13[$i]=trim($question_13[$i]);
$question_13[$i]=$this->real_escape($question_13[$i]);
}
for($i=0;$i<count($question_14);$i++)
{
$question_14[$i]=trim($question_14[$i]);
$question_14[$i]=$this->real_escape($question_14[$i]);
}
for($i=0;$i<count($question_15);$i++)
{
$question_15[$i]=trim($question_15[$i]);
$question_15[$i]=$this->real_escape($question_15[$i]);
}
$statement="INSERT INTO shristi_treatments(for_std,for_month,code,for_week,for_day,created_by,created_browser,created_ip) VALUES('$std','$month','$code','$week','$day','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 1...!!!");
}
$generated_id=$this->insert_id();
$title="<P>".$title."</P>";
$title=$this->real_escape($title);
$statement="INSERT INTO shristi_treatments_main_questions(treatment_code,question_paragraph,created_by,created_browser,created_ip) VALUES('$generated_id','$title','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 7...!!!");
}
$generated_id_2=$this->insert_id();
if(count($question_1)>0)
{
$temp_answer=$this->real_escape($answer_1);
$temp_str=implode("!@!@",$question_1);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_2)>0)
{
$temp_answer=$this->real_escape($answer_2);
$temp_str=implode("!@!@",$question_2);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_3)>0)
{
$temp_answer=$this->real_escape($answer_3);
$temp_str=implode("!@!@",$question_3);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_4)>0)
{
$temp_answer=$this->real_escape($answer_4);
$temp_str=implode("!@!@",$question_4);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_5)>0)
{
$temp_answer=$this->real_escape($answer_5);
$temp_str=implode("!@!@",$question_5);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_6)>0)
{
$temp_answer=$this->real_escape($answer_6);
$temp_str=implode("!@!@",$question_6);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_7)>0)
{
$temp_answer=$this->real_escape($answer_7);
$temp_str=implode("!@!@",$question_7);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_8)>0)
{
$temp_answer=$this->real_escape($answer_8);
$temp_str=implode("!@!@",$question_8);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_9)>0)
{
$temp_answer=$this->real_escape($answer_9);
$temp_str=implode("!@!@",$question_9);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_10)>0)
{
$temp_answer=$this->real_escape($answer_10);
$temp_str=implode("!@!@",$question_10);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_11)>0)
{
$temp_answer=$this->real_escape($answer_11);
$temp_str=implode("!@!@",$question_11);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_12)>0)
{
$temp_answer=$this->real_escape($answer_12);
$temp_str=implode("!@!@",$question_12);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_13)>0)
{
$temp_answer=$this->real_escape($answer_13);
$temp_str=implode("!@!@",$question_13);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_14)>0)
{
$temp_answer=$this->real_escape($answer_14);
$temp_str=implode("!@!@",$question_14);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
if(count($question_15)>0)
{
$temp_answer=$this->real_escape($answer_15);
$temp_str=implode("!@!@",$question_15);
$temp_str=$this->real_escape($temp_str);
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,answer,type,created_by,created_ip) VALUES('$generated_id_2','$temp_str','$temp_answer','18','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
}
$this->commit();
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function add_treatment_type_5($code,$std,$month,$week,$day,$title)
{
try
{
$title=trim($title);
if($this->validate_obj->is_set($code)){throw new Exception(ERROR_INVALID_REQUEST."1");}
if($this->validate_obj->is_empty($code)){throw new Exception(ERROR_INVALID_REQUEST."2");}
if($this->validate_obj->is_char($code)){throw new Exception(ERROR_INVALID_REQUEST."3");}
if($this->validate_obj->is_set($std)){throw new Exception(ERROR_INVALID_REQUEST."4");}
if($this->validate_obj->is_empty($std)){throw new Exception(ERROR_INVALID_REQUEST."5");}
if($this->validate_obj->is_num($std)){throw new Exception(ERROR_INVALID_REQUEST."6");}
if($this->validate_obj->is_set($month)){throw new Exception(ERROR_INVALID_REQUEST."7");}
if($this->validate_obj->is_empty($month)){throw new Exception(ERROR_INVALID_REQUEST."8");}
if($this->validate_obj->is_num($month)){throw new Exception(ERROR_INVALID_REQUEST."9");}
if($this->validate_obj->is_set($week)){throw new Exception(ERROR_INVALID_REQUEST."10");}
if($this->validate_obj->is_empty($week)){throw new Exception("Error : Please select week...");}
if($this->validate_obj->is_num($week)){throw new Exception(ERROR_INVALID_REQUEST."11");}
if($this->validate_obj->is_set($day)){throw new Exception(ERROR_INVALID_REQUEST."12");}
if($this->validate_obj->is_empty($day)){throw new Exception("Error : Please select day...");}
if($this->validate_obj->is_num($day)){throw new Exception(ERROR_INVALID_REQUEST."13");}
if($this->validate_obj->is_set($title)){throw new Exception(ERROR_INVALID_REQUEST."13");}
if($this->validate_obj->is_empty($title)){throw new Exception("Error : Please enter Title...");}
// file upload
$allowedExts = array("png", "jpg", "jpeg", "jpe","doc","docx","xls","xlsx","pdf","ppt", "PNG", "JPG", "JPEG", "JPE","DOC","DOCX","XLS","XLSX","PDF","PPT");
$month_year=date("m_Y");
$upload_directory="../franchise/images/".$month_year;
if (!is_dir($upload_directory))
{
mkdir($upload_directory, 0777, true);
}
$upload_directory_to_write="images/".$month_year;
if($_FILES["upload_files"]["error"]==UPLOAD_ERR_NO_FILE)
{
throw new Exception("Error : Please choose a file first...");
}
if($_FILES["upload_files"]["error"]>1)
{
throw new Exception("Error : Error in file...".$_FILES["upload_files"]["error"]);
}
if($_FILES["upload_files"]["size"]>MAX_IMAGE_SIZE)
{
throw new Exception("Error : File size must not exceed ".MAX_IMAGE_SIZE_ERROR."...");
}
$temp = explode(".", $_FILES["upload_files"]["name"]);
$extension = end($temp);
if(!in_array($extension, $allowedExts))
{
throw new Exception("Error : This type of file is not allowed...");
}
$target_filename=$_FILES["upload_files"]["tmp_name"];
$unique="no";
while($unique=="no")
{
$new_file_name=time().str_shuffle("ABCDEFGHIJKLMNOPQRSTUPWXYZ").rand(1000,9999).".".$extension;
if(!file_exists($upload_directory."/".$new_file_name))
{
$unique="yes";
}
}
if(!move_uploaded_file($_FILES["upload_files"]["tmp_name"], $upload_directory."/".$new_file_name))
{
throw new Exception("Error : Couldn't save file on server...");
}
$this->open_connection();
$this->START_TRANSACTION();
$title=$this->real_escape($title);
$statement="INSERT INTO shristi_treatments(for_std,for_month,code,for_week,for_day,created_by,created_browser,created_ip) VALUES('$std','$month','$code','$week','$day','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 1...!!!");
}
$generated_id=$this->insert_id();
$statement="INSERT INTO shristi_treatments_main_questions(treatment_code,question_paragraph,created_by,created_browser,created_ip) VALUES('$generated_id','$title','$this->my_table_id','$this->browser','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 8...!!!");
}
$generated_id_2=$this->insert_id();
$to_write="<h3><a href=\"".$upload_directory."/".$new_file_name."\" target=\"_blank\">Link</a></h3>";
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$to_write','25','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
$this->commit();
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function update_type_5_upload($tid)
{
try
{
if($this->validate_obj->is_set($tid)){throw new Exception(ERROR_INVALID_REQUEST."1");}
if($this->validate_obj->is_empty($tid)){throw new Exception(ERROR_INVALID_REQUEST."2");}
if($this->validate_obj->is_num($tid)){throw new Exception(ERROR_INVALID_REQUEST."3");}
// file upload
$allowedExts = array("png", "jpg", "jpeg", "jpe","doc","docx","xls","xlsx","pdf","ppt", "PNG", "JPG", "JPEG", "JPE","DOC","DOCX","XLS","XLSX","PDF","PPT");
$month_year=date("m_Y");
$upload_directory="../franchise/images/".$month_year;
if (!is_dir($upload_directory))
{
mkdir($upload_directory, 0777, true);
}
$upload_directory_to_write="images/".$month_year;
if($_FILES["upload_files"]["error"]==UPLOAD_ERR_NO_FILE)
{
throw new Exception("Error : Please choose a file first...");
}
if($_FILES["upload_files"]["error"]>1)
{
throw new Exception("Error : Error in file...".$_FILES["upload_files"]["error"]);
}
if($_FILES["upload_files"]["size"]>MAX_IMAGE_SIZE)
{
throw new Exception("Error : File size must not exceed ".MAX_IMAGE_SIZE_ERROR."...");
}
$temp = explode(".", $_FILES["upload_files"]["name"]);
$extension = end($temp);
if(!in_array($extension, $allowedExts))
{
throw new Exception("Error : This type of file is not allowed...");
}
$target_filename=$_FILES["upload_files"]["tmp_name"];
$unique="no";
while($unique=="no")
{
$new_file_name=time().str_shuffle("ABCDEFGHIJKLMNOPQRSTUPWXYZ").rand(1000,9999).".jpeg";
if(!file_exists($upload_directory."/".$new_file_name))
{
$unique="yes";
}
}
if(!move_uploaded_file($_FILES["upload_files"]["tmp_name"], $upload_directory."/".$new_file_name))
{
throw new Exception("Error : Couldn't save file on server...");
}
$this->open_connection();
$statement="SELECT table_id FROM shristi_treatments_main_questions WHERE treatment_code='$tid'";
$res=$this->simply_run_statement_passed($statement);
if($res->num_rows!=1)
{
throw new Exception("Error : Corrupt VDR treatment...!!!");
}
$detail=$res->fetch_assoc();
$generated_id_2=$detail['table_id'];
$to_write="<h3><a href=\"".$upload_directory."/".$new_file_name."\" target=\"_blank\">Link</a></h3>";
$statement="INSERT INTO shristi_treatments_sub_questions(sub_treatment_codes,options,type,created_by,created_ip) VALUES('$generated_id_2','$to_write','25','$this->my_table_id','$this->ip')";
if(!$this->simply_run_statement_passed($statement))
{
$this->rollback();
$this->close_connection();
throw new Exception("Error : Couldn't save 3...!!!");
}
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function add_treatment_condition($code,$std,$month,$week,$day)
{
try
{
if($this->validate_obj->is_set($code)){throw new Exception(ERROR_INVALID_REQUEST."1");}
if($this->validate_obj->is_empty($code)){throw new Exception("Error : Please select Code...");}
if($this->validate_obj->is_char($code)){throw new Exception(ERROR_INVALID_REQUEST."3");}
if($this->validate_obj->is_set($std)){throw new Exception(ERROR_INVALID_REQUEST."4");}
if($this->validate_obj->is_empty($std)){throw new Exception("Error : Please select Std...");}
if($this->validate_obj->is_num($std)){throw new Exception(ERROR_INVALID_REQUEST."6");}
if($this->validate_obj->is_set($month)){throw new Exception(ERROR_INVALID_REQUEST."7");}
if($this->validate_obj->is_empty($month)){throw new Exception("Error : Please select Month...");}
if($this->validate_obj->is_num($month)){throw new Exception(ERROR_INVALID_REQUEST."9");}
if($this->validate_obj->is_set($week)){throw new Exception(ERROR_INVALID_REQUEST."10");}
if($this->validate_obj->is_empty($week)){throw new Exception("Error : Please select week...");}
if($this->validate_obj->is_num($week)){throw new Exception(ERROR_INVALID_REQUEST."11");}
if($this->validate_obj->is_set($day)){throw new Exception(ERROR_INVALID_REQUEST."12");}
if($this->validate_obj->is_empty($day)){throw new Exception("Error : Please select day...");}
if($this->validate_obj->is_num($day)){throw new Exception(ERROR_INVALID_REQUEST."13");}
$this->open_connection();
$code=$this->real_escape($code);
$prep="INSERT INTO shristi_treatments(code,for_std,for_month,for_week,for_day) VALUES('$code','$std','$month','$week','$day')";
if(!$this->simply_run_statement_passed($prep))
{
$this->close_connection();
throw new Exception("Error : Couldn't insert...Please contact your administrator...!!!");
}
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function get_code_from_table_id($tid)
{
try
{
if($this->validate_obj->is_set($tid)){throw new Exception(ERROR_INVALID_REQUEST."4");}
if($this->validate_obj->is_empty($tid)){throw new Exception(ERROR_INVALID_REQUEST."5");}
if($this->validate_obj->is_num($tid)){throw new Exception(ERROR_INVALID_REQUEST."6");}
$this->open_connection();
$res=$this->simply_run_statement_passed("SELECT code FROM shristi_treatments WHERE table_id='$tid'");
$this->close_connection();
if($res->num_rows!=1) throw new Exception("Error : treatment not found...");
$detail=$res->fetch_assoc();
return $detail['code'];
}
catch(Exception $e)
{
echo($e->getMessage());
exit();
}
}
function delete_treatment($to_delete)
{
try
{
if($this->validate_obj->is_set($to_delete)){throw new Exception(ERROR_INVALID_REQUEST."4");}
if($this->validate_obj->is_empty($to_delete)){throw new Exception(ERROR_INVALID_REQUEST."5");}
if($this->validate_obj->is_num($to_delete)){throw new Exception(ERROR_INVALID_REQUEST."6");}
$this->open_connection();
$this->START_TRANSACTION();
$prep="SELECT table_id FROM shristi_treatments_main_questions WHERE treatment_code='$to_delete'";
$res=$this->simply_run_statement_passed($prep);
while($detail=$res->fetch_assoc())
{
$this->simply_run_statement_passed("DELETE FROM shristi_treatments_sub_questions WHERE sub_treatment_codes='{$detail['table_id']}'");
}
$this->simply_run_statement_passed("DELETE FROM shristi_treatments_main_questions WHERE treatment_code='$to_delete'");
$this->simply_run_statement_passed("DELETE FROM shristi_treatments WHERE table_id='$to_delete'");
$this->commit();
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function change_password($id,$old_password,$new_password,$retype_password)
{
try
{
if($this->validate_obj->is_set($id)){throw new Exception(ERROR_SESSION_INVALID);}
if($this->validate_obj->is_empty($id)){throw new Exception(ERROR_SESSION_INVALID);}
if($this->validate_obj->is_num($id)){throw new Exception(ERROR_SESSION_INVALID);}
if($this->validate_obj->is_set($old_password)){throw new Exception("Error : Invalid old password...!!!");}
if($this->validate_obj->is_empty($old_password)){throw new Exception("Error : Please enter old password...!!!");}
if($this->validate_obj->is_exceeding_limit($old_password,100)){throw new Exception("Error : Old Password must be below 100 characters...!!!");}
if($this->validate_obj->is_set($new_password)){throw new Exception("Error : Invalid new password...!!!");}
if($this->validate_obj->is_empty($new_password)){throw new Exception("Error : Please enter new password...!!!");}
if($this->validate_obj->is_exceeding_limit($new_password,100)){throw new Exception("Error : New Password must be below 100 characters...!!!");}
if($this->validate_obj->is_set($retype_password)){throw new Exception("Error : Invalid Retype password...!!!");}
if($this->validate_obj->is_empty($retype_password)){throw new Exception("Error : Please Retype New password...!!!");}
if($new_password!=$retype_password)
{
throw new Exception("Error : Password and Retype Password do not match...!!!");
}
if(strlen($new_password)<6)
{
throw new Exception("Error : Please enter atleast 6 characters in New password...!!!");
}
$this->open_connection();
$id=$this->real_escape($id);
$new_password=$this->real_escape($new_password);
$prep="UPDATE login SET password='$new_password' WHERE table_id='$id' AND password='$old_password'";
$this->simply_run_statement_passed($prep);
if($this->affected_rows()!=1)
{
$this->close_connection();
throw new Exception("Error : Incorrect old password...");
}
$this->close_connection();
return "ok";
}
catch (Exception $e)
{
return $e->getMessage();
}
}
function all_students($page_no,&$pages_return,$reg_no,$franchise,$student_name,$reg_date_from,$reg_date_to)
{
try
{
if($this->validate_obj->is_set($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($page_no))
{
if($this->validate_obj->is_num($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
}
$this->open_connection();
$reg_no=$this->real_escape($reg_no);
$franchise=$this->real_escape($franchise);
$student_name=$this->real_escape($student_name);
$reg_date_from=$this->real_escape($reg_date_from);
$reg_date_to=$this->real_escape($reg_date_to);
$statement="SELECT SQL_CALC_FOUND_ROWS a.name,a.registration_no,a.registration_date,b.username AS franchise_name FROM shristi_child_details a INNER JOIN shristi_login b ON b.table_id=a.franchise_id WHERE 1=1 ";
if($reg_no!="")
{
$statement.=" AND a.registration_no='$reg_no' ";
}
if($franchise!="")
{
$statement.=" AND b.username LIKE ('%$franchise%') ";
}
if($student_name!="")
{
$statement.=" AND a.name LIKE('%$student_name%') ";
}
if($reg_date_from!="")
{
$statement.=" AND a.registration_date>='$reg_date_from' ";
}
if($reg_date_to!="")
{
$statement.=" AND a.registration_date<='$reg_date_to' ";
}
$statement.=" ORDER BY a.name ";
$start=PER_PAGE_STUDENTS*$page_no;
$statement.=" LIMIT $start,50 ";
$sql = $this->simply_run_statement_passed($statement);
$res_rows=$this->simply_run_statement_passed("SELECT FOUND_ROWS() as total_rows");
$this->close_connection();
$detail_rows=$res_rows->fetch_assoc();
$rows_found=$detail_rows['total_rows'];
$left=$rows_found%PER_PAGE_STUDENTS;
$pages_return=(int)($rows_found/PER_PAGE_STUDENTS);
if($left>0)$pages_return++;
return $sql;
}
catch(Exception $e)
{
echo($e->getMessage());
exit();
}
}
/*function month_view($id){
try
{
$this->open_connection();
echo $statement = "UPDATE shristi_login SET 5month_view='0' WHERE table_id='$id'";
$sql = $this->simply_run_statement_passed($statement);
return "ok";
}
catch(Exception $e){
echo($e->getMessage());
exit();
}
}*/
function all_franchise($page_no,&$pages_return)
{
try
{
if($this->validate_obj->is_set($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
if($this->validate_obj->is_empty($page_no))
{
if($this->validate_obj->is_num($page_no)){echo(ERROR_INVALID_REQUEST);exit();}
}
$this->open_connection();
$statement="SELECT SQL_CALC_FOUND_ROWS a.table_id,a.name,a.username,a.5month_view,a.password,a.status,DATE(a.created_date) AS reg_date,(SELECT COUNT(table_id) AS total_children FROM shristi_child_details WHERE franchise_id=a.table_id) AS children_count FROM shristi_login a WHERE 1=1 AND type='franchise' ORDER BY a.username ";
$start=PER_PAGE_STUDENTS*$page_no;
$statement.=" LIMIT $start,50 ";
$sql = $this->simply_run_statement_passed($statement);
$res_rows=$this->simply_run_statement_passed("SELECT FOUND_ROWS() as total_rows");
$this->close_connection();
$detail_rows=$res_rows->fetch_assoc();
$rows_found=$detail_rows['total_rows'];
$left=$rows_found%PER_PAGE_STUDENTS;
$pages_return=(int)($rows_found/PER_PAGE_STUDENTS);
if($left>0)$pages_return++;
return $sql;
}
catch(Exception $e)
{
echo($e->getMessage());
exit();
}
}
function add_franchise($id,$name,$username,$password,$status)
{
try
{
if($this->validate_obj->is_set($id)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($id)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_num($id)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_set($name)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($name)){throw new Exception("Error : Please enter Name...!!!");}
if($this->validate_obj->is_set($username)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($username)){throw new Exception("Error : Please enter Username...!!!");}
if($this->validate_obj->is_set($password)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($password)){throw new Exception("Error : Please enter Password...!!!");}
if($this->validate_obj->is_set($status)){throw new Exception(ERROR_INVALID_REQUEST);}
$this->open_connection();
$name=$this->real_escape($name);
$username=$this->real_escape($username);
$password=$this->real_escape($password);
$status=$this->real_escape($status);
$res=$this->simply_run_statement_passed("SELECT table_id FROM shristi_login WHERE username='$username'");
if($res->num_rows>0)
{
$this->close_connection();
throw new Exception("Error : Username already exists...Please choose another username...!!!");
}
$statement=" INSERT INTO shristi_login(username,password,name,type,status) VALUES('$username','$password','$name','franchise','$status') ";
if(!$this->simply_run_statement_passed($statement))
{
$this->close_connection();
throw new Exception("Error : Couldn't add...Please contact your administrator...");
}
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function update_franchise($id,$name,$username,$password,$status)
{
try
{
if($this->validate_obj->is_set($id)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($id)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_num($id)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_set($name)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($name)){throw new Exception("Error : Please enter Name...!!!");}
if($this->validate_obj->is_set($username)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($username)){throw new Exception("Error : Please enter Username...!!!");}
if($this->validate_obj->is_set($password)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($password)){throw new Exception("Error : Please enter Password...!!!");}
if($this->validate_obj->is_set($status)){throw new Exception(ERROR_INVALID_REQUEST);}
$this->open_connection();
$name=$this->real_escape($name);
$username=$this->real_escape($username);
$password=$this->real_escape($password);
$status=$this->real_escape($status);
$statement=" UPDATE shristi_login SET username='$username',password='$password',name='$name',status='$status' WHERE table_id='$id' ";
if(!$this->simply_run_statement_passed($statement))
{
$this->close_connection();
throw new Exception("Error : Couldn't add...Please contact your administrator...");
}
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
function get_franchise_details($fid)
{
try
{
if($this->validate_obj->is_set($fid)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($fid)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_num($fid)){throw new Exception(ERROR_INVALID_REQUEST);}
$this->open_connection();
$statement=" SELECT * FROM shristi_login WHERE table_id='$fid' ";
$res=$this->simply_run_statement_passed($statement);
$this->close_connection();
return $res;
}
catch(Exception $e)
{
echo $e->getMessage();exit();
}
}
function delete_franchise($fid)
{
try
{
if($this->validate_obj->is_set($fid)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_empty($fid)){throw new Exception(ERROR_INVALID_REQUEST);}
if($this->validate_obj->is_num($fid)){throw new Exception(ERROR_INVALID_REQUEST);}
$this->open_connection();
$statement=" SELECT * FROM shristi_child_details WHERE franchise_id='$fid' ";
$res=$this->simply_run_statement_passed($statement);
if($res->num_rows>0)
{
$this->close_connection();
throw new Exception("Error : There are Students under this franchise...Cannot delete...");
}
$this->simply_run_statement_passed("DELETE FROM shristi_login WHERE table_id='$fid'");
$this->close_connection();
return "ok";
}
catch(Exception $e)
{
return $e->getMessage();
}
}
}
?>