Preview: WebadminController.php
Size: 80.83 KB
/home/jambtst2015/public_html/protected/controllers/_notes/WebadminController.php
<?php
class WebadminController extends Controlleradmin
{
private $exam_body;
private $subject_body;
private $question_body;
private $lastID;
private $ajax_val;
private $question_answer;
private $pin_value;
private $pin_body;
private $cms_body;
private $array_new;
private $pin_mapping;
/**
* Declares class-based actions.
*/
/**
* tableId 1 for exambody
* tableId 2 for exam_subject
* tableId 3 for exam_paper
* tableId 4 for exam_question
*/
public function actions()
{
return array(
// captcha action renders the CAPTCHA image displayed on the contact page
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
),
// page action renders "static" pages stored under 'protected/views/site/pages'
// They can be accessed via: index.php?r=site/page&view=FileName
'page'=>array(
'class'=>'CViewAction',
),
);
}
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionIndex()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->pageTitle = Yii::app()->name . ' - Dashboard';
/*$this->breadcrumbs = array(
'Login / Register',
);*/
//echo Helpers::getsingleRecord('exam_body','name','id','1');
//$this->getsingleRecord('Exambody::','name','id','1');
//echo $filename = Yii::app()->params['imagebasePath'].'/pincsv/pin.csv';
//echo '<br>';
//$record = Csvreader::parse_file($filename);
//$record = $this->parse_file($filename);
//print_r($record);
//exit;
$this->layout = 'adminmain';
$this->render('index');
}
/**
* This is the action to handle external exceptions.
*/
public function actionError()
{
if($error=Yii::app()->errorHandler->error)
{
if(Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionExambodylist()
{
//print_r(Yii::app()->user->getState('SearchForm'));
$model=new ExambodylistForm;
$editRecord['name']='';
$editRecord['full_name']='';
$editRecord['validity']='';
for($days=1;$days<366;$days++){
$dayArray[$days] = $days;
}
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->pageTitle = Yii::app()->name . ' - Login / Register';
/*$this->breadcrumbs = array(
'Login / Register',
);*/
if(empty($_GET['page'])){
$pageNo = 1;
}else{
$pageNo = $_GET['page'];
}
$criteria=new CDbCriteria();
$search = Yii::app()->request->getQuery('search');
if($search>0){
if(isset($_POST['ExambodylistForm']) || Yii::app()->user->hasState('SearchForm'))
{
$criteria2=new CDbCriteria;
if(isset($_POST['ExambodylistForm'])){
Yii::app()->user->setState('SearchForm',$_POST['ExambodylistForm']);
}else{
$_POST['ExambodylistForm']=Yii::app()->user->getState('SearchForm');
}
if($_POST['ExambodylistForm']['name']!=''){
$criteria->condition = 'name LIKE :name';
$criteria->params = array(':name' => '%'.trim($_POST['ExambodylistForm']['name']).'%');
$editRecord['name']=$_POST['ExambodylistForm']['name'];
}
if($_POST['ExambodylistForm']['full_name']!=''){
$criteria2->condition = 'full_name LIKE :full_name';
$criteria2->params = array(':full_name' => '%'.trim($_POST['ExambodylistForm']['full_name']).'%');
$editRecord['full_name']=$_POST['ExambodylistForm']['full_name'];
}
if($_POST['ExambodylistForm']['validity']!=''){
$criteria->compare('validity',$_POST['ExambodylistForm']['validity']);
$editRecord['validity']=$_POST['ExambodylistForm']['validity'];
}
$criteria->order = 'id desc';
$criteria->mergeWith($criteria2, 'AND');
}
}else{
Yii::app()->user->setState('SearchForm','');
}
//create orderring//
$ordering_field = Yii::app()->request->getQuery('field');
$ordering_type = Yii::app()->request->getQuery('order');
$ordering_type_array=explode('/',$ordering_type);
//echo $ordering_type = $ordering_type_array[0];
if($ordering_field!='' && $ordering_type!=''){
$order_by = $ordering_field.' '.$ordering_type;
Yii::app()->user->setState('order_by',$order_by);
}
if(Yii::app()->user->hasState('order_by') && Yii::app()->user->getState('order_by')!=''){
$criteria->order = Yii::app()->user->getState('order_by');
}
if($search=='' && $ordering_field==''){
$criteria->order = ('id desc');
Yii::app()->user->setState('order_by','');
}
//end of ordering//
$criteria->compare('del_status',0);
$count=Exambody::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Exambody::model()->findAll($criteria);
$allExambody = $models;
$this->layout = 'adminmain';
$this->render('exambodylist',array('allExambody'=>$allExambody,'model'=>$model,'pageMax' => $pages->pageSize,'pageNo' => $pageNo,'pages' => $pages,'editRecord'=>$editRecord,'dayArray'=>$dayArray));
}
/**
* Displays the exam bode page
*/
public function actionExambody()
{
$model=new ExambodyForm;
//echo Yii::app()->imagebasePath;
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$this->pageTitle = Yii::app()->name . ' - Exam Body Edit';
$this->breadcrumbs=array(
'Exam Body'=>array('webadmin/exambodylist'),
'Exam Body Edit',
);
$editRecord = Exambody::model()->findByPK($editId);
}else{ //add
$this->pageTitle = Yii::app()->name . ' - Exam Body Add';
$this->breadcrumbs=array(
'Exam Body'=>array('webadmin/exambodylist'),
'Exam Body Add',
);
$editRecord['name']='';
$editRecord['full_name']='';
$editRecord['logo']='';
$editRecord['validity']='';
}
if(isset($_POST['ExambodyForm']))
{
$model->attributes=$_POST['ExambodyForm'];
if($model->validate())
{
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$record = Exambody::model()->find("name = '".addslashes($model->name)."' AND id!='".$editId."' AND del_status='0'");
if (empty($record)){
$images_forcheck = CUploadedFile::getInstancesByName('image');
if(count($images_forcheck)>0){
$images = EUploadedImage::getInstancesByName('image');
foreach($images as $img)
{
$newName = md5(microtime(true)) . '_' . str_replace("#","",$img->name);
$res = $img->saveAs('uploads/exambody/' . $newName);
$img->maxWidth = 144;
$img->maxHeight = 80;
$res = $img->saveAs('uploads/exambody/thumbnail/' .$newName);
}
}else{
$newName=$_REQUEST['h_image'];
}
//update
$updateExambody = Exambody::model()->updateByPk($editId,array("name"=>$model->name,"full_name"=>$model->full_name,"logo"=>$newName,"validity"=>$model->validity,"modify_date"=>new CDbExpression('NOW()')));
if($updateExambody){
Yii::app()->user->setFlash('exambody','Exam Body Updated Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/exambodylist/'));
}
}else{
// record exists
Yii::app()->user->setFlash('error','Exam Body Already Exists.');
$editRecord['name']=$model->name;
$editRecord['full_name']=$model->full_name;
}
}else{ //add
$record = Exambody::model()->find("name = '".addslashes($model->name)."' AND del_status='0'");
if (empty($record)){
// record does't exist
//exit("record does't exist");
//image upload
//$uploadedFile=CUploadedFile::getInstance($model,'image');
$images_forcheck = CUploadedFile::getInstancesByName('image');
if(count($images_forcheck)>0){
$images = EUploadedImage::getInstancesByName('image');
foreach($images as $img)
{
$newName = md5(microtime(true)) . '_' .str_replace("#","",$img->name);
$res = $img->saveAs('uploads/exambody/' . $newName);
$img->maxWidth = 144;
$img->maxHeight = 80;
$res = $img->saveAs('uploads/exambody/thumbnail/' .$newName);
}
}else{
$newName='';
}
//insert
$this->exam_body = new Exambody;
$this->exam_body->name = $model->name;
$this->exam_body->full_name = $model->full_name;
$this->exam_body->logo = $newName;
$this->exam_body->validity = $model->validity;
$this->exam_body->post_date = new CDbExpression('NOW()');
$saved = $this->exam_body->save();
$this->lastID = Yii::app()->db->getLastInsertID();
//exit($this->lastID);
if($this->lastID){
Yii::app()->user->setFlash('exambody','Exam Body Added Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/exambodylist/'));
}
}else {
// record exists
Yii::app()->user->setFlash('error','Exam Body Already Exists.');
$editRecord['name']=$model->name;
$editRecord['full_name']=$model->full_name;
//$this->refresh();
//exit("record exists");
}
}
}
}
for($days=1;$days<366;$days++){
$dayArray[$days] = $days;
}
$this->layout = 'adminmain';
$this->render('exambody',array('model'=>$model,'editRecord'=>$editRecord,'dayArray'=>$dayArray));
}
/**
* Displays the contact page
*/
public function actionContact()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$name='=?UTF-8?B?'.base64_encode($model->name).'?=';
$subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
$headers="From: $name <{$model->email}>\r\n".
"Reply-To: {$model->email}\r\n".
"MIME-Version: 1.0\r\n".
"Content-Type: text/plain; charset=UTF-8";
mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->layout = 'adminmain';
$this->render('contact',array('model'=>$model));
}
/**
* Displays the login page
*/
public function actionLogin()
{
//exit("actionLogin");
$model=new AdminLoginForm;
$this->pageTitle=Yii::app()->name . ' - Administration Login';
// if it is ajax validation request
if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
// collect user input data
if(isset($_POST['AdminLoginForm']))
{
//exit("actionLogin");
$model->attributes=$_POST['AdminLoginForm'];
// validate user input and redirect to the previous page if valid
if($model->validate() && $model->login())
$this->redirect(Yii::app()->user->returnUrl.'webadmin/');
}
$this->layout = 'adminmain';
// display the login form
$this->render('login',array('model'=>$model));
}
// List The subjects //
public function actionSubjectlist()
{
$model=new SubjectbodylistForm;
$editRecord['exam_id']='';
$editRecord['subject']='';
$editRecord['pass_marks']='';
$models=Exambody::model()->findAll("del_status='0' order by name asc");
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->pageTitle = Yii::app()->name . ' - Subject List';
$this->breadcrumbs = array(
'Subject List',
);
if(empty($_GET['page'])){
$pageNo = 1;
}else{
$pageNo = $_GET['page'];
}
$criteria=new CDbCriteria(array('order'=>'id desc'));
$criteria2=new CDbCriteria;
$search = Yii::app()->request->getQuery('search');
if($search>0){
if(isset($_POST['SubjectbodylistForm']) || Yii::app()->user->hasState('SearchForm'))
{
if(isset($_POST['SubjectbodylistForm'])){
Yii::app()->user->setState('SearchForm',$_POST['SubjectbodylistForm']);
}else{
$_POST['SubjectbodylistForm']=Yii::app()->user->getState('SearchForm');
}
if($_POST['SubjectbodylistForm']['exam_name']!=''){
$criteria->compare('exam_id',$_POST['SubjectbodylistForm']['exam_name']);
$editRecord['exam_id']=$_POST['SubjectbodylistForm']['exam_name'];
}
if($_POST['SubjectbodylistForm']['subject_name']!=''){
$criteria2->condition = 'subject LIKE :subject';
$criteria2->params = array(':subject' => '%'.trim($_POST['SubjectbodylistForm']['subject_name']).'%');
$editRecord['subject']=$_POST['SubjectbodylistForm']['subject_name'];
}
if($_POST['SubjectbodylistForm']['marks']!=''){
$criteria->compare('pass_marks',$_POST['SubjectbodylistForm']['marks']);
$editRecord['pass_marks']=$_POST['SubjectbodylistForm']['marks'];
}
$criteria->order = 'id desc';
$criteria->mergeWith($criteria2, 'AND');
}
}else{
Yii::app()->user->setState('SearchForm','');
}
//create orderring//
$ordering_field = Yii::app()->request->getQuery('field');
$ordering_type = Yii::app()->request->getQuery('order');
if($ordering_field!='' && $ordering_type!=''){
$order_by = $ordering_field.' '.$ordering_type;
Yii::app()->user->setState('order_by',$order_by);
}
if(Yii::app()->user->hasState('order_by') && Yii::app()->user->getState('order_by')!=''){
$criteria->order = Yii::app()->user->getState('order_by');
}
if($search=='' && $ordering_field==''){
$criteria->order = ('id desc');
Yii::app()->user->setState('order_by','');
}
//end of ordering//
$criteria->compare('del_status',0);
$count=Subjectbody::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Subjectbody::model()->findAll($criteria);
$allSubject = $models;
$this->layout = 'adminmain';
$this->render('subjectbodylist',array('allSubject'=>$allSubject,'editRecord'=>$editRecord,'allSubjectarray'=>$allSubjectarray,'model'=>$model,'pageMax' => $pages->pageSize,'pageNo' => $pageNo,'pages' => $pages));
}
//end of subject Listing//
//add or edit subject//
public function actionSubjectbody()
{
$model=new SubjectbodyForm;
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$this->pageTitle = Yii::app()->name . ' - Subject Body Edit';
$this->breadcrumbs=array(
'Subject Body'=>array('webadmin/subjectlist'),
'Subject Body Edit',
);
$editRecord = Subjectbody::model()->findByPK($editId);
}else{ //add
$this->pageTitle = Yii::app()->name . ' - Subject Body Add';
$this->breadcrumbs=array(
'Subject Body'=>array('webadmin/subjectlist'),
'Subject Body Add',
);
$editRecord['exam_name']='';
$editRecord['subject']='';
$editRecord['pass_marks']='';
$editRecord['compulsory']='';
$editRecord['exam_id']='';
}
if(isset($_POST['SubjectbodyForm']))
{
$model->attributes=$_POST['SubjectbodyForm'];
if($model->validate())
{
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$record = Subjectbody::model()->find("subject = '".addslashes($model->subject_name)."' AND exam_id='".$model->exam_name."' AND id!='".$editId."' AND del_status='0'");
if (empty($record)){
//update
$updateExambody = Subjectbody::model()->updateByPk($editId,array("exam_id"=>$model->exam_name,"subject"=>$model->subject_name,"pass_marks"=>$model->marks,"compulsory"=>$model->compulsory,"modify_date"=>new CDbExpression('NOW()')));
if($updateExambody){
Yii::app()->user->setFlash('subjectbody','Subject Body Updated Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/subjectlist/'));
}
}else{
// record exists
Yii::app()->user->setFlash('error','Subject Already Exists.');
$editRecord['subject_name']=$model->subject_name;
$editRecord['exam_name']=$model->exam_name;
$editRecord['marks']=$model->marks;
}
}else{ //add
$record = Subjectbody::model()->find("subject = '".addslashes($model->subject_name)."' AND exam_id='".$model->exam_name."' AND del_status='0'");
if (empty($record)){
//insert
$this->subject_body = new Subjectbody;
$this->subject_body->exam_id = $model->exam_name;
$this->subject_body->subject= $model->subject_name;
$this->subject_body->pass_marks = $model->marks;
//$this->subject_body->pass_marks = $model->marks;
$this->subject_body->compulsory = $model->compulsory;
//$this->subject_body->logo = $model->image;
$this->subject_body->post_date = new CDbExpression('NOW()');
$saved = $this->subject_body->save();
$this->lastID = Yii::app()->db->getLastInsertID();
//exit($this->lastID);
if($this->lastID){
Yii::app()->user->setFlash('subjectbody','Subject Added Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/subjectlist/'));
}
}else {
// record exists
Yii::app()->user->setFlash('error','Subject Already Exists.');
$editRecord['subject_name']=$model->subject_name;
$editRecord['exam_name']=$model->exam_name;
$editRecord['marks']=$model->marks;
//$editRecord['exam_name']=$model->exam_name;
//$this->refresh();
//exit("record exists");
}
}
}
}
$criteria=new CDbCriteria(array('order'=>'name desc'));
$criteria->compare('del_status',0);
$models=Exambody::model()->findAll("status='Active' and del_status='0' order by name asc");
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
$this->layout = 'adminmain';
$this->render('subjectbody',array('model'=>$model,'editRecord'=>$editRecord,'allSubjectarray'=>$allSubjectarray));
}
//end of add edit subject//
//question paper listing//
public function actionQuestionbatch()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$model=new QuestionbodylistForm;
$editRecord['exam_id']='';
$editRecord['subject_id']='';
$editRecord['paper_name']='';
$editRecord['pass_marks']='';
$subject = array();
$paper=array();
$criteria=new CDbCriteria(array('order'=>'name desc'));
$criteria->compare('del_status',0);
$models=Exambody::model()->findAll($criteria);
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
$this->pageTitle = Yii::app()->name . ' - Question Paper Listing';
$this->breadcrumbs = array(
'Question Paper List',
);
if(empty($_GET['page'])){
$pageNo = 1;
}else{
$pageNo = $_GET['page'];
}
$criteria=new CDbCriteria(array('order'=>'id desc'));
$criteria2=new CDbCriteria;
$search = Yii::app()->request->getQuery('search');
if($search>0){
if(isset($_POST['QuestionbodylistForm']) || Yii::app()->user->hasState('SearchForm'))
{
if(isset($_POST['QuestionbodylistForm'])){
Yii::app()->user->setState('SearchForm',$_POST['QuestionbodylistForm']);
}else{
$_POST['QuestionbodylistForm']=Yii::app()->user->getState('SearchForm');
}
if($_POST['QuestionbodylistForm']['exam_name']!=''){
$criteria->compare('exam_id',$_POST['QuestionbodylistForm']['exam_name']);
$editRecord['exam_id']=$_POST['QuestionbodylistForm']['exam_name'];
$subjects=Subjectbody::model()->findAll("exam_id=".$editRecord['exam_id']." AND del_status='0'");
$allSubjectarray2=CHtml::listData($subjects, 'id', 'subject');
$subject = $allSubjectarray2;
}
if($_POST['QuestionbodylistForm']['subject_name']!=''){
$criteria->compare('subject_id',$_POST['QuestionbodylistForm']['subject_name']);
$editRecord['subject_id']=$_POST['QuestionbodylistForm']['subject_name'];
}
if($_POST['QuestionbodylistForm']['question_paper_name']!=''){
$criteria2->condition = 'paper_name LIKE :paper_name';
$criteria2->params = array(':paper_name' => '%'.trim($_POST['QuestionbodylistForm']['question_paper_name']).'%');
$editRecord['paper_name']=$_POST['QuestionbodylistForm']['question_paper_name'];
}
if($_POST['QuestionbodylistForm']['marks']!=''){
$criteria->compare('pass_marks',$_POST['QuestionbodylistForm']['marks']);
$editRecord['pass_marks']=$_POST['QuestionbodylistForm']['marks'];
}
$criteria->order = ('id desc');
$criteria->mergeWith($criteria2, 'AND');
}
}else{
Yii::app()->user->setState('SearchForm','');
}
$criteria->compare('del_status',0);
//create orderring//
$ordering_field = Yii::app()->request->getQuery('field');
$ordering_type = Yii::app()->request->getQuery('order');
if($ordering_field!='' && $ordering_type!=''){
$order_by = $ordering_field.' '.$ordering_type;
Yii::app()->user->setState('order_by',$order_by);
}
if(Yii::app()->user->hasState('order_by') && Yii::app()->user->getState('order_by')!=''){
$criteria->order = Yii::app()->user->getState('order_by');
}
if($search=='' && $ordering_field==''){
$criteria->order = ('id desc');
Yii::app()->user->setState('order_by','');
}
//end of ordering//
$count=Questionbody::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Questionbody::model()->findAll($criteria);
$allQuestions = $models;
$this->layout = 'adminmain';
$this->render('questionbodylist',array('allQuestions'=>$allQuestions,'editRecord'=>$editRecord,'model'=>$model,'pageMax' => $pages->pageSize,'subject'=>$subject,'allSubjectarray'=>$allSubjectarray,'pageNo' => $pageNo,'pages' => $pages));
}
//end of question paper listing//
//question add or edit //
public function actionQuestionaddedit()
{
$model=new QuestionbodyForm;
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$this->pageTitle = Yii::app()->name . ' - Question Paper Edit';
$this->breadcrumbs=array(
'Question Paper'=>array('webadmin/questionbatch'),
'Question Paper Edit',
);
$editRecord = Questionbody::model()->findByPK($editId);
$subjects=Subjectbody::model()->findAll("exam_id=".$editRecord['exam_id']." AND del_status='0' AND status='Active'");
$allSubjectarray=CHtml::listData($subjects, 'id', 'subject');
$subject = $allSubjectarray;
}else{ //add
$this->pageTitle = Yii::app()->name . ' - Question Paper Add';
$this->breadcrumbs=array(
'Question Paper'=>array('webadmin/questionbatch'),
'Question Paper Add',
);
$editRecord['subject_id']='';
$editRecord['paper_name']='';
$editRecord['pass_marks']='';
$editRecord['compulsory']='';
$editRecord['exam_id']='';
$subject = array();
$paper = array();
}
if(isset($_POST['QuestionbodyForm']))
{
$model->attributes=$_POST['QuestionbodyForm'];
if($model->validate())
{
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$record = Questionbody::model()->find("exam_id = '".$model->exam_name."' AND subject_id='".$model->subject_name."' AND paper_name='".addslashes($model->question_paper_name)."' AND id!='".$editId."' AND del_status='0'");
if (empty($record)){
$updateExambody = Questionbody::model()->updateByPk($editId,array(
"exam_id"=>$model->exam_name,
"subject_id"=>$model->subject_name,
"pass_marks"=>$model->marks,
"paper_name"=>$model->question_paper_name,
"modify_date"=>new CDbExpression('NOW()')
));
if($updateExambody){
Yii::app()->user->setFlash('questionbody','Question Paper Updated Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/questionbatch/'));
}
}else{
// record exists
Yii::app()->user->setFlash('error','Question Already Exists.');
//$test = $this->actionAjaxpage('1',$editRecord['exam_id']);
//print_r($test);exit;
$editRecord['exam_id']=$model->exam_name;
$editRecord['paper_name']=$model->question_paper_name;
$editRecord['pass_marks']=$model->marks;
}
}else{ //add
$record = Questionbody::model()->find("exam_id = '".$model->exam_name."' AND subject_id='".$model->subject_name."'AND paper_name='".addslashes($model->question_paper_name)."' AND del_status='0'");
if (empty($record)){
//insert
$this->question_body = new Questionbody;
$this->question_body->exam_id = $model->exam_name;
$this->question_body->subject_id= $model->subject_name;
$this->question_body->pass_marks= $model->marks;
$this->question_body->paper_name = $model->question_paper_name;
$this->question_body->post_date = new CDbExpression('NOW()');
$saved = $this->question_body->save();
$this->lastID = Yii::app()->db->getLastInsertID();
//exit($this->lastID);
if($this->lastID){
Yii::app()->user->setFlash('questionbody','Question Paper Added Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/questionbatch/'));
}
}else {
// record exists
Yii::app()->user->setFlash('error','Question Already Exists.');
$editRecord['exam_id']=$model->exam_name;
$get_subject =$subjects=Subjectbody::model()->findAll("exam_id=".$editRecord['exam_id']." AND status='Active' AND del_status='0'");
$subject = CHtml::listData($get_subject, 'id', 'subject');
//print_r($editRecord['subject_id']);exit;
$editRecord['paper_name']=$model->question_paper_name;
$editRecord['pass_marks']=$model->marks;
}
}
}
}
$criteria=new CDbCriteria(array('order'=>'name desc'));
$criteria->compare('del_status',0);
$criteria->compare('status','Active');
$models=Exambody::model()->findAll($criteria);
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
$this->layout = 'adminmain';
$this->render('questionbody',array('model'=>$model,'editRecord'=>$editRecord,'subject'=>$subject,'allSubjectarray'=>$allSubjectarray));
}
//end of question add or edit//
//get ajax value//
public function actionAjaxpage($flag='',$purpose='')
{
if($flag!=''){
$_REQUEST['flag']=$flag;
}
if($purpose!=''){
$_REQUEST['value']=$purpose;
}
if($_REQUEST['flag']==1){
//flag 1//
$subjects=Subjectbody::model()->findAll("exam_id=".$_REQUEST['value']." AND status='Active' AND del_status='0'");
$allSubject = $subjects;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'subject');
$opVal = '';
$opVal = '<option value="">Select subject name</option>';
foreach($allSubjectarray as $key=>$value){
$opVal .= '<option value="'.$key.'">'.$value.'</option>';
}
if($flag!='' && $purpose!=''){
return $opVal;
}else{
echo $opVal;
}
}
elseif($_REQUEST['flag']==2){
//flag 2//
$subjects=Questionbody::model()->findAll("exam_id=".$_REQUEST['value']." AND subject_id='".$_REQUEST['subject']."' AND status='Active' AND DEL_status='0'");
$allSubject = $subjects;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'paper_name');
$opVal = '';
$opVal = '<option value="">Select paper name</option>';
foreach($allSubjectarray as $key=>$value){
$opVal .= '<option value="'.$key.'">'.$value.'</option>';
}
if($flag!='' && $purpose!=''){
return $opVal;
}else{
echo $opVal;
}
}
}
//end of ajax value//
//add question along with multiple answer//
public function actionConfigurequestionbatch(){
$model=new QuestionanswerForm;
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$this->pageTitle = Yii::app()->name . ' - Configure Question Batch Edit';
$this->breadcrumbs=array(
'Question Batch'=>array('webadmin/listinganswers'),
'Question Batch Edit',
);
$editRecord = Questionanswerbody::model()->findByPK($editId);
$subjects=Subjectbody::model()->findAll("exam_id=".$editRecord['exam_id']." AND status='Active' AND del_status='0'");
$allSubjectarray=CHtml::listData($subjects, 'id', 'subject');
$subject = $allSubjectarray;
$papers = Questionbody::model()->findAll("subject_id=".$editRecord['subject_id']." AND status='Active' AND del_status='0'");
$allPaperarray=CHtml::listData($papers, 'id', 'paper_name');
$paper = $allPaperarray;
$model->correct_answer = $editRecord['correct_ans'];
}else{ //add
$this->pageTitle = Yii::app()->name . ' - Configure Question Batch Add';
$this->breadcrumbs=array(
'Question Batch'=>array('webadmin/listinganswers'),
'Question Batch Add',
);
$editRecord['subject_id']='';
//$editRecord['paper_name']='';
$editRecord['paper_id']='';
//$editRecord['paper_name']='';
$editRecord['question']='';
$editRecord['exam_id']='';
$editRecord['ans1']='';
$editRecord['ans2']='';
$editRecord['ans3']='';
$editRecord['ans4']='';
$editRecord['ans5']='';
$paper=array();
//$model->correct_answer ='';
$subject = array();
}
if(isset($_POST['QuestionanswerForm']))
{
$model->attributes=$_POST['QuestionanswerForm'];
if($model->validate())
{
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$record = Questionanswerbody::model()->find("exam_id = '".$model->exam_name."' AND subject_id='".$model->subject_name."' AND paper_id='".$model->paper_name."' AND question='".$model->question."' AND id!='".$editId."' AND del_status='0'");
if (empty($record)){
$updateExambody = Questionanswerbody::model()->updateByPk($editId,array(
"exam_id"=>$model->exam_name,
"subject_id"=>$model->subject_name,
"paper_id"=>$model->paper_name,
"question"=>$model->question,
"ans1"=>$model->answer1,
"ans2"=>$model->answer2,
"ans3"=>$model->answer3,
"ans4"=>$model->answer4,
"ans5"=>$model->answer5,
"correct_ans"=>$model->correct_answer,
"modify_date"=>new CDbExpression('NOW()')
));
if($updateExambody){
Yii::app()->user->setFlash('questionbody','Question Batch Updated Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/listinganswers/'));
}
}else{
// record exists
Yii::app()->user->setFlash('error','Question Already Exists.');
$editRecord['exam_id']=$model->exam_name;
$editRecord['paper_name']=$model->question_paper_name;
$editRecord['pass_marks']=$model->marks;
}
}else{ //add
$record = Questionanswerbody::model()->find("exam_id = '".$model->exam_name."' AND subject_id='".$model->subject_name."' AND paper_id='".$model->paper_name."' AND question='".$model->question."' AND del_status='0'");
if (empty($record)){
//insert
$this->question_answer = new Questionanswerbody;
$this->question_answer->exam_id = $model->exam_name;
$this->question_answer->subject_id= $model->subject_name;
$this->question_answer->paper_id= $model->paper_name;
$this->question_answer->question = $model->question;
$this->question_answer->ans1 = $model->answer1;
$this->question_answer->ans2 = $model->answer2;
$this->question_answer->ans3 = $model->answer3;
$this->question_answer->ans4 = $model->answer4;
$this->question_answer->ans5 = $model->answer5;
$this->question_answer->correct_ans = $model->correct_answer;
$this->question_answer->post_date = new CDbExpression('NOW()');
$saved = $this->question_answer->save();
$this->lastID = Yii::app()->db->getLastInsertID();
//exit($this->lastID);
if($this->lastID){
Yii::app()->user->setFlash('questionanswer','Question Batch Added Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/listinganswers/'));
}
}else {
// record exists
Yii::app()->user->setFlash('error','Question Already Exists.');
$editRecord['exam_id']=$model->exam_name;
$editRecord['subject_id']=$model->subject_name;
$editRecord['paper_id']=$model->paper_name;
$editRecord['question']=$model->question;
$editRecord['ans1']=$model->answer1;
$editRecord['ans2']=$model->answer2;
$editRecord['ans3']=$model->answer3;
$editRecord['ans4']=$model->answer4;
$editRecord['ans5']=$model->answer5;
$model->correct_answer = $model->correct_answer;
//$editRecord['pass_marks']=$model->marks;
$get_subject =$subjects=Subjectbody::model()->findAll("exam_id=".$editRecord['exam_id']." AND status='Active' AND del_status='0'");
$subject = CHtml::listData($get_subject, 'id', 'subject');
$get_paper =Questionbody::model()->findAll("subject_id=".$editRecord['subject_id']." AND status='Active' AND del_status='0'");
$paper = CHtml::listData($get_paper, 'id', 'paper_name');
}
}
}
$editRecord['exam_id']=$model->exam_name;
$editRecord['subject_id']=$model->subject_name;
$editRecord['paper_id']=$model->paper_name;
$editRecord['question']=$model->question;
$editRecord['ans1']=$model->answer1;
$editRecord['ans2']=$model->answer2;
$editRecord['ans3']=$model->answer3;
$editRecord['ans4']=$model->answer4;
$editRecord['ans5']=$model->answer5;
$model->correct_answer = $model->correct_answer;
//$editRecord['pass_marks']=$model->marks;
$get_subject =$subjects=Subjectbody::model()->findAll("exam_id=".$editRecord['exam_id']." AND status='Active' AND del_status='0'");
$subject = CHtml::listData($get_subject, 'id', 'subject');
$get_paper =Questionbody::model()->findAll("subject_id=".$editRecord['subject_id']." AND status='Active' AND del_status='0'");
$paper = CHtml::listData($get_paper, 'id', 'paper_name');
}
$criteria=new CDbCriteria(array('order'=>'name desc'));
$criteria->compare('del_status',0);
$criteria->compare('status','Active');
$models=Exambody::model()->findAll($criteria);
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
$this->layout = 'adminmain';
$this->render('questionanswerbody',array('model'=>$model,'editRecord'=>$editRecord,'subject'=>$subject,'paper'=>$paper,'allSubjectarray'=>$allSubjectarray));
}
//end of add question along with multiple answer//
//add question answer bulk upload//
public function actionConfigurequestionbulk(){
$model=new QuestionanswerbulkForm;
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$this->pageTitle = Yii::app()->name . ' - Configure Question Batch Edit';
$this->breadcrumbs=array(
'Question Batch'=>array('webadmin/listinganswers'),
'Question Batch Edit',
);
$editRecord = Questionanswerbody::model()->findByPK($editId);
$subjects=Subjectbody::model()->findAll("exam_id=".$editRecord['exam_id']." AND status='Active' AND del_status='0'");
$allSubjectarray=CHtml::listData($subjects, 'id', 'subject');
$subject = $allSubjectarray;
$papers = Questionbody::model()->findAll("subject_id=".$editRecord['subject_id']." AND status='Active' AND del_status='0'");
$allPaperarray=CHtml::listData($papers, 'id', 'paper_name');
$paper = $allPaperarray;
$model->correct_answer = $editRecord['correct_ans'];
}else{ //add
$this->pageTitle = Yii::app()->name . ' - Configure Question Batch Add';
$this->breadcrumbs=array(
'Question Batch'=>array('webadmin/listinganswers'),
'Question Batch Add',
);
$editRecord['subject_id']='';
//$editRecord['paper_name']='';
$editRecord['paper_id']='';
//$editRecord['paper_name']='';
$editRecord['question']='';
$editRecord['exam_id']='';
$editRecord['ans1']='';
$editRecord['ans2']='';
$editRecord['ans3']='';
$editRecord['ans4']='';
$editRecord['ans5']='';
$paper=array();
//$model->correct_answer ='';
$subject = array();
}
if(isset($_POST['QuestionanswerbulkForm']))
{
$model->attributes=$_POST['QuestionanswerbulkForm'];
if($model->validate())
{
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$record = Questionanswerbody::model()->find("exam_id = '".$model->exam_name."' AND subject_id='".$model->subject_name."' AND paper_id='".$model->paper_name."' AND question='".$model->question."' AND id!='".$editId."' AND del_status='0'");
if (empty($record)){
$updateExambody = Questionanswerbody::model()->updateByPk($editId,array(
"exam_id"=>$model->exam_name,
"subject_id"=>$model->subject_name,
"paper_id"=>$model->paper_name,
"question"=>$model->question,
"ans1"=>$model->answer1,
"ans2"=>$model->answer2,
"ans3"=>$model->answer3,
"ans4"=>$model->answer4,
"ans5"=>$model->answer5,
"correct_ans"=>$model->correct_answer,
"modify_date"=>new CDbExpression('NOW()')
));
if($updateExambody){
Yii::app()->user->setFlash('questionbody','Question Batch Updated Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/listinganswers/'));
}
}else{
// record exists
Yii::app()->user->setFlash('error','Question Already Exists.');
$editRecord['exam_id']=$model->exam_name;
$editRecord['paper_name']=$model->question_paper_name;
$editRecord['pass_marks']=$model->marks;
}
}else{ //add
$qusfile = CUploadedFile::getInstancesByName('qusfile');
if(count($qusfile)>0){
foreach($qusfile as $qus)
{
$newName = md5(microtime(true)) . '_' .date('m-d-Y').'_'. str_replace("#","",$qus->name);
$res = $qus->saveAs('uploads/quescsv/' . $newName);
}
$filename = Yii::app()->params['imagebasePath'].'/quescsv/'.$newName;
$record = $this->parse_file($filename);
//print_r($record);
foreach($record as $rec){
$record = Questionanswerbody::model()->find("exam_id = '".$model->exam_name."' AND subject_id='".$model->subject_name."' AND paper_id='".$model->paper_name."' AND question='".$rec['question']."' AND del_status='0'");
if(empty($record)){
//insert
$this->question_answer = new Questionanswerbody;
$this->question_answer->exam_id = $model->exam_name;
$this->question_answer->subject_id= $model->subject_name;
$this->question_answer->paper_id= $model->paper_name;
$this->question_answer->question = $rec['question'];
$this->question_answer->ans1 = $rec['answer1'];
$this->question_answer->ans2 = $rec['answer2'];
$this->question_answer->ans3 = $rec['answer3'];
$this->question_answer->ans4 = $rec['answer4'];
$this->question_answer->ans5 = $rec['answer5'];
$this->question_answer->correct_ans = $rec['correct'];
$this->question_answer->post_date = new CDbExpression('NOW()');
$saved = $this->question_answer->save();
$this->lastID = Yii::app()->db->getLastInsertID();
//exit($this->lastID);
}
}
if($this->lastID){
Yii::app()->user->setFlash('questionanswer','Question Batch Added Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/listinganswers/'));
}
//exit;
}
}
}
}
$criteria=new CDbCriteria(array('order'=>'name desc'));
$criteria->compare('del_status',0);
$criteria->compare('status','Active');
$models=Exambody::model()->findAll($criteria);
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
$this->layout = 'adminmain';
$this->render('questionanswerbodybulk',array('model'=>$model,'editRecord'=>$editRecord,'subject'=>$subject,'paper'=>$paper,'allSubjectarray'=>$allSubjectarray));
}
//end question answer bulk upload//
//listing of question and ansqer//
public function actionListinganswers()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->pageTitle = Yii::app()->name . ' - Question Batch List';
$this->breadcrumbs = array(
'Question Batch List',
);
if(empty($_GET['page'])){
$pageNo = 1;
}else{
$pageNo = $_GET['page'];
}
$model=new QuestionanswerlistForm;
$editRecord['exam_id']='';
$editRecord['subject_id']='';
$editRecord['paper_id']='';
//$editRecord['pass_marks']='';
$subject = array();
$paper=array();
$criteria=new CDbCriteria(array('order'=>'name desc'));
$criteria->compare('del_status',0);
$models=Exambody::model()->findAll($criteria);
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
$criteria=new CDbCriteria(array('order'=>'id desc'));
$search = Yii::app()->request->getQuery('search');
if($search>0){
if(isset($_POST['QuestionanswerlistForm']) || Yii::app()->user->hasState('SearchForm'))
{
if(isset($_POST['QuestionanswerlistForm'])){
Yii::app()->user->setState('SearchForm',$_POST['QuestionanswerlistForm']);
}else{
$_POST['QuestionanswerlistForm']=Yii::app()->user->getState('SearchForm');
}
if($_POST['QuestionanswerlistForm']['exam_name']!=''){
$criteria->compare('exam_id',$_POST['QuestionanswerlistForm']['exam_name']);
$editRecord['exam_id']=$_POST['QuestionanswerlistForm']['exam_name'];
$subjects=Subjectbody::model()->findAll("exam_id=".$editRecord['exam_id']." AND del_status='0'");
$allSubjectarray2=CHtml::listData($subjects, 'id', 'subject');
$subject = $allSubjectarray2;
}
if($_POST['QuestionanswerlistForm']['subject_name']!=''){
$criteria->compare('subject_id',$_POST['QuestionanswerlistForm']['subject_name']);
$editRecord['subject_id']=$_POST['QuestionanswerlistForm']['subject_name'];
$papers = Questionbody::model()->findAll("subject_id=".$editRecord['subject_id']." AND del_status='0'");
$allPaperarray=CHtml::listData($papers, 'id', 'paper_name');
$paper = $allPaperarray;
}
if($_POST['QuestionanswerlistForm']['paper_name']!=''){
$criteria->compare('paper_id',$_POST['QuestionanswerlistForm']['paper_name']);
$editRecord['paper_id']=$_POST['QuestionanswerlistForm']['paper_name'];
}
$criteria->order = ('id desc');
}
}else{
Yii::app()->user->setState('SearchForm','');
}
$criteria->compare('del_status',0);
//create orderring//
$ordering_field = Yii::app()->request->getQuery('field');
$ordering_type = Yii::app()->request->getQuery('order');
if($ordering_field!='' && $ordering_type!=''){
$order_by = $ordering_field.' '.$ordering_type;
Yii::app()->user->setState('order_by',$order_by);
}
if(Yii::app()->user->hasState('order_by') && Yii::app()->user->getState('order_by')!=''){
$criteria->order = Yii::app()->user->getState('order_by');
}
if($search=='' && $ordering_field==''){
$criteria->order = ('id desc');
Yii::app()->user->setState('order_by','');
}
//end of ordering//
$count=Questionanswerbody::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Questionanswerbody::model()->findAll($criteria);
$criteria->compare('del_status',0);
$allQuestionsanswers = $models;
$this->layout = 'adminmain';
$this->render('questionbatchlist',array('allQuestionsanswers'=>$allQuestionsanswers,'editRecord'=>$editRecord,'pageMax' => $pages->pageSize,'subject'=>$subject,'allSubjectarray'=>$allSubjectarray,'model'=>$model,'paper'=>$paper,'pageNo' => $pageNo,'pages' => $pages));
}
//end of listing//
/**
* This is the default 'index' action that is invoked
* when an action is not explicitly requested by users.
*/
public function actionPinlist()
{
//print_r(Yii::app()->user->getState('SearchForm'));
$model=new PinForm;
$editRecord['pin_type']='';
$editRecord['userid']='';
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->pageTitle = Yii::app()->name . ' - Pin Management';
$this->breadcrumbs = array(
'Pin List',
);
if(empty($_GET['page'])){
$pageNo = 1;
}else{
$pageNo = $_GET['page'];
}
$criteria=new CDbCriteria();
$criteria2=new CDbCriteria();
$search = Yii::app()->request->getQuery('search');
if($search>0){
//$model=new PinForm;
if(isset($_POST['PinForm']) || Yii::app()->user->hasState('SearchForm'))
{
if(isset($_POST['PinForm'])){
Yii::app()->user->setState('SearchForm',$_POST['PinForm']);
}else{
$_POST['PinForm']=Yii::app()->user->getState('SearchForm');
}
if($_POST['PinForm']['pin_type']!=''){
$criteria->condition = 'pin_type LIKE :pin_type';
$criteria->params = array(':pin_type' => '%'.trim($_POST['PinForm']['pin_type']).'%');
$editRecord['pin_type']=$_POST['PinForm']['pin_type'];
}
if($_POST['PinForm']['userid']!=''){
$criteria->compare('userid',$_POST['PinForm']['userid']);
$editRecord['userid']=$_POST['PinForm']['userid'];
}
$criteria->order = 'id desc';
}
}else{
Yii::app()->user->setState('SearchForm','');
}
//create orderring//
$ordering_field = Yii::app()->request->getQuery('field');
$ordering_type = Yii::app()->request->getQuery('order');
$ordering_type_array=explode('/',$ordering_type);
$ordering_type = $ordering_type_array[0];
if($ordering_field!='' && $ordering_type!=''){
$order_by = $ordering_field.' '.$ordering_type;
Yii::app()->user->setState('order_by',$order_by);
}
if(Yii::app()->user->hasState('order_by') && Yii::app()->user->getState('order_by')!=''){
$criteria->order = Yii::app()->user->getState('order_by');
}
if($search=='' && $ordering_field==''){
$criteria->order = ('id desc');
Yii::app()->user->setState('order_by','');
}
//end of ordering//
$criteria->compare('del_status',0);
$count=Pin::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Pin::model()->findAll($criteria);
$allExambody = $models;
$this->layout = 'adminmain';
$this->render('pinlist',array('allExambody'=>$allExambody,'model'=>$model,'pageMax' => $pages->pageSize,'pageNo' => $pageNo,'pages' => $pages,'editRecord'=>$editRecord));
}
public function actionPinlistaddedit(){
$editId = Yii::app()->request->getQuery('edit');
if($editId==''){
$pinfile = CUploadedFile::getInstancesByName('pinfile');
if(count($pinfile)>0){
foreach($pinfile as $pin)
{
$newName = md5(microtime(true)) . '_' .date('m-d-Y').'_'. str_replace("#","",$pin->name);
$res = $pin->saveAs('uploads/pincsv/' . $newName);
}
$filename = Yii::app()->params['imagebasePath'].'/pincsv/'.$newName;
$record = $this->parse_file($filename);
foreach($record as $recordSingle){
$record = Pin::model()->find("pin_type = '".addslashes($recordSingle['pin_type'])."' AND userid='".$recordSingle['user_id']."' AND password='".addslashes($recordSingle['pass_code'])."' AND del_status='0' ");
if (empty($record)){
//insert
$this->pin_value = new Pin;
$this->pin_value->pin_type = addslashes($recordSingle['pin_type']);
$this->pin_value->userid = addslashes($recordSingle['user_id']);
$this->pin_value->password = addslashes($recordSingle['pass_code']);
$this->pin_value->post_date = new CDbExpression('NOW()');
$saved = $this->pin_value->save();
$this->lastID = Yii::app()->db->getLastInsertID();
$lastId = $this->pin_value->id;
//mapping if record exist//
$sql = "SELECT exam_id FROM exam_body_pin WHERE pin_type = '".addslashes($recordSingle['pin_type'])."'";
$data = Pinactivation::model()->findAllBySql($sql);
foreach($data as $dataSingle){
//pin_mapping
//mapping beging
$this->pin_mapping = new Pinactivation;
$this->pin_mapping->pin_id = $lastId;
$this->pin_mapping->exam_id = $dataSingle['exam_id'];
$this->pin_mapping->pin_type = $recordSingle['pin_type'];
$saved = $this->pin_mapping->save();
}
//enf of mapping
}
}
Yii::app()->user->setFlash('pinbody','Pin List Inserted Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/pinlist/'));
}else{
Yii::app()->user->setFlash('error','Select A file first.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/pinlist/'));
}
}
$editRecord = Pin::model()->findByPK($editId);
$model=new PinForm;
$this->pageTitle = Yii::app()->name . ' - Pin List Edit';
$this->breadcrumbs=array(
'Pin List'=>array('webadmin/pinlist'),
'Pin List Edit',
);
if(isset($_POST['PinForm'])){
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$model->attributes=$_POST['PinForm'];
if($model->validate())
{
$record = Pin::model()->find("pin_type = '".addslashes($model->pin_type)."' AND userid='".$model->userid."' AND id!='".$editId."' AND del_status='0'");
if (empty($record)){
$updateExambody = Pin::model()->updateByPk($editId,array(
"pin_type"=>$model->pin_type,
"userid"=>$model->userid,
"password"=>$model->password,
"modify_date"=>new CDbExpression('NOW()')
));
if($updateExambody){
Yii::app()->user->setFlash('pinbody','Pin List Modified Successfully.');
$this->redirect(Yii::app()->createUrl('webadmin/pinlist/'));
}
}else{
// record exists
Yii::app()->user->setFlash('error','Pin Already Exists.');
$editRecord['pin_type']=$model->pin_type;
$editRecord['userid']=$model->userid;
$editRecord['password']=$model->password;
}
}
}//else{
//
// $pinfile = CUploadedFile::getInstancesByName('pinfile');
// if(count($pinfile)>0){
// foreach($pinfile as $pin)
// {
// $newName = md5(microtime(true)) . '_' .date('m-d-Y').'_'. $pin->name;
// $res = $pin->saveAs('uploads/pincsv/' . $newName);
// }
// }
// $filename = Yii::app()->params['imagebasePath'].'/pincsv/'.$newName;
// $record = $this->parse_file($filename);
// foreach($record as $recordSingle){
// $record = Pin::model()->find("pin_type = '".$recordSingle['pin_type']."' AND userid='".$recordSingle['user_id']."' AND password='".$recordSingle['pass_code']."' AND del_status='0' ");
// if (empty($record)){
// //insert
// $this->pin_value = new Pin;
// $this->pin_value->pin_type = $recordSingle['pin_type'];
// $this->pin_value->userid = $recordSingle['user_id'];
// $this->pin_value->password = $recordSingle['pass_code'];
// $this->pin_value->post_date = new CDbExpression('NOW()');
// $saved = $this->pin_value->save();
// $this->lastID = Yii::app()->db->getLastInsertID();
// }
// }
//
// Yii::app()->user->setFlash('pinbody','Pin List Inserted Successfully.');
// //$this->refresh();
// $this->redirect(Yii::app()->createUrl('webadmin/pinlist/'));
// }
}
$this->layout = 'adminmain';
$this->render('pinlistaddedit',array('model'=>$model,'editRecord'=>$editRecord));
}
public function actionPinactivationlist()
{
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$model=new PinactivationForm;
$editRecord['exam_id']='';
$editRecord['pin_id']='';
$subject = array();
$paper=array();
$criteria=new CDbCriteria(array('order'=>'name desc'));
$criteria->compare('del_status',0);
$models=Exambody::model()->findAll($criteria);
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
$pin=Pin::model()->findAll("del_status='0'");
$pin_array=CHtml::listData($pin, 'id', 'pin_type');
$all_pin = $pin_array;
$this->pageTitle = Yii::app()->name . ' - Pin Mapping Listing';
$this->breadcrumbs = array(
'Pin Mapping List',
);
if(empty($_GET['page'])){
$pageNo = 1;
}else{
$pageNo = $_GET['page'];
}
$criteria=new CDbCriteria(array('order'=>'id desc'));
$search = Yii::app()->request->getQuery('search');
if($search>0){
if(isset($_POST['PinactivationForm']) || Yii::app()->user->hasState('SearchForm'))
{
if(isset($_POST['PinactivationForm'])){
Yii::app()->user->setState('SearchForm',$_POST['PinactivationForm']);
}else{
$_POST['PinactivationForm']=Yii::app()->user->getState('SearchForm');
}
if($_POST['PinactivationForm']['exam_id']!=''){
$criteria->compare('exam_id',$_POST['PinactivationForm']['exam_id']);
$editRecord['exam_id']=$_POST['PinactivationForm']['exam_id'];
}
if($_POST['PinactivationForm']['pin_id']!=''){
$criteria->compare('pin_id',$_POST['PinactivationForm']['pin_id']);
$editRecord['pin_id']=$_POST['PinactivationForm']['pin_id'];
}
$criteria->order = ('id desc');
}
}else{
Yii::app()->user->setState('SearchForm','');
}
$criteria->compare('del_status',0);
$criteria->compare('del_status',0);
$criteria->group='exam_id';
//$criteria->group='exam_id';
//create orderring//
$ordering_field = Yii::app()->request->getQuery('field');
$ordering_type = Yii::app()->request->getQuery('order');
if($ordering_field!='' && $ordering_type!=''){
$order_by = $ordering_field.' '.$ordering_type;
Yii::app()->user->setState('order_by',$order_by);
}
if(Yii::app()->user->hasState('order_by') && Yii::app()->user->getState('order_by')!=''){
$criteria->order = Yii::app()->user->getState('order_by');
}
if($search=='' && $ordering_field==''){
$criteria->order = ('id desc');
Yii::app()->user->setState('order_by','');
}
//end of ordering//
$count=Pinactivation::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Pinactivation::model()->findAll($criteria);
$allQuestions = $models;
$this->layout = 'adminmain';
$this->render('pinactivationlist',array('allQuestions'=>$allQuestions,'editRecord'=>$editRecord,'model'=>$model,'pageMax' => $pages->pageSize,'all_pin'=>$all_pin,'allSubjectarray'=>$allSubjectarray,'pageNo' => $pageNo,'pages' => $pages));
}
public function actionPinactivationbody()
{
$model=new PinactivationForm;
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$this->pageTitle = Yii::app()->name . ' - Pin Activation Edit';
$this->breadcrumbs=array(
'Pin Maping Listing'=>array('webadmin/pinactivationlist'),
'Pin Maping Edit',
);
$editRecord = Pinactivation::model()->findByPK($editId);
}else{ //add
$this->pageTitle = Yii::app()->name . ' - Pin Activation Add';
$this->breadcrumbs=array(
'Pin Maping Listing'=>array('webadmin/pinactivationlist'),
'Pin Maping Add',
);
$editRecord['pin_id']='';
$editRecord['exam_id']='';
$editRecord['pin_type']='';
}
if(isset($_POST['PinactivationForm']))
{
$model->attributes=$_POST['PinactivationForm'];
if($model->validate())
{
$editId = Yii::app()->request->getQuery('edit');
if($editId > 0){ //edit
$record = Pinactivation::model()->find("pin_type = '".addslashes($model->pin_id)."' AND exam_id='".$model->exam_id."' AND id!='".$editId."' AND del_status='0'");
if (empty($record)){
//update
$updatePinmapping = Pinactivation::model()->updateByPk($editId,array("exam_id"=>$model->exam_id));
//if($updatePinmapping){
Yii::app()->user->setFlash('pinactivation','Pin Activation Modified Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/pinactivationlist/'));
//}
}else{
// record exists
Yii::app()->user->setFlash('error','Record Already Exists.');
$editRecord['pin_id']=$model->pin_id;
$editRecord['exam_id']=$model->exam_id;
}
}else{ //add
$record = Pinactivation::model()->find("pin_type = '".addslashes($model->pin_id)."' AND exam_id='".$model->exam_id."' AND del_status='0'");
if (empty($record)){
$pin_details=Pin::model()->findAll(" del_status='0' AND status='Active' AND pin_type='".addslashes($model->pin_id)."'");
foreach($pin_details as $pin_details_single){
//insert
$this->pin_body = new Pinactivation;
$this->pin_body->exam_id = $model->exam_id;
$this->pin_body->pin_id = $pin_details_single['id'];
$this->pin_body->pin_type = $pin_details_single['pin_type'];
//$this->pin_body->post_date = new CDbExpression('NOW()');
$saved = $this->pin_body->save();
$this->lastID = Yii::app()->db->getLastInsertID();
}
//exit($this->lastID);
if($this->lastID){
Yii::app()->user->setFlash('pinactivation','Pin Activated Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/pinactivationlist/'));
}
}else {
// record exists
Yii::app()->user->setFlash('error','Record Already Exists.');
$editRecord['exam_id']=$model->exam_id;
$editRecord['pin_id']=$model->pin_id;
}
}
}
}
$criteria=new CDbCriteria(array('order'=>'name desc'));
$criteria->compare('del_status',0);
$models=Exambody::model()->findAll("status='Active' and del_status='0' order by name asc");
$allSubject = $models;
$allSubjectarray=CHtml::listData($allSubject, 'id', 'name');
$pin=Pin::model()->findAll(" del_status='0' AND status='Active'");
$pinarray=CHtml::listData($pin, 'pin_type', 'pin_type');
$all_pin = $pinarray;
$this->layout = 'adminmain';
$this->render('pinactivationbody',array('model'=>$model,'editRecord'=>$editRecord,'allSubjectarray'=>$allSubjectarray,'all_pin'=>$all_pin));
}
/**
* Logs out the current user and redirect to homepage.
*/
public function actionDelete(){
$criteria = new CDbCriteria;
$table = $_REQUEST['table'];
$id = $_REQUEST['id'];
if( $table=='1'){
/*$models = Exambody::model()->findAll(" id='".$id."'");
if($models[0]['logo']!=''){
unlink(Yii::app()->params['imagebasePath'].'/exambody/'.$models[0]['logo']);
}*/
Exambody::model()->updateByPk($id,array(
"del_status"=> '1'
));
//Update subject table//
$criteria->addCondition("exam_id='".$id."'");
Subjectbody::model()->updateAll(array("del_status"=> '1'), $criteria );
//Update subject table//
//Update Question paper table//
$criteria->addCondition("exam_id='".$id."'");
Questionbody::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update Question paper table//
//Update Question batch table//
$criteria->addCondition("exam_id='".$id."'");
Questionanswerbody::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update Question batch table//
//Update exam_body_pin table//
$criteria->addCondition("exam_id='".$id."'");
Pinactivation::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update exam_body_pin table//
Yii::app()->user->setFlash('exambody','Record Deleted Successfully.');
}
if($table=='2'){
Subjectbody::model()->updateByPk($id,array(
"del_status"=> '1'
));
//Update Question paper table//
$criteria->addCondition("subject_id='".$id."'");
Questionbody::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update Question paper table//
//Update Question batch table//
$criteria->addCondition("subject_id='".$id."'");
Questionanswerbody::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update Question batch table//
Yii::app()->user->setFlash('subjectbody','Record Deleted Successfully.');
}
if($table=='3'){
Questionbody::model()->updateByPk($id,array(
"del_status"=> '1'
));
//Update Question batch table//
$criteria->addCondition("paper_id='".$id."'");
Questionanswerbody::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update Question batch table//
Yii::app()->user->setFlash('questionbody','Record Deleted Successfully.');
}
if($table=='4'){
Questionanswerbody::model()->updateByPk($id,array(
"del_status"=> '1'
));
Yii::app()->user->setFlash('questionbody','Record Deleted Successfully.');
}
if($table=='5'){
Pin::model()->updateByPk($id,array(
"del_status"=> '1'
));
//Update exam_body_pin table//
$criteria->addCondition("pin_id='".$id."'");
Pinactivation::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update exam_body_pin table//
Yii::app()->user->setFlash('pinbody','Record Deleted Successfully.');
}
if($table=='6'){
Pinactivation::model()->updateByPk($id,array(
"del_status"=> '1'
));
Yii::app()->user->setFlash('pinbody','Record Deleted Successfully.');
}
echo 'success';
}
public function actionChangestatus(){
$criteria = new CDbCriteria;
$table = $_REQUEST['table'];
$id = $_REQUEST['id'];
$status = $_REQUEST['status'];
if( $table=='1'){
Exambody::model()->updateByPk($id,array(
"status"=> $status
));
//Update subject table//
$criteria->addCondition("exam_id='".$id."'");
Subjectbody::model()->updateAll(array("status"=> $status), $criteria );
//Update subject table//
//Update Question paper table//
$criteria->addCondition("exam_id='".$id."'");
Questionbody::model()->updateAll(array("status"=> $status), $criteria );
//End of Update Question paper table//
//Update Question batch table//
$criteria->addCondition("exam_id='".$id."'");
Questionanswerbody::model()->updateAll(array("status"=> $status), $criteria );
//End of Update Question batch table//
//Update exam_body_pin table//
$criteria->addCondition("exam_id='".$id."'");
Pinactivation::model()->updateAll(array("status"=> $status), $criteria );
//End of Update exam_body_pin table//
Yii::app()->user->setFlash('exambody','Status Changed Successfully.');
}
if( $table=='2'){
Subjectbody::model()->updateByPk($id,array(
"status"=> $status
));
//Update Question paper table//
$criteria->addCondition("subject_id='".$id."'");
Questionbody::model()->updateAll(array("status"=> $status), $criteria );
//End of Update Question paper table//
//Update Question batch table//
$criteria->addCondition("subject_id='".$id."'");
Questionanswerbody::model()->updateAll(array("status"=> $status), $criteria );
//End of Update Question batch table//
Yii::app()->user->setFlash('subjectbody','Status Changed Successfully.');
}
if( $table=='3'){
Questionbody::model()->updateByPk($id,array(
"status"=> $status
));
//Update Question batch table//
$criteria->addCondition("paper_id='".$id."'");
Questionanswerbody::model()->updateAll(array("status"=> $status), $criteria );
//End of Update Question batch table//
Yii::app()->user->setFlash('questionbody','Status Changed Successfully.');
}
if( $table=='4'){
Questionanswerbody::model()->updateByPk($id,array(
"status"=> $status
));
Yii::app()->user->setFlash('questionbody','Status Changed Successfully.');
}
if( $table=='5'){
Pin::model()->updateByPk($id,array(
"status"=> $status
));
//Update exam_body_pin table//
$criteria->addCondition("pin_id='".$id."'");
Pinactivation::model()->updateAll(array("status"=> $status), $criteria );
//End of Update exam_body_pin table//
Yii::app()->user->setFlash('pinbody','Status Changed Successfully.');
}
if( $table=='6'){
Pinactivation::model()->updateByPk($id,array(
"status"=> $status
));
Yii::app()->user->setFlash('pinactivation','Status Changed Successfully.');
}
if( $table=='7'){
Cmscontent::model()->updateByPk($id,array(
"seller"=> $status
));
Yii::app()->user->setFlash('cms','Status Changed Successfully.');
}
if( $table=='8'){
Contactus::model()->updateByPk($id,array(
"status"=> $status
));
Yii::app()->user->setFlash('contactus','Status Changed Successfully.');
}
echo 'success';
}
public function actionGetname(){
$id = Yii::app()->request->getQuery('id');
$t_id = Yii::app()->request->getQuery('id');
$record = Questionanswerbody::model()->find("exam_id = '".$model->exam_name."' AND subject_id='".$model->subject_name."' AND paper_id='".$model->paper_name."' AND question='".$model->question."' AND del_status='0'");
//Update subject table//
$criteria->addCondition("exam_id='".$id."'");
Subjectbody::model()->find("exam_id = '".$id."'");
//Update subject table//
//Update Question paper table//
$criteria->addCondition("exam_id='".$id."'");
Questionbody::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update Question paper table//
//Update Question batch table//
$criteria->addCondition("exam_id='".$id."'");
Questionanswerbody::model()->updateAll(array("del_status"=> '1'), $criteria );
//End of Update Question batch table//
}
public function ActionDelete_image(){
$id = $_REQUEST['id'];
$models = Exambody::model()->findAll(" id='".$id."'");
if($models[0]['logo']!=''){
unlink(Yii::app()->params['imagebasePath'].'/exambody/'.$models[0]['logo']);
Exambody::model()->updateByPk($id,array(
"logo"=> ''
));
}
echo 'success';
}
public function ActionDelete_cms_image(){
$id = $_REQUEST['id'];
$models = Cmscontent::model()->find(" id='".$id."'");
if($models['image']!=''){
unlink(Yii::app()->params['imagebasePath'].'/cmsimage/'.$models['image']);
Cmscontent::model()->updateByPk($id,array(
"image"=> ''
));
}
echo 'success';
}
/* public function actionCms()
{
$model=new CmsForm;
//echo Yii::app()->imagebasePath;
$url_field = Yii::app()->request->getQuery('page');
$this->pageTitle = Yii::app()->name . ' - About Us';
$this->breadcrumbs=array(
'About Us'=>array('webadmin/aboutus'),
'Exam Body Edit',
);
$editRecord = Cmscontent::model()->find("url = '".$url_field."'");
if(isset($_POST['CmsForm']))
{
$criteria=new CDbCriteria();
$model->attributes=$_POST['CmsForm'];
if($model->validate())
{
//echo $_REQUEST['page'];exit;
$record = Cmscontent::model()->find("url !='".$_REQUEST['page']."' AND title = '".$model->title."'");
if (empty($record)){
//Update content table//
$criteria->addCondition("url='".$_REQUEST['page']."'");
$updateContent = Cmscontent::model()->updateAll(array("title"=>$model->title,"meta_title"=>$model->meta_title,"meta_keywords"=>$model->meta_keywords,"meta_description"=>$model->meta_description,"content"=>$model->content,"seller"=>$model->seller,"modify_date"=>new CDbExpression('NOW()')), $criteria );
Yii::app()->user->setFlash('cms','Content Updated Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/cms/page/'.$_REQUEST['page']));
}else{
// record exists
Yii::app()->user->setFlash('error','Content already exist.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/cms/page/'.$_REQUEST['page']));
}
}
}
$model->seller = $editRecord['seller'];
$this->layout = 'adminmain';
$this->render('cmspage',array('model'=>$model,'editRecord'=>$editRecord));
}*/
public function actionCms()
{
$model=new CmsForm;
//echo Yii::app()->imagebasePath;
$url_field = Yii::app()->request->getQuery('page');
if($url_field!=''){
$this->pageTitle = Yii::app()->name . ' - '.$url_field.' Edit';
$this->breadcrumbs=array(
'Cms List'=>array('webadmin/cmslist'),
'Edit Cms Content',
);
}else{
$this->pageTitle = Yii::app()->name . ' - Cms Add';
$this->breadcrumbs=array(
'Cms List'=>array('webadmin/cmslist'),
'Add Cms Content',
);
}
$editRecord = Cmscontent::model()->find("url = '".$url_field."'");
if(isset($_POST['CmsForm']))
{
$criteria=new CDbCriteria();
$model->attributes=$_POST['CmsForm'];
if($model->validate())
{
if($_REQUEST['page']!=''){
//echo $_REQUEST['page'];exit;
$record = Cmscontent::model()->find("url !='".$_REQUEST['page']."' AND title = '".addslashes($model->title)."'");
if (empty($record)){
$url_nocheck = strtolower((str_replace(" ","-",$model->title)));
$url = str_replace("'","",$url_nocheck);
//add image//
$images = CUploadedFile::getInstancesByName('image');
if(count($images)>0){
foreach($images as $img)
{
$newName = md5(microtime(true)) . '_' .str_replace("#","",$img->name);
$res = $img->saveAs('uploads/cmsimage/' . $newName);
}
}else{
$newName=$_REQUEST['h_image'];
}
//Update content table//
$criteria->addCondition("url='".$_REQUEST['page']."'");
$updateContent = Cmscontent::model()->updateAll(array("title"=>$model->title,"meta_title"=>$model->meta_title,"meta_keywords"=>$model->meta_keywords,"url"=>$url,"meta_description"=>$model->meta_description,"content"=>$model->content,"image"=>$newName,"seller"=>$model->seller,"modified_date"=>new CDbExpression('NOW()')), $criteria );
//Update content table//
if($updateContent){
Yii::app()->user->setFlash('cms','Content Updated Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/cmslist'));
}
}else{
// record exists
Yii::app()->user->setFlash('error','Content Already Exists.');
$editRecord['title']=$model->title;
$editRecord['meta_title']=$model->meta_title;
$editRecord['meta_description']=$model->meta_description;
$editRecord['meta_keywords']=$model->meta_keywords;
$editRecord['content']=$model->content;
$editRecord['seller ']=$model->seller ;
}
}else{
//echo $_REQUEST['page'];exit;
$record = Cmscontent::model()->find("title = '".addslashes($model->title)."'");
if (empty($record)){
$url_nocheck = strtolower((str_replace(" ","-",$model->title)));
$url = str_replace("'","",$url_nocheck);
//add image//
$images = CUploadedFile::getInstancesByName('image');
if(count($images)>0){
foreach($images as $img)
{
$newName = md5(microtime(true)) . '_' .str_replace("#","",$img->name);
$res = $img->saveAs('uploads/cmsimage/' . $newName);
}
}else{
$newName='';
}
//insert
$this->cms_body = new Cmscontent;
$this->cms_body->title = $model->title;
$this->cms_body->url = $url;
$this->cms_body->meta_title = $model->meta_title;
$this->cms_body->meta_keywords = $model->meta_keywords;
$this->cms_body->meta_description = $model->meta_description;
$this->cms_body->content = $model->content;
$this->cms_body->image = $newName;
$this->cms_body->seller = $model->seller;
$this->cms_body->modified_date = new CDbExpression('NOW()');
$saved = $this->cms_body->save();
$this->lastID = Yii::app()->db->getLastInsertID();
//exit($this->lastID);
if($this->lastID){
Yii::app()->user->setFlash('cms','Content Added Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/cmslist/'));
}
}else{
// record exists
Yii::app()->user->setFlash('error','Exam Body Already Exists.');
$editRecord['title']=$model->title;
$editRecord['meta_title']=$model->meta_title;
$editRecord['meta_description']=$model->meta_description;
$editRecord['meta_keywords']=$model->meta_keywords;
$editRecord['content']=$model->content;
$editRecord['seller']=$model->seller;
$editRecord['image']='';
}
}
}
}
$this->layout = 'adminmain';
$this->render('cmspage',array('model'=>$model,'editRecord'=>$editRecord));
}
public function actionCmslist()
{
$this->pageTitle = Yii::app()->name . ' - Cms Content';
$this->breadcrumbs = array(
'Cms Contents',
);
$model=new CmsForm;
if(empty($_GET['page'])){
$pageNo = 1;
}else{
$pageNo = $_GET['page'];
}
$criteria=new CDbCriteria();
//create orderring//
$ordering_field = Yii::app()->request->getQuery('field');
$ordering_type = Yii::app()->request->getQuery('order');
$ordering_type_array=explode('/',$ordering_type);
//echo $ordering_type = $ordering_type_array[0];
if($ordering_field!='' && $ordering_type!=''){
$order_by = $ordering_field.' '.$ordering_type;
Yii::app()->user->setState('order_by',$order_by);
}
if(Yii::app()->user->hasState('order_by') && Yii::app()->user->getState('order_by')!=''){
$criteria->order = Yii::app()->user->getState('order_by');
}
if($ordering_field==''){
$criteria->order = ('id desc');
Yii::app()->user->setState('order_by','');
}
//end of ordering//
$count=Cmscontent::model()->count($criteria);
$pages=new CPagination($count);
// results per page
$pages->pageSize=10;
$pages->applyLimit($criteria);
$models=Cmscontent::model()->findAll($criteria);
$allContent = $models;
$this->layout = 'adminmain';
$this->render('cmslist',array('allContent'=>$allContent,'model'=>$model,'pageMax' => $pages->pageSize,'pageNo' => $pageNo,'pages' => $pages));
}
public function actionGlobalconfig()
{
$model=new GlobalconfigForm;
//echo Yii::app()->imagebasePath;
$this->pageTitle = Yii::app()->name . ' - Exam Body Edit';
$this->breadcrumbs=array(
'Global Configaration'
);
$editRecord = Globalconfig::model()->findAll();
$key = 0;
$data_content=array();
foreach($editRecord as $data_content_new){
$data_content[$key]['id']=$data_content_new['id'];
$data_content[$key]['field_name']=$data_content_new['field_name'];
$data_content[$key][str_replace("global_","",$data_content_new['field_key'])]=$data_content_new['field_value'];
$data_content[$key]['field_key']=str_replace("global_","",$data_content_new['field_key']);
$key++;
}
if(isset($_POST['GlobalconfigForm']))
{
$model->attributes=$_POST['GlobalconfigForm'];
if($model->validate())
{
//update
foreach($model as $key=>$value){
$criteria=new CDbCriteria();
$fldNmae = 'global_'.$key;
$criteria->addCondition("field_key='".$fldNmae."'");
$updateGlobalconfig = Globalconfig::model()->updateAll(array("field_value"=> $value), $criteria );
}
Yii::app()->user->setFlash('globalconfig','Configuration Updated Successfully.');
$this->redirect(Yii::app()->createUrl('webadmin/globalconfig/'));
}
}
$this->layout = 'adminmain';
$this->render('globalconfig',array('model'=>$model,'data_content'=>$data_content));
}
public function actionChangepassword()
{
$isAdmin = Yii::app()->user->getState("isAdmin");
$model=new ChangepasswordForm;
//echo Yii::app()->imagebasePath;
$this->pageTitle = Yii::app()->name . ' - Change Password';
$this->breadcrumbs=array(
'Change Password',
);
//$editRecord = Admin::model()->find("password = '".addslashes($model->confirm_password)."' AND id='".$isAdmin."'");
if(isset($_POST['ChangepasswordForm']))
{
$criteria=new CDbCriteria();
$model->attributes=$_POST['ChangepasswordForm'];
if($model->validate())
{
$record = Admin::model()->find("password = '".md5($model->old_password)."' AND id='".$isAdmin."'");
if (!empty($record)){
$criteria->addCondition("id='".$isAdmin."'");
$updateContent = Admin::model()->updateAll(array("password"=>md5($model->confirm_password)), $criteria );
//Update content table//
Yii::app()->user->setFlash('changepassword','Password Changed Successfully.');
//$this->refresh();
$this->redirect(Yii::app()->createUrl('webadmin/changepassword'));
}else{
// not match
Yii::app()->user->setFlash('error','Wrong username or password.');
$this->redirect(Yii::app()->createUrl('webadmin/changepassword'));
}
}
}
$this->layout = 'adminmain';
$this->render('changepassword',array('model'=>$model));
}
public function actionContactusdetails()
{
$this->pageTitle = Yii::app()->name . ' - Contact Us';
$this->breadcrumbs = array(
'Contact Us Details',
);
$editRecord = Contactus::model()->findAll();
$this->layout = 'adminmain';
$this->render('contactusdetails',array('editRecord'=>$editRecord));
}
public function actionContactus()
{
$this->pageTitle = Yii::app()->name . ' - Contact Us Edit';
$this->breadcrumbs=array(
'Contact Us Details'=>array('webadmin/contactusdetails'),
'Contact Us Edit',
);
$model=new contactusForm;
$editRecord = Contactus::model()->find();
if(isset($_POST['contactusForm']))
{
$criteria=new CDbCriteria();
$model->attributes=$_POST['contactusForm'];
if($model->validate())
{
$updateContent = Contactus::model()->updateAll(array("email"=>$model->email,"phone"=>$model->phone,"address"=>$model->address,"googlemap"=>$model->googlemapcode));
Yii::app()->user->setFlash('contactus','Details save Successfully.');
$this->redirect(Yii::app()->createUrl('webadmin/contactusdetails'));
}
}
$this->layout = 'adminmain';
$this->render('contactus',array('model'=>$model,'editRecord'=>$editRecord));
}
public function actionLogout()
{
Yii::app()->user->logout();
$this->redirect(Yii::app()->user->returnUrl.'webadmin/');
}
}
Directory Contents
Dirs: 0 × Files: 3