Advertisement
Guest User

controller

a guest
Apr 7th, 2017
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 35.43 KB | None | 0 0
  1. <?php
  2. Yii::import('application.extensions.BootstrapLinkPager');
  3. Yii::import('application.extensions.EExcelView');
  4. class AdmissionScheduleController extends Controller
  5. {
  6.     /**
  7.      * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
  8.      * using two-column layout. See 'protected/views/layouts/column2.php'.
  9.      */
  10.     public $layout='//layouts/main';
  11.  
  12.     /**
  13.      * @return array action filters
  14.      */
  15.     public function filters()
  16.     {
  17.         return array(
  18.             'accessControl', // perform access control for CRUD operations
  19.             'postOnly + delete', // we only allow deletion via POST request
  20.         );
  21.     }
  22.  
  23.     /**
  24.      * Specifies the access control rules.
  25.      * This method is used by the 'accessControl' filter.
  26.      * @return array access control rules
  27.      */
  28.     public function accessRules()
  29.     {
  30.         return array(
  31.             array('allow',  // allow all users to perform 'index' and 'view' actions
  32.                 'actions'=>array('index','view','create','update','admin','delete','processyettoprocess','processcreate','processhold','processresch','reject','processreject','enrollall','schyettoprocess','schrejected','processrejected','enrollrejected','enrollreject','exportprocessexcel','exportscheduleexcel','exportenrollexcel','createsms','postdata','processcreatesms','processrejectsms','processholdsms','smsall','processreschsms','enrollrejectsms','enrollcreate'),
  33.                 'users'=>array('*'),
  34.             ),
  35.             array('deny',  // deny all users
  36.                 'users'=>array('*'),
  37.             ),
  38.         );
  39.     }
  40.  
  41.    
  42.  
  43.     /**
  44.      * Displays a particular model.
  45.      * @param integer $id the ID of the model to be displayed
  46.      */
  47.     public function actionView($id)
  48.     {
  49.         $this->render('form_view',array(
  50.             'model'=>$this->loadModel($id),
  51.         ));
  52.     }
  53.  
  54.     /**
  55.      * Creates a new model.
  56.      * If creation is successful, the browser will be redirected to the 'view' page.
  57.      */
  58.  
  59.     public function actionEnrollAll()
  60.     {
  61.         $model=new AdmissionForm('search');
  62.         $sch_model=new AdmissionSchedule;
  63.        
  64.         $model->unsetAttributes();
  65.         if(isset($_GET['AdmissionForm']))
  66.             $model->attributes=$_GET['AdmissionForm'];
  67.         if(isset($_GET['pageSize'])) {
  68.             Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
  69.             unset($_GET['pageSize']);
  70.         }
  71.         $this->render('enrollall',array(
  72.             'model'=>$model,'sch_model'=>$sch_model,));
  73.     }
  74.  
  75.     public function actionEnrollRejected()
  76.     {
  77.         $model=new AdmissionForm('search');
  78.         $sch_model=new AdmissionSchedule;
  79.         $model->unsetAttributes();
  80.         if(isset($_GET['AdmissionForm']))
  81.             $model->attributes=$_GET['AdmissionForm'];
  82.         if(isset($_GET['pageSize'])) {
  83.             Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
  84.             unset($_GET['pageSize']);
  85.         }
  86.         $this->render('enrollrejected',array(
  87.             'model'=>$model,'sch_model'=>$sch_model));
  88.     }
  89.  
  90.     //dev by ram starts
  91.     public function actionEnrollCreate()
  92.     {
  93.         $currentbatch=Yii::app()->session['currentbatch'];
  94.         $batch_year=substr($currentbatch,-2);
  95.         $batch_model=BatchTable::model()->findAll(array("condition"=>"batch_code='".$currentbatch."'"));
  96.         if(count($batch_model) > 0)
  97.             $batch=$batch_model[0]->batch_id;
  98.         else
  99.             $batch=1;
  100.            
  101.         $sel_students=explode(",",$_POST['selected_val']) ;
  102.         $unique_stud=array_unique($sel_students);
  103.         foreach ($unique_stud as $stud) {
  104.             //admission block code 
  105.             $stu_detail=AdmissionForm::model()->findByPk($stud);
  106.             $schedule_model=AdmissionSchedule::model()->find('admn_form_id='.$stud);
  107.             //$schedule_model->comment = $_POST['comment'];
  108.             $schedule_model->enroll_status =1;
  109.             $stu_detail->admission_status = 'Selected';
  110.             $schedule_model->save();
  111.             $stu_detail->save();
  112.  
  113.             //student table code block
  114.             if($stu_detail->gender == 'M')
  115.                 $gender=1;
  116.             else if($stu_detail->gender == 'F')
  117.                 $gender=2;
  118.             else
  119.                 $gender=3;
  120.             if($stu_detail->admission_no == "")
  121.                 $stu_detail->admission_no=NULL;
  122.             $stu_model=new StudentTable;
  123.             $stu_model->admission_id=$stu_detail->admission_no;
  124.             $stu_model->first_name=$stu_detail->first_name;
  125.             $stu_model->last_name=$stu_detail->last_name;
  126.             $stu_model->gender=$gender;
  127.             $stu_model->dob=$stu_detail->date_of_birth;
  128.             $stu_model->joining_quota=$stu_detail->quota_id;
  129.             $stu_model->emis_number=$stu_detail->emis_no;
  130.             $stu_model->class=$stu_detail->class_id;
  131.             $stu_model->first_language=$stu_detail->first_lang_id;
  132.             $stu_model->second_language=$stu_detail->sec_lang_id;
  133.             $stu_model->profile_image=$stu_detail->profile_image;
  134.             $stu_model->religion=$stu_detail->religion_id;
  135.             $stu_model->bloodgroup=$stu_detail->bg_id;
  136.             $stu_model->caste=$stu_detail->caste_id;
  137.             $stu_model->mothertongue=$stu_detail->mother_tongue;
  138.             $stu_model->nationality=$stu_detail->nationality_id;
  139.             $stu_model->previous_school=$stu_detail->previous_school_name;
  140.             $stu_model->reason_gap=$stu_detail->reason_gap;
  141.             $stu_model->reason_change=$stu_detail->reason_change;
  142.             $stu_model->prev_course=$stu_detail->last_class;
  143.             $stu_model->prev_mark=$stu_detail->last_class_percentage;
  144.             $stu_model->aadhar_card=$stu_detail->aadhar_number;
  145.             $stu_model->physicallychallenged='N';
  146.             $stu_model->disability_detail='NA';
  147.             $stu_model->batch=$batch;
  148.             $stu_model->class=$stu_detail->class_id;
  149.            
  150.             $student_records = StudentTable::model()->findAll(array("select"=>"MAX(SUBSTR(student_id, -4)) as student_number","condition"=>"student_id like '%".$batch_year."S%'","order"=>"student_number"));         
  151.             if(count($student_records) == 0) {
  152.                 $student_id=Yii::app()->session['schoolid'].$batch_year."S0001";
  153.             }
  154.             else {
  155.                 $last_student_id=$student_records[0]->student_number;
  156.                 if($last_student_id==""){
  157.                     $student_id=Yii::app()->session['schoolid'].$batch_year."S0001";
  158.                 }else{
  159.                     $current_student_id=(int)$last_student_id+1;
  160.                     $current_student_id=str_pad($current_student_id, 4, '0', STR_PAD_LEFT);
  161.                     $student_id=Yii::app()->session['schoolid'].$batch_year."S".$current_student_id;
  162.                 }
  163.             }
  164.            
  165.             $stu_model->student_id=$student_id;
  166.             $stu_model->created_by=1;
  167.             $stu_model->lastedited_by=1;
  168.             $stu_model->save(false);
  169.            
  170.             $stud_primary_id=$stu_model->student_table_id;//last inserted student table id
  171.    
  172.             //parent table insertion code block  
  173.             $parent_model=new ParentTable;
  174.             $parent_records = ParentTable::model()->findAll(array("select"=>"MAX(SUBSTR(parent_id, -4)) as parent_number","condition"=>"parent_id like '%".$batch_year."P%'","order"=>"parent_number"));           
  175.             if(count($parent_records) == 0) {
  176.                 $parent_id=Yii::app()->session['schoolid'].$batch_year."P0001";
  177.             }
  178.             else {
  179.                 $last_parent_id=$parent_records[0]->parent_number;
  180.                 if($last_parent_id==""){
  181.                     $parent_id=Yii::app()->session['schoolid'].$batch_year."P0001";
  182.                 }else{
  183.                     $current_parent_id=(int)$last_parent_id+1;
  184.                     $current_parent_id=str_pad($current_parent_id, 4, '0', STR_PAD_LEFT);
  185.                     $parent_id=Yii::app()->session['schoolid'].$batch_year."P".$current_parent_id;
  186.                 }
  187.             }
  188.            
  189.             $parent_model->parent_id=$parent_id;
  190.             $parent_model->parent_name=$stu_detail->father_name;
  191.             $parent_model->parent_name2=$stu_detail->mother_name;
  192.             $parent_model->guardian_name=$stu_detail->guardian_name;
  193.             $parent_model->parent_occupation=$stu_detail->occupation;
  194.             $parent_model->annual_income=$stu_detail->annual_income;
  195.             $parent_model->gender=1;
  196.             $parent_model->gender2=2;
  197.             $parent_model->mobile_no=$stu_detail->mobile_no;
  198.             $parent_model->guardian_mobile=$stu_detail->guardian_mobile_no;
  199.             $parent_model->email_id=$stu_detail->email_id;
  200.             $parent_model->altemail_id=$stu_detail->email_id_alt;
  201.             $parent_model->guardian_email=$stu_detail->guardian_email;
  202.             $parent_model->created_by=1;
  203.             $parent_model->lastedited_by=1;
  204.             $parent_model->created_on=date('Y-m-d H:i:s');
  205.             $parent_model->lastedited_on=date('Y-m-d H:i:s');
  206.             $parent_model->save();
  207.             $parent_primary_id=$parent_model->parent_table_id; //for fetch last inserted primary id of parent table
  208.            
  209.             //student Parent Table
  210.             $par_stud_model=new ParentStudentTable;
  211.             $par_stud_model->parent_id=$parent_id;
  212.             $par_stud_model->student_id=$student_id;
  213.             $par_stud_model->save();
  214.        
  215.             //student relation Table
  216.             $stu_relation_model=new StudentRelation;
  217.             $stu_relation_model->parent=$parent_primary_id;
  218.             $stu_relation_model->student=$stud_primary_id;
  219.             $stu_relation_model->save();
  220.            
  221.             $login_model=new LoginTable;
  222.             $login_model->userid=$stu_model->student_id;
  223.             $login_model->password=sha1(strToLower($stu_model->student_id));
  224.             $login_model->mailid=$stu_model->email_id;
  225.             $login_model->mobile_no=$stu_model->mobile_no;
  226.             $login_model->access_id='4';
  227.             $login_model->status='1';
  228.             $login_model->save(false);
  229.            
  230.             $login_model=new LoginTable;
  231.             $login_model->userid=$parent_model->parent_id;
  232.             $login_model->mailid=$parent_model->email_id;
  233.             $login_model->mobile_no=$parent_model->mobile_no;
  234.             $login_model->password=sha1(strToLower($parent_model->parent_id));
  235.             $login_model->access_id='3';
  236.             $login_model->status='1';
  237.             $login_model->save(false);
  238.            
  239.             $login_user=new UserLogin;
  240.             $login_user->school_id=Yii::app()->session['school_registration_id'];
  241.             $login_user->user_id=$stu_model->student_id;
  242.             $login_user->user_email_id=$stu_model->email_id;
  243.             $login_user->user_mobile_no=$stu_model->mobile_no;
  244.             $login_user->user_password=sha1(strToLower($stu_model->student_id));
  245.             $login_user->role_id=4;
  246.             $login_user->lock_count=3;
  247.             $login_user->is_locked=0;
  248.             $login_user->verif_gen_date=date('Y-m-d');
  249.             $cur_date=date('H:i:s');
  250.             $currentDate = strtotime($cur_date);
  251.             $futureDate = $currentDate+(60*60*48);
  252.             $login_user->verif_exp_min=date('H:i:s',$futureDate);
  253.             $login_user->save(false);
  254.            
  255.             $login_user=new UserLogin;
  256.             $login_user->school_id=Yii::app()->session['school_registration_id'];
  257.             $login_user->user_id=$parent_model->parent_id;
  258.             $login_user->user_email_id=$parent_model->email_id;
  259.             $login_user->user_mobile_no=$parent_model->mobile_no;
  260.             $login_user->user_password=sha1(strToLower($parent_model->parent_id));
  261.             $login_user->role_id=3;
  262.             $login_user->lock_count=3;
  263.             $login_user->is_locked=0;
  264.             $login_user->verif_gen_date=date('Y-m-d');
  265.             $cur_date=date('H:i:s');
  266.             $currentDate = strtotime($cur_date);
  267.             $futureDate = $currentDate+(60*15);
  268.             $login_user->verif_exp_min=date('H:i:s',$futureDate);
  269.             $login_user->save(false);
  270.         }
  271.         $contact=$users=$com=array();
  272.         $h=0;
  273.         $sel_val = explode(',',$_POST['selected_val']);
  274.         foreach($sel_val as $val){
  275.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  276.             $comment = $_POST['comment'];
  277.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  278.             $school_name=Yii::app()->session['school_name'];
  279.             $comment2=str_replace("*school_name*",$school_name,$comment1);
  280.             $comment3=str_replace("*message*",$_POST['add_comment'],$comment2);
  281.             $model->comment = $comment3;
  282.             $form_model = AdmissionForm::model()->findByPk($val);
  283.             $contact[$h]=$form_model->mobile_no;
  284.             $users[$h]=$form_model->admn_form_id;
  285.             $com[$h]=$comment3;
  286.             $model->save();
  287.             $form_model->save();
  288.             $h++;
  289.         }
  290.         $this->actionSmsall($contact,$com,$users);
  291.         echo CJSON::encode("success");
  292.     }
  293.     //dev by ram ends
  294.  
  295.  
  296.     public function actionEnrollReject()
  297.     {
  298.         $sel_val = explode(',',$_POST['selected_val']);
  299.         foreach($sel_val as $val){
  300.             $form_model = AdmissionForm::model()->find('admn_form_id='.$val);
  301.             $schedule_model = AdmissionSchedule::model()->find('admn_form_id='.$val);
  302.             $schedule_model->comment = $_POST['comment'];
  303.             //Here i have maintained enroll stauts 1 =>selected and 0 =>rejected
  304.             $schedule_model->enroll_status =0;
  305.             $form_model->admission_status = 'Rejected';
  306.             $schedule_model->save();
  307.             $form_model->save();
  308.             echo CJSON::encode("success");
  309.         }
  310.     }
  311.    
  312.     public function actionEnrollrejectsms()
  313.     {
  314.         //print_r($_POST);exit;
  315.         $contact=$users=$com=array();
  316.         $h=0;
  317.         $sel_val = explode(',',$_POST['id']);
  318.         foreach($sel_val as $val){
  319.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  320.             $comment = $_POST['comment'];
  321.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  322.             $school_name=Yii::app()->session['school_name'];
  323.             $comment2=str_replace("*school_name*",$school_name,$comment1);
  324.             $comment3=str_replace("*message*",$_POST['add_comment'],$comment2);
  325.             $model->comment = $comment3;
  326.             $model->enroll_status =0;
  327.             $form_model = AdmissionForm::model()->findByPk($val);
  328.             $form_model->admission_status = 'Rejected';
  329.             $contact[$h]=$form_model->mobile_no;
  330.             $users[$h]=$form_model->admn_form_id;
  331.             $com[$h]=$comment3;
  332.             $model->save();
  333.             $form_model->save();
  334.             $h++;
  335.         }
  336.         $this->actionSmsall($contact,$com,$users);
  337.         echo CJSON::encode("success");
  338.     }
  339.  
  340.     public function actionExportEnrollExcel($id) {
  341.         $data=Yii::app()->session['admissionexcel'];
  342.         //print_r(Yii::app()->session['studentexcel']);
  343.         if(empty(Yii::app()->session['admissionexcel'])){
  344.             $data= new CActiveDataProvider('AdmissionForm');
  345.         }
  346.         if($id == 1){
  347.             $fileName = "admission_enroll_";
  348.         }
  349.         else {
  350.             $fileName = "enroll_rejected_";
  351.         }
  352.         $cur_time=date("Ymd_his");
  353.         $this->widget('EExcelView', array(
  354.             'dataProvider'=>  $data,
  355.             'grid_mode'=>'export',
  356.             'title'=>'Title',
  357.             'filename'=>$fileName.$cur_time,
  358.             'stream'=>true,
  359.             'exportType'=>'Excel2007',
  360.             'columns'=>array(
  361.                 array(//'name'=>'application_number',
  362.                     'value'=>'$data->application_number',
  363.                     'header'=>'Application No',
  364.                 ),
  365.                 array(//'name'=>'first_name',
  366.                     'value'=>'$data->first_name." ".$data->last_name',
  367.                     'header'=>'Student Name',
  368.                 ),
  369.                 array(//'name'=>'father_name',
  370.                     'header'=>'Parent Name',
  371.                     'value'=>'$data->father_name',
  372.                 ),
  373.                 array(//'name'=>'mobile_no',
  374.                     'header'=>'Mobile',
  375.                     'value'=>'$data->mobile_no',
  376.                 ),
  377.                 array(//'name'=>'class_id',
  378.                     'value'=>'$data->class->class_name',
  379.                     'header'=>'Class',
  380.                 ),
  381.                 array(//'name'=>'course',
  382.                     'value'=>'$data->course->course_name',
  383.                     'header'=>'Group',
  384.                 ),
  385.                 array(//'name'=>'application_fee',
  386.                     'value'=>'$data->application_fee==NULL?0:$data->application_fee',
  387.                     'type'=>'raw',
  388.                     'header'=>'Application Fee Paid',
  389.                 ),
  390.                 array(//'name'=>'quota',
  391.                     'value'=>'$data->quota->quota_name',
  392.                     'header'=>'Quota',
  393.                 ),
  394.                 array(//'name'=>'admission_fee',
  395.                     'value'=>'$data->admission_fee==NULL?0:$data->admission_fee',
  396.                     'type'=>'raw',
  397.                     'header'=>'Admission Fee Paid',
  398.                 ),             
  399.             ),
  400.         ));
  401.         Yii::app()->end();
  402.     }
  403.  
  404.     public function actionCreate()
  405.     {
  406.         // Uncomment the following line if AJAX validation is needed
  407.         // $this->performAjaxValidation($model);
  408.         $sel_val = explode(',',$_POST['selected_val']);
  409.         foreach($sel_val as $val){
  410.             $model = new AdmissionSchedule;
  411.             $model->admn_form_id = $val;
  412.             $when=$_POST['int_date'];
  413.             $when_date=date("d-m-Y",strtotime($when));
  414.             $when_time=date("H:i A",strtotime($when));
  415.             $model->interview_date = date("Y-m-d H:i:s",strtotime($when));
  416.             $model->interview_venue = $_POST['int_venue'];
  417.             $comment = $_POST['comment'];
  418.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  419.             $comment2=str_replace("*interview_date*",$when_date,$comment1);
  420.             $comment3=str_replace("*start_time*",$when_time,$comment2);
  421.             $comment4=str_replace("*venue*",$_POST['int_venue'],$comment3);
  422.             $comment5=str_replace("*message*",$_POST['add_comment'],$comment4);
  423.             $model->comment = $comment5;
  424.             $model->interview_status = 'YetToProcess';
  425.             $form_model = AdmissionForm::model()->findByPk($val);
  426.             $form_model->application_status = 'Selected';
  427.             $model->save();
  428.             $form_model->save();
  429.             echo CJSON::encode("success");
  430.         }
  431.  
  432.     }
  433.     public function actionCreatesms()
  434.     {
  435.         $contact=$users=$com=array();
  436.         $h=0;
  437.         $sel_val = explode(',',$_POST['id']);
  438.         foreach($sel_val as $val){
  439.             $model = new AdmissionSchedule;
  440.             $model->admn_form_id = $val;
  441.             $when=$_POST['int_date'];
  442.             $when_date=date("d-m-Y",strtotime($when));
  443.             $when_time=date("H:i A",strtotime($when));
  444.             $model->interview_date = date("Y-m-d H:i:s",strtotime($when));
  445.             $model->interview_venue = $_POST['int_venue'];
  446.             $comment = $_POST['comment'];
  447.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  448.             $comment2=str_replace("*interview_date*",$when_date,$comment1);
  449.             $comment3=str_replace("*start_time*",$when_time,$comment2);
  450.             $comment4=str_replace("*venue*",$_POST['int_venue'],$comment3);
  451.             $comment5=str_replace("*message*",$_POST['add_comment'],$comment4);
  452.             $model->comment = $comment5;
  453.             $model->interview_status = 'YetToProcess';
  454.             $form_model = AdmissionForm::model()->findByPk($val);
  455.             $form_model->application_status = 'Selected';
  456.             $contact[$h]=$form_model->mobile_no;
  457.             $users[$h]=$form_model->admn_form_id;
  458.             $com[$h]=$comment5;
  459.             $model->save();
  460.             $form_model->save();
  461.             $h++;
  462.         }
  463.         $this->actionSmsall($contact,$com,$users);
  464.         echo CJSON::encode("success");
  465.     }
  466.  
  467.  
  468.     public function actionReject()
  469.     {
  470.         // Uncomment the following line if AJAX validation is needed
  471.         // $this->performAjaxValidation($model);
  472.         $sel_val = explode(',',$_POST['selected_val']);
  473.         foreach($sel_val as $val){
  474.             $form_model = AdmissionForm::model()->findByPk($val);
  475.             $form_model->application_status = 'Rejected';
  476.             $form_model->save();
  477.             echo CJSON::encode("success");
  478.         }
  479.  
  480.     }
  481.  
  482.     /**
  483.      * Updates a particular model.
  484.      * If update is successful, the browser will be redirected to the 'view' page.
  485.      * @param integer $id the ID of the model to be updated
  486.      */
  487.     public function actionUpdate($id)
  488.     {
  489.         $model=$this->loadModel($id);
  490.  
  491.         // Uncomment the following line if AJAX validation is needed
  492.         // $this->performAjaxValidation($model);
  493.  
  494.         if(isset($_POST['AdmissionSchedule']))
  495.         {
  496.             $model->attributes=$_POST['AdmissionSchedule'];
  497.             if($model->save())
  498.                 $this->redirect(array('view','id'=>$model->schedule_id));
  499.         }
  500.  
  501.         $this->render('update',array(
  502.             'model'=>$model,
  503.         ));
  504.     }
  505.  
  506.     /**
  507.      * Deletes a particular model.
  508.      * If deletion is successful, the browser will be redirected to the 'admin' page.
  509.      * @param integer $id the ID of the model to be deleted
  510.      */
  511.     public function actionDelete($id)
  512.     {
  513.         $this->loadModel($id)->delete();
  514.  
  515.         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
  516.         if(!isset($_GET['ajax']))
  517.             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
  518.     }
  519.  
  520.     /**
  521.      * Lists all models.
  522.      */
  523.     public function actionIndex()
  524.     {
  525.         $dataProvider=new CActiveDataProvider('AdmissionSchedule');
  526.         $this->render('index',array(
  527.             'dataProvider'=>$dataProvider,
  528.         ));
  529.     }
  530.  
  531.     /**
  532.      * Manages all models.
  533.      */
  534.     public function actionAdmin()
  535.     {
  536.         $model=new AdmissionForm('search');
  537.         $sch_model = new AdmissionSchedule;
  538.         $model->unsetAttributes();  // clear any default values
  539.         if(isset($_GET['AdmissionForm']))
  540.             $model->attributes=$_GET['AdmissionForm'];
  541.  
  542.         $this->render('admin',array(
  543.             'model'=>$model, 'sch_model'=>$sch_model,              
  544.         ));
  545.     }
  546.  
  547.     public function actionSchYetToProcess()
  548.     {
  549.         $model=new AdmissionForm('search');
  550.         $sch_model = new AdmissionSchedule;
  551.         $model->unsetAttributes();  // clear any default values
  552.         if(isset($_GET['AdmissionForm']))
  553.             $model->attributes=$_GET['AdmissionForm'];
  554.         if(isset($_GET['pageSize'])) {
  555.             Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
  556.             unset($_GET['pageSize']);
  557.         }
  558.        
  559.         $this->render('schyettoprocess',array(
  560.             'model'=>$model, 'sch_model'=>$sch_model,          
  561.         ));
  562.     }
  563.  
  564.     public function actionExportScheduleExcel($id) {
  565.         $data=Yii::app()->session['admissionexcel'];
  566.         //print_r(Yii::app()->session['studentexcel']);
  567.         if(empty(Yii::app()->session['admissionexcel'])){
  568.             $data= new CActiveDataProvider('AdmissionForm');
  569.         }
  570.         if($id == 1){
  571.             $fileName = "admission_schedule_";
  572.         }
  573.         else {
  574.             $fileName = "schedule_rejected_";
  575.         }
  576.         $cur_time=date("Ymd_his");
  577.         $this->widget('EExcelView', array(
  578.             'dataProvider'=>  $data,
  579.             'grid_mode'=>'export',
  580.             'title'=>'Title',
  581.             'filename'=>$fileName.$cur_time,
  582.             'stream'=>true,
  583.             'exportType'=>'Excel2007',
  584.             'columns'=>array(
  585.                 array(//'name'=>'application_number',
  586.                     'value'=>'$data->application_number',
  587.                     'header'=>'Application No',
  588.                 ),
  589.                 array(//'name'=>'first_name',
  590.                     'value'=>'$data->first_name." ".$data->last_name',
  591.                     'header'=>'Student Name',
  592.                 ),
  593.                 array(//'name'=>'father_name',
  594.                     'header'=>'Parent Name',
  595.                     'value'=>'$data->father_name',
  596.                 ),
  597.                 array(//'name'=>'mobile_no',
  598.                     'header'=>'Mobile',
  599.                     'value'=>'$data->mobile_no',
  600.                 ),
  601.                 array(//'name'=>'class_id',
  602.                     'value'=>'$data->class->class_name',
  603.                     'header'=>'Class',
  604.                 ),
  605.                 array(//'name'=>'course',
  606.                     'value'=>'$data->course->course_name',
  607.                     'header'=>'Course',
  608.                 ),
  609.                 array(//'name'=>'caste',
  610.                     'value'=>'$data->quota->quota_name',
  611.                     'header'=>'Quota',
  612.                 ),
  613.                 array(//'name'=>'admission_status',
  614.                     'header'=>'Application Status',
  615.                     'value'=>'$data->application_status',
  616.                 ),             
  617.             ),
  618.         ));
  619.         Yii::app()->end();
  620.     }
  621.  
  622.     public function actionSchRejected()
  623.     {
  624.         $model=new AdmissionForm('search');
  625.         $sch_model = new AdmissionSchedule;
  626.         $model->unsetAttributes();  // clear any default values
  627.         if(isset($_GET['AdmissionForm']))
  628.             $model->attributes=$_GET['AdmissionForm'];
  629.         if(isset($_GET['pageSize'])) {
  630.             Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
  631.             unset($_GET['pageSize']);
  632.         }
  633.         $this->render('schrejected',array(
  634.             'model'=>$model, 'sch_model'=>$sch_model,            
  635.         ));
  636.     }
  637.  
  638.     public function actionProcessYetToProcess()
  639.     {
  640.         $model=new AdmissionSchedule('search');
  641.         //$form_model=new AdmissionForm;
  642.         $sch_model = new AdmissionSchedule;
  643.         $model->unsetAttributes();
  644.         if(isset($_GET['AdmissionSchedule']))
  645.             $model->attributes=$_GET['AdmissionSchedule'];
  646.         if(isset($_GET['pageSize'])) {
  647.             Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
  648.             unset($_GET['pageSize']);
  649.         }
  650.         $this->render('processyettoprocess',array(
  651.             'model'=>$model,'sch_model'=>$sch_model));
  652.     }
  653.  
  654.     public function actionProcessRejected()
  655.     {
  656.         $model=new AdmissionSchedule('search');
  657.         //$form_model=new AdmissionForm;
  658.         $sch_model = new AdmissionSchedule;
  659.         $model->unsetAttributes();
  660.         if(isset($_GET['AdmissionSchedule']))
  661.             $model->attributes=$_GET['AdmissionSchedule'];
  662.         if(isset($_GET['pageSize'])) {
  663.             Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']);
  664.             unset($_GET['pageSize']);
  665.         }
  666.         $this->render('processrejected',array(
  667.             'model'=>$model,'sch_model'=>$sch_model));
  668.     }
  669.  
  670.     public function actionProcessCreate()
  671.     {
  672.         $sel_val = explode(',',$_POST['selected_val']);
  673.         foreach($sel_val as $val){
  674.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  675.             $comment = $_POST['comment'];
  676.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  677.             $fee_date=date('Y-m-d', strtotime("+25 days"));
  678.             $comment2=str_replace("*Date*",$fee_date,$comment1);
  679.             $comment3=str_replace("*message*",$_POST['add_comment'],$comment2);
  680.             $model->comment = $comment3;       
  681.             $model->interview_status = 'Selected';
  682.             $model->save();
  683.             echo CJSON::encode("success");
  684.         }
  685.  
  686.     }
  687.  
  688.     public function actionProcesscreatesms()
  689.     {
  690.         $contact=$users=$com=array();
  691.         $h=0;
  692.         $sel_val = explode(',',$_POST['id']);
  693.         foreach($sel_val as $val){
  694.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  695.             //$model->admn_form_id = $val;
  696.             //$when=$_POST['int_date'];
  697.             //$when_date=date("d-m-Y",strtotime($when));
  698.             //$when_time=date("H:i A",strtotime($when));
  699.             //$model->interview_date = date("Y-m-d H:i:s",strtotime($when));
  700.             //$model->interview_venue = $_POST['int_venue'];
  701.             $comment = $_POST['comment'];
  702.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  703.             $fee_date=date('Y-m-d', strtotime("+25 days"));
  704.             $comment2=str_replace("*Date*",$fee_date,$comment1);
  705.             //$comment3=str_replace("*start_time*",$when_time,$comment2);
  706.             //$comment4=str_replace("*venue*",$_POST['int_venue'],$comment3);
  707.             $comment5=str_replace("*message*",$_POST['add_comment'],$comment2);
  708.             $model->comment = $comment5;       
  709.             $model->interview_status = 'Selected';
  710.             $form_model = AdmissionForm::model()->findByPk($val);
  711.             $contact[$h]=$form_model->mobile_no;
  712.             $users[$h]=$form_model->admn_form_id;
  713.             $com[$h]=$comment5;
  714.             $model->save();
  715.             $form_model->save();
  716.             $h++;
  717.         }
  718.         $this->actionSmsall($contact,$com,$users);
  719.         echo CJSON::encode("success");
  720.        
  721.        
  722.     }
  723.  
  724.     public function actionProcessReject()
  725.     {
  726.         $sel_val = explode(',',$_POST['selected_val']);
  727.         foreach($sel_val as $val){
  728.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  729.             $comment = $_POST['comment'];
  730.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);          
  731.             $comment2=str_replace("*message*",$_POST['add_comment'],$comment1);
  732.             $model->comment = $comment2;       
  733.             $model->interview_status = 'Rejected';
  734.             $model->save();
  735.             echo CJSON::encode("success");
  736.         }
  737.     }
  738.     public function actionProcessrejectsms()
  739.     {
  740.         $contact=$users=$com=array();
  741.         $h=0;
  742.         $sel_val = explode(',',$_POST['id']);
  743.         foreach($sel_val as $val){
  744.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  745.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  746.             $comment = $_POST['comment'];
  747.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);          
  748.             $comment2=str_replace("*message*",$_POST['add_comment'],$comment1);
  749.             $model->comment = $comment2;       
  750.             $model->interview_status = 'Rejected';
  751.             $form_model = AdmissionForm::model()->findByPk($val);
  752.             $contact[$h]=$form_model->mobile_no;
  753.             $users[$h]=$form_model->admn_form_id;
  754.             $com[$h]=$comment2;
  755.             $model->save();
  756.             $form_model->save();
  757.             $h++;
  758.         }
  759.         $this->actionSmsall($contact,$com,$users);
  760.         echo CJSON::encode("success");
  761.     }
  762.  
  763.  
  764.  
  765.     public function actionSmsall($mobile,$message,$list)
  766.     {
  767.         $msg_id=$m=0;
  768.         $sender=Yii::app()->session['sms_header'];
  769.         if($sender=="" || $sender==NULL)
  770.             $sender="HEPHIV";
  771.         $sms_user=Yii::app()->session['sms_user'];
  772.         $sms_pass=Yii::app()->session['sms_pass'];
  773.        
  774.         $max_msg=SmsLog::model()->findAll(array("select"=>"max(msg_id) as max_msg_id"));
  775.         if(count($max_msg) > 0)
  776.             $msg_id=$max_msg[0]->max_msg_id+1;
  777.         foreach($list as $key=>$user)
  778.         {
  779.             $len_message = preg_replace("/[\r]/","",$message[$key]);
  780.             $length=strlen($len_message);
  781.             $mb_length=mb_strlen($len_message, "UTF-8");
  782.             $current_count=Yii::app()->list->smslength($length,$mb_length);
  783.  
  784.             $sms_log_model = new SmsLog;
  785.             $sms_log_model->sms_description=$message[$key];
  786.             $sms_log_model->msg_id=$msg_id;
  787.             $sms_log_model->sms_type=14;
  788.             $sms_log_model->mobile_no=$mobile[$key];
  789.             $sms_log_model->sms_count=$current_count;
  790.             $sms_log_model->access=15;
  791.             $sms_log_model->sent_on=date('Y-m-d H:i:s');
  792.             $sms_log_model->sent_by=1;
  793.             $sms_log_model->dist_type=14;
  794.             $sms_log_model->distribution_list=$user;
  795.             $sms_log_model->save();
  796.  
  797.             $jsondata[$m]['mobile_no']= $mobile[$key];
  798.             $jsondata[$m]['final_message']=$message[$key];
  799.             $jsondata[$m]['sender']=$sender;
  800.             $jsondata[$m]['sms_user']=$sms_user;
  801.             $jsondata[$m]['sms_pass']=$sms_pass;
  802.             $m++;
  803.         }
  804.         $enc_json=json_encode($jsondata);
  805.         $this->actionPostData($enc_json);
  806.     }
  807.  
  808.     public function actionProcessHold()
  809.     {
  810.         // Uncomment the following line if AJAX validation is needed
  811.         // $this->performAjaxValidation($model);
  812.         $sel_val = explode(',',$_POST['selected_val']);
  813.         foreach($sel_val as $val){
  814.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  815.             $comment = $_POST['comment'];
  816.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  817.             $comment2=str_replace("*message*",$_POST['add_comment'],$comment1);
  818.             $model->comment = $comment2;       
  819.             $model->interview_status = 'OnHold';
  820.             $model->save();
  821.             echo CJSON::encode("success");
  822.         }
  823.     }
  824.     public function actionProcessholdsms()
  825.     {
  826.         $contact=$users=$com=array();
  827.         $h=0;
  828.         $sel_val = explode(',',$_POST['id']);
  829.         foreach($sel_val as $val){
  830.             $model =AdmissionSchedule::model()->find('admn_form_id='.$val);
  831.             $comment = $_POST['comment'];
  832.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  833.             $comment2=str_replace("*message*",$_POST['add_comment'],$comment1);
  834.             $model->comment = $comment2;       
  835.             $model->interview_status = 'OnHold';
  836.             $form_model = AdmissionForm::model()->findByPk($val);
  837.             $contact[$h]=$form_model->mobile_no;
  838.             $users[$h]=$form_model->admn_form_id;
  839.             $com[$h]=$comment2;
  840.             $model->save();
  841.             $form_model->save();
  842.             $h++;
  843.         }
  844.         $this->actionSmsall($contact,$com,$users);
  845.         echo CJSON::encode("success");
  846.     }
  847.  
  848.     public function actionProcessResch()
  849.     {
  850.         $sel_val = explode(',',$_POST['selected_val']);
  851.         foreach($sel_val as $val){
  852.             $model = AdmissionSchedule::model()->find('admn_form_id='.$val);
  853.             $when=$_POST['interview_date'];
  854.             $when_date=date("d-m-Y",strtotime($when));
  855.             $when_time=date("H:i A",strtotime($when));
  856.             $model->interview_date = date("Y-m-d H:i:s",strtotime($when));
  857.             $model->interview_venue = $_POST['interview_venue'];
  858.             $comment = $_POST['comment'];
  859.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  860.             $comment2=str_replace("*date*",$when_date,$comment1);
  861.             $comment3=str_replace("*time*",$when_time,$comment2);
  862.             $comment4=str_replace("*venue*",$_POST['interview_venue'],$comment3);
  863.             $comment5=str_replace("*message*",$_POST['add_comment'],$comment4);
  864.             $model->comment = $comment5;
  865.             $model->interview_status = 'YetToProcess';
  866.             $model->save();
  867.             echo CJSON::encode("success");
  868.         }
  869.     }
  870.  
  871.     public function actionProcessreschsms()
  872.     {
  873.         $contact=$users=$com=array();
  874.         $h=0;
  875.         $sel_val = explode(',',$_POST['id']);
  876.         foreach($sel_val as $val){
  877.             $model = new AdmissionSchedule;
  878.             $model = AdmissionSchedule::model()->find('admn_form_id='.$val);
  879.             $when=$_POST['interview_date'];
  880.             $when_date=date("d-m-Y",strtotime($when));
  881.             $when_time=date("H:i A",strtotime($when));
  882.             $model->interview_date = date("Y-m-d H:i:s",strtotime($when));
  883.             $model->interview_venue = $_POST['interview_venue'];
  884.             $comment = $_POST['comment'];
  885.             $comment1=str_replace("*student_name*",$model->admnSch->first_name,$comment);
  886.             $comment2=str_replace("*date*",$when_date,$comment1);
  887.             $comment3=str_replace("*time*",$when_time,$comment2);
  888.             $comment4=str_replace("*venue*",$_POST['interview_venue'],$comment3);
  889.             $comment5=str_replace("*message*",$_POST['add_comment'],$comment4);
  890.             $model->comment = $comment5;
  891.             $model->interview_status = 'YetToProcess';
  892.             $form_model = AdmissionForm::model()->findByPk($val);
  893.             $contact[$h]=$form_model->mobile_no;
  894.             $users[$h]=$form_model->admn_form_id;
  895.             $com[$h]=$comment5;
  896.             $model->save();
  897.             $form_model->save();
  898.             $h++;
  899.         }
  900.         $this->actionSmsall($contact,$com,$users);
  901.         echo CJSON::encode("success");
  902.     }
  903.  
  904.     public function actionExportProcessExcel($id) {
  905.         $data=Yii::app()->session['admissionexcel'];
  906.         //print_r(Yii::app()->session['studentexcel']);
  907.         if(empty(Yii::app()->session['admissionexcel'])){
  908.             $data= new CActiveDataProvider('AdmissionSchedule');
  909.         }
  910.         if($id == 1){
  911.             $fileName = "admission_process_";
  912.         }
  913.         else {
  914.             $fileName = "process_rejected_";
  915.         }
  916.         $cur_time=date("Ymd_his");
  917.         $this->widget('EExcelView', array(
  918.             'dataProvider'=>  $data,
  919.             'grid_mode'=>'export',
  920.             'title'=>'Title',
  921.             'filename'=>$fileName.$cur_time,
  922.             'stream'=>true,
  923.             'exportType'=>'Excel2007',
  924.             'columns'=>array(
  925.                 array(//'name'=>'application_number',
  926.                     'value'=>'$data->admnSch->application_number',
  927.                     'header'=>'Application No',
  928.                 ),
  929.                 array(//'name'=>'first_name',
  930.                     'value'=>'$data->admnSch->first_name." ".$data->admnSch->last_name',
  931.                     'header'=>'Student Name',
  932.                 ),
  933.                 array(//'name'=>'father_name',
  934.                     'header'=>'Parent Name',
  935.                     'value'=>'$data->admnSch->father_name',
  936.                 ),
  937.                 array(//'name'=>'mobile_no',
  938.                     'header'=>'Mobile',
  939.                     'value'=>'$data->admnSch->mobile_no',
  940.                 ),
  941.                 array(//'name'=>'class_id',
  942.                     'value'=>'$data->admnSch->class->class_name',
  943.                     'header'=>'Class',
  944.                 ),
  945.                 array(//'name'=>'course',
  946.                     'value'=>'$data->admnSch->course->course_name',
  947.                     'header'=>'Group',
  948.                 ),
  949.                 array(//'name'=>'caste',
  950.                     'value'=>'$data->admnSch->quota->quota_name',
  951.                     'header'=>'Quota',
  952.                 ),
  953.                 array(//'name'=>'caste',
  954.                     'value'=>'$data->interview_date',
  955.                     'header'=>'Interview Date',
  956.                 ),
  957.                 array(//'name'=>'admission_status',
  958.                     'header'=>'Interview Status',
  959.                     'value'=>'$data->interview_status',
  960.                 ),             
  961.             ),
  962.         ));
  963.         Yii::app()->end();
  964.     }
  965.  
  966.     /**
  967.      * Returns the data model based on the primary key given in the GET variable.
  968.      * If the data model is not found, an HTTP exception will be raised.
  969.      * @param integer $id the ID of the model to be loaded
  970.      * @return AdmissionSchedule the loaded model
  971.      * @throws CHttpException
  972.      */
  973.     public function loadModel($id)
  974.     {
  975.         $model=AdmissionSchedule::model()->findByPk($id);
  976.         if($model===null)
  977.             throw new CHttpException(404,'The requested page does not exist.');
  978.         return $model;
  979.     }
  980.  
  981.     /**
  982.      * Performs the AJAX validation.
  983.      * @param AdmissionSchedule $model the model to be validated
  984.      */
  985.     protected function performAjaxValidation($model)
  986.     {
  987.         if(isset($_POST['ajax']) && $_POST['ajax']==='admission-schedule-form')
  988.         {
  989.             echo CActiveForm::validate($model);
  990.             Yii::app()->end();
  991.         }
  992.     }
  993.  
  994.     public function actionPostData($enc_json){
  995.         $post_data = 'jsondata='.$enc_json;
  996.  
  997.         //print_r($post_data);
  998.         //exit;
  999.         //Initiates a connection to example.com using port 80 with a timeout of 15 seconds.
  1000.         $socket = fsockopen("app.timetoschool.com", 80, $errno, $errstr, 5000);
  1001.    
  1002.         //Checks if the connection was fine
  1003.         if(!$socket){
  1004.             //Connection failed so we display the error number and message and stop the script from continuing
  1005.             echo ' error: ' . $errno . ' ' . $errstr;
  1006.             die;
  1007.         }else{
  1008.             //Builds the header data we will send along with are post data. This header data tells the web server we are connecting to what
  1009.             //we are, what we are requesting and the content type so that it can process are request.
  1010.             $http  = "POST /school/message_service.php HTTP/1.1\r\n";
  1011.             $http .= "Host: app.timetoschool.com\r\n";
  1012.             $http .= "User-Agent: " . $_SERVER['HTTP_USER_AGENT'] . "\r\n";
  1013.             $http .= "Content-Type: application/x-www-form-urlencoded\r\n";
  1014.             $http .= "Content-length: " . strlen($post_data) . "\r\n";
  1015.             $http .= "Connection: close\r\n\r\n";
  1016.             $http .= $post_data . "\r\n\r\n";
  1017.             //Sends are header data to the web server
  1018.             //stream_set_timeout($socket, 0, 2000 * 1000);
  1019.             fputs($socket, $http);
  1020.             $contents = "";
  1021.             //Waits for the web server to send the full response. On every line returned we append it onto the $contents
  1022.             //variable which will store the whole returned request once completed.
  1023.             /*while (!feof($socket)) {
  1024.              $contents .= fgets($socket, 4096);
  1025.             }*/
  1026.             //Close are request or the connection will stay open untill are script has completed.
  1027.             fclose($socket);
  1028.         }
  1029.         return null;
  1030.     }
  1031. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement