File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/modules/form/controllers/Form.php
Back
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Form extends MY_Controller { function __construct() { parent::__construct(); $this->load->model('Form_model'); } function listing() { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_FORM_BUILDER')) show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "form/form"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "form_top"; $data['sub_menu'] = "form_builder"; $data['pagetitle'] = $this->lang->line('form_builder'); $data['forms'] = $this->Form_model->getForms(); $this->load->view('basetemplate', $data); } else { redirect("login"); } } function add() { if($this->session->userdata("user_id")) { if(!$this->input->post()) { if(!$this->acl->hasPermission('MANAGE_FORM_BUILDER')) show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "form/add"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "form_top"; $data['sub_menu'] = "form_builder"; $data['pagetitle'] = $this->lang->line('add_form_template'); $this->load->view('basetemplate', $data); } else { if(!$this->acl->hasPermission('MANAGE_FORM_BUILDER')) show_error($this->lang->line('no_permission_error')); $this->form_validation->set_rules('title', 'Title', 'required'); $this->form_validation->set_rules('version', 'Version', 'required'); if ($this->form_validation->run()==false){ $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } else { if($this->Form_model->addForm($this->input->post())) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } redirect('form/form/listing'); } } else { redirect("login"); } } function edit($id) { if($this->session->userdata("user_id")) { if(!$this->input->post()) { if(!$this->acl->hasPermission('MANAGE_FORM_BUILDER')) show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "form/edit"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "form_top"; $data['sub_menu'] = "form_builder"; $data['pagetitle'] = $this->lang->line('edit_form_template'); $data['form'] = $this->Form_model->getForm($id); $this->load->view('basetemplate', $data); } else { if(!$this->acl->hasPermission('MANAGE_FORM_BUILDER')) show_error($this->lang->line('no_permission_error')); $data = $this->Form_model->getForm($id); if(empty($data)) show_error('No record found'); $this->form_validation->set_rules('title', 'Title', 'required'); $this->form_validation->set_rules('version', 'Version', 'required'); if ($this->form_validation->run()==false){ $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } else { if($this->Form_model->editForm($this->input->post(),$id)) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } //redirect($_SERVER['HTTP_REFERER']); redirect('form/listing'); } } else { redirect("login"); } } function delete($id=0){ if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_FORM_BUILDER')) show_error($this->lang->line('no_permission_error')); $data = $this->Form_model->getForm($id); if(empty($data)) show_error('No record found'); if($this->Form_model->deleteForm($id)) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); redirect($_SERVER['HTTP_REFERER']); } else { redirect("login"); } } function get($id=0) { if($this->session->userdata("user_id")) { $data = $this->Form_model->getForm($id); $data['structure'] = preg_replace(array('/'/'),array('\''),$data['structure']); echo json_encode($data); } else { redirect("login"); } } function fr_clone($id=0){ if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('MANAGE_FORM_BUILDER')) show_error($this->lang->line('no_permission_error')); $data = $this->Form_model->getForm($id); if(empty($data)) show_error('No record found'); if($this->Form_model->cloneForm($id)) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); redirect($_SERVER['HTTP_REFERER']); } else { redirect("login"); } } function downloadFormAnswer($id) { if($this->session->userdata("user_id")) { $filename="formAnswer_csv_format.csv"; //load our new PHPExcel library $this->load->library('excel'); //activate worksheet number 1 $this->excel->setActiveSheetIndex(0); //name the worksheet $this->excel->getActiveSheet()->setTitle('Forms list'); $holidays = $this->Form_model->getFilledForms($id); $outarray = array(); //$data= $data1=$holidays[0]['answer']; //echo $data1."<br>"; $data= $holidays[0]['structure']; //echo $data;die; $dataarr=json_decode($data,true); $headerarr=[]; $allquestion=[]; //echo count($dataarr); $newarray=array( "applicant"=> "Applicant"); $headerarr=array_merge($headerarr, $newarray); $m=1; $l=1; for ($i=0; $i <count($dataarr) ; $i++) { for ($j=0; $j <count($dataarr['pages'][$i]['elements']) ; $j++) { $newarray=array( "question$m"=> $dataarr['pages'][$i]['elements'][$j]['name']); $headerarr=array_merge($headerarr, $newarray); $m++; if($dataarr['pages'][$i]['elements'][$j]['type']=='matrix'){ $myarray = array( "question$l"=> array("name"=>$dataarr['pages'][$i]['elements'][$j]['name'],"type"=>$dataarr['pages'][$i]['elements'][$j]['type'] ,"rows"=>$dataarr['pages'][$i]['elements'][$j]['rows'] )); }elseif($dataarr['pages'][$i]['elements'][$j]['type']=='matrixdropdown'){ $myarray = array( "question$l"=> array("name"=>$dataarr['pages'][$i]['elements'][$j]['name'],"type"=>$dataarr['pages'][$i]['elements'][$j]['type'] ,"rows"=>$dataarr['pages'][$i]['elements'][$j]['rows'],"columns"=>$dataarr['pages'][$i]['elements'][$j]['columns'] )); } elseif($dataarr['pages'][$i]['elements'][$j]['type']=='matrixdynamic'){ $myarray = array( "question$l"=> array("name"=>$dataarr['pages'][$i]['elements'][$j]['name'],"type"=>$dataarr['pages'][$i]['elements'][$j]['type'] ,"columns"=>$dataarr['pages'][$i]['elements'][$j]['columns'] )); } elseif($dataarr['pages'][$i]['elements'][$j]['type']=='multipletext'){ $myarray = array( "question$l"=> array("name"=>$dataarr['pages'][$i]['elements'][$j]['name'],"type"=>$dataarr['pages'][$i]['elements'][$j]['type'] ,"items"=>$dataarr['pages'][$i]['elements'][$j]['items'] )); } else { $myarray = array( "question$l"=> array("name"=>$dataarr['pages'][$i]['elements'][$j]['name'],"type"=>$dataarr['pages'][$i]['elements'][$j]['type'] )); } $allquestion=array_merge($allquestion, $myarray); $l++; } } //print_r($allquestion); //print_r($holidays); for($i=0;$i<count($holidays);$i++) { $newarray=$holidays[$i]; $ans=''; if($i==0) { $newdata=array(); $n=1; $answer=json_decode($newarray['answer'],true); //echo $newarray['answer']; //print_r($answer); //die; $bodydata=array("applicant"=>$newarray['name_english']); $newdata=array_merge($newdata,$bodydata); for ($j=0; $j <count($allquestion); $j++) { //$can_foreach=is_array($que); //echo $allquestion["question$n"]['type']."<br>"; if($allquestion["question$n"]['type']=='checkbox'){ if(array_key_exists($headerarr["question$n"],$answer)) { $que=$answer[$headerarr["question$n"]]; for ($k=0; $k <count($que) ; $k++) { $ans.= $que[$k].','; } $ans=rtrim($ans,','); $bodydata=array("question$n"=>$ans); }else { $bodydata=array("question$n"=>''); } }elseif($allquestion["question$n"]['type']=='html' ||$allquestion["question$n"]['type']=='file' ||$allquestion["question$n"]['type']=='panel'){ $bodydata=array("question$n"=>''); }elseif($allquestion["question$n"]['type']=='matrixdynamic' ){ if(array_key_exists($headerarr["question$n"],$answer)) { $columns=$allquestion["question$n"]['columns']; $ans=''; for ($k=0; $k < count($answer["question$n"]); $k++) { # code... for ($x=0; $x <count($columns); $x++) { $colm=$columns[$x]['name']; $ans.= $answer["question$n"][$k][$colm].','; } } $ans=rtrim($ans,','); $bodydata=array("question$n"=>$ans); } else { $bodydata=array("question$n"=>''); } }elseif($allquestion["question$n"]['type']=='matrixdropdown' ){ if(array_key_exists($headerarr["question$n"],$answer)) { $matd=$allquestion["question$n"]['rows']; $columns=$allquestion["question$n"]['columns']; $ans=''; for ($k=0; $k <count($matd); $k++) { $text=$matd[$k]; for ($x=0; $x <count($columns); $x++) { $colm=$columns[$x]['name']; $ans.= $answer["question$n"][$text][$colm].','; } //echo $answer["question$n"][$text]; } $ans=rtrim($ans,','); $bodydata=array("question$n"=>$ans); } else { $bodydata=array("question$n"=>''); } //$bodydata=array("question$n"=>''); }elseif($allquestion["question$n"]['type']=='matrix'){ if(array_key_exists($headerarr["question$n"],$answer)) { $mat=$allquestion["question$n"]['rows']; //print_r($mat); $ans=''; for ($k=0; $k <count($mat); $k++) { $text=$mat[$k]; $ans.= $answer["question$n"][$text].','; //echo $answer["question$n"][$text]; } $ans=rtrim($ans,','); $bodydata=array("question$n"=>$ans); } else { $bodydata=array("question$n"=>''); } }elseif($allquestion["question$n"]['type']=='multipletext'){ if(array_key_exists($headerarr["question$n"],$answer)) { $que=$allquestion["question$n"]['items']; //print_r($que); $ans=''; for ($k=0; $k <count($que); $k++) { $text=$que[$k]['name']; $ans.= $answer["question$n"][$text].','; //echo $answer["question$n"][$text]; } $ans=rtrim($ans,','); //echo $ans;die; $bodydata=array("question$n"=>$ans); } else { $bodydata=array("question$n"=>''); } } else{ if(array_key_exists($headerarr["question$n"],$answer)) { $bodydata=array("question$n"=>$answer[$headerarr["question$n"]]); } else { //echo $headerarr["question$n"]; $bodydata=array("question$n"=>''); } } //$bodydata=array("question$n"=>$answer[$headerarr["question$n"]]); $newdata=array_merge($newdata,$bodydata); $n++; } $outarray[]=$headerarr; $outarray[]=$newdata; } else { //unset($newarray['id']); $newdata=array(); $n=1; //echo $newarray['answer']; $answer=json_decode($newarray['answer'],true); //print_r($answer); $bodydata=array("applicant"=>$newarray['name_english']); $newdata=array_merge($newdata,$bodydata); for ($j=0; $j <count($allquestion) ; $j++) { //$can_foreach=is_array($que); if($allquestion["question$n"]['type']=='checkbox'){ if(array_key_exists($headerarr["question$n"],$answer)) { $que=$answer[$headerarr["question$n"]]; for ($k=0; $k <count($que) ; $k++) { $ans.= $que[$k].','; } $ans=rtrim($ans,','); $bodydata=array("question$n"=>$ans); }else { $bodydata=array("question$n"=>''); } }elseif($allquestion["question$n"]['type']=='html' ||$allquestion["question$n"]['type']=='file' ||$allquestion["question$n"]['type']=='panel'){ $bodydata=array("question$n"=>''); }elseif($allquestion["question$n"]['type']=='matrixdynamic' ){ if(array_key_exists($headerarr["question$n"],$answer)) { $columns=$allquestion["question$n"]['columns']; $ans=''; for ($k=0; $k < count($answer["question$n"]); $k++) { # code... for ($x=0; $x <count($columns); $x++) { $colm=$columns[$x]['name']; $ans.= $answer["question$n"][$k][$colm].','; } } $ans=rtrim($ans,','); $bodydata=array("question$n"=>$ans); } else { $bodydata=array("question$n"=>''); } }elseif($allquestion["question$n"]['type']=='matrixdropdown' ){ if(array_key_exists($headerarr["question$n"],$answer)) { $matd=$allquestion["question$n"]['rows']; $columns=$allquestion["question$n"]['columns']; $ans=''; for ($k=0; $k <count($matd); $k++) { $text=$matd[$k]; for ($x=0; $x <count($columns); $x++) { $colm=$columns[$x]['name']; $ans.= $answer["question$n"][$text][$colm].','; } //echo $answer["question$n"][$text]; } $ans=rtrim($ans,','); $bodydata=array("question$n"=>$ans); } else { $bodydata=array("question$n"=>''); } //$bodydata=array("question$n"=>''); }elseif($allquestion["question$n"]['type']=='matrix'){ if(array_key_exists($headerarr["question$n"],$answer)) { $mat=$allquestion["question$n"]['rows']; //print_r($mat); $ans=''; for ($k=0; $k <count($mat); $k++) { $text=$mat[$k]; $ans.= $answer["question$n"][$text].','; //echo $answer["question$n"][$text]; } $ans=rtrim($ans,','); $bodydata=array("question$n"=>$ans); } else { $bodydata=array("question$n"=>''); } }elseif($allquestion["question$n"]['type']=='multipletext'){ if(array_key_exists($headerarr["question$n"],$answer)) { $que=$allquestion["question$n"]['items']; //print_r($que); $ans=''; for ($k=0; $k <count($que); $k++) { $text=$que[$k]['name']; $ans.= $answer["question$n"][$text].','; //echo $answer["question$n"][$text]; } $ans=rtrim($ans,','); //echo $ans;die; $bodydata=array("question$n"=>$ans); } else { $bodydata=array("question$n"=>''); } } else{ if(array_key_exists($headerarr["question$n"],$answer)) { $bodydata=array("question$n"=>$answer[$headerarr["question$n"]]); } else { //echo $headerarr["question$n"]; $bodydata=array("question$n"=>''); } } $newdata=array_merge($newdata,$bodydata); $n++; } $outarray[]=$newdata; } } //die; // read data to active sheet $this->excel->getActiveSheet()->fromArray($outarray); header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=".$filename); $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); $objWriter->save('php://output'); } else { redirect("login"); } } }
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.45 |
proxy
|
phpinfo
|
Settings