File manager - Edit - /home/wwwroot/camplus.hk/master.camplus.hk/public_html/application/modules/workflow/controllers/Workflow_form.php
Back
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Workflow_form extends MY_Controller { function __construct() { parent::__construct(); $this->load->model('Workflow_form_model'); $this->load->model('form/Form_model'); $this->load->model('core/User_model'); $this->load->model('core/User_group_model'); $this->load->model('Workflow_model'); $this->load->model('Academic_year/Academic_year_model'); } function listing($year=0) { if($this->session->userdata("user_id")) { // if(!$this->acl->hasPermission('APPLY_FORM')) // show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['current_year'] = $this->Academic_year_model->getCurrentAcademicYear()['id']; if($year==0) $year = $data['current_year']; else $data['current_year'] = $year; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "workflow/my_form"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "wf_top"; $data['sub_menu'] = "myform"; $data['pagetitle'] = $this->lang->line('my') . ' ' . $this->lang->line('form'); $data['ac_years'] = $this->Academic_year_model->getAcademicYears(); $data['myforms'] = $this->Workflow_form_model->getAppliedForms($year); $data['users'] = $this->User_model->getAllUsers(); $data['units'] = $this->User_group_model->getGroups(); $data['workflowforms'] = $this->Workflow_model->getWorkflowForms(); $this->load->view('basetemplate', $data); } else { redirect("login"); } } function all($year=0) { if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('VIEW_ALL_FORM')) show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['current_year'] = $this->Academic_year_model->getCurrentAcademicYear()['id']; if($year==0) $year = $data['current_year']; else $data['current_year'] = $year; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "workflow/all_form"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "wf_top"; $data['sub_menu'] = "allform"; $data['ac_year'] = $year; $data['pagetitle'] = $this->lang->line('all') . ' ' . $this->lang->line('form'); $data['ac_years'] = $this->Academic_year_model->getAcademicYears(); $data['myforms'] = $this->Workflow_form_model->getAllForms($year); $data['units'] = $this->User_group_model->getGroups(); $data['workflowforms'] = $this->Workflow_model->getWorkflowForms(); //pr($data['myforms']); $data['users'] = $this->User_model->getAllUsers(); $this->load->view('basetemplate', $data); } else { redirect("login"); } } function approval($year=0) { if($this->session->userdata("user_id")) { //if(!$this->acl->hasPermission('ACCESS_FORM_APPROVAL')) //show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['current_year'] = $this->Academic_year_model->getCurrentAcademicYear()['id']; if($year==0) $year = $data['current_year']; else $data['current_year'] = $year; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "workflow/form_approval"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "wf_top"; $data['sub_menu'] = "form_approval"; $data['pagetitle'] = $this->lang->line('form') . ' ' . $this->lang->line('approval'); $data['ac_years'] = $this->Academic_year_model->getAcademicYears(); $data['myforms'] = $this->Workflow_form_model->getApprovalForms($year); $data['units'] = $this->User_group_model->getGroups(); $data['workflowforms'] = $this->Workflow_model->getWorkflowForms(); $data['users'] = $this->User_model->getAllUsers(); $this->load->view('basetemplate', $data); } else { redirect("login"); } } function getForm($id = 0) { return $this->db->get_where('form',array('id' => $id))->row_array(); } function clone($id = 0) { $data = $this->db->get_where('wf_filled_form',array('id' => $id))->row_array(); $form_workflow = $this->db->get_where('wf_form_workflow',array('fid' => $data['fid']))->row_array(); $workflow = $this->db->get_where('wf_workflow',array('id' => $form_workflow['wid']))->row_array(); $wf = json_decode($workflow['workflow']); $wf->checkbox = []; $ac_year = $this->Academic_year_model->getCurrentAcademicYear(); $this->db->insert('wf_filled_form',['unit'=>$data['unit'],'uid'=>$data['uid'],'fid'=>$data['fid'],'workflow'=>json_encode($wf),'apply_date'=>date('Y-m-d'),'status'=>'draft','ay_id'=>$ac_year['id']]); $data = $this->db->insert_id(); $form_answer = $this->db->get_where('wf_form_answers',['ff_id'=>$id])->row_array(); $this->db->insert('wf_form_answers',['ff_id'=>$data,'answer'=>$form_answer['answer']]); redirect('workflow/workflow_form/edit/'.$data); } function add() { if($this->session->userdata("user_id")) { if(!$this->input->post()) { if(!$this->acl->hasPermission('APPLY_FORM')) show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "workflow/my_form_add"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "wf_top"; $data['sub_menu'] = "addnewmyform"; $data['pagetitle'] = $this->lang->line('apply') . ' ' . $this->lang->line('new') . ' ' . $this->lang->line('form'); $data['workflowforms'] = $this->Workflow_model->getWorkflowForms(); $data['units'] = $this->User_group_model->getMyGroups(); $data['users'] = $this->User_model->getAllUsers(); $data['years'] = $this->Academic_year_model->getAcademicYears(); $data['current_year'] = $this->Academic_year_model->getCurrentAcademicYear()['id']; if(count($data['units'])==0) $this->session->set_flashdata('error', 'You do not belongs to any group'); $this->load->view('basetemplate', $data); } else { //if(!$this->acl->hasPermission('MANAGE_XXX')) // show_error($this->lang->line('no_permission_error')); //$this->form_validation->set_rules('title', 'Title', 'required'); //if ($this->form_validation->run()==false){ // $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); //} //else //{ //print_r($this->input->post()); die; if($this->Workflow_form_model->addForm($this->input->post())) echo $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else echo $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); //} //var_dump($this->input->post()); redirect('workflow/workflow_form/listing'); } } else { redirect("login"); } } function submit($id) { if($this->Workflow_form_model->submitMyForm($id)) { $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); } else { $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); redirect('workflow/workflow_form/listing'); } function saveForm() { //print_r($this->input->post());echo count($this->input->post()); //die; if($this->Workflow_form_model->saveForm($this->input->post())){ echo $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); } else{ echo $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } redirect('workflow/workflow_form/listing'); } function saveEditForm() { //print_r($this->input->post()); if($this->Workflow_form_model->saveEditForm($this->input->post())) echo $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else echo $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); redirect('workflow/workflow_form/listing'); } function edit($id) { if($this->session->userdata("user_id")) { if(!$this->input->post()) { if(!$this->acl->hasPermission('APPLY_FORM')) show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['fid']=$id; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "workflow/my_form_edit"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "wf_top"; $data['sub_menu'] = "myform"; $data['pagetitle'] = $this->lang->line('edit') . ' ' . $this->lang->line('form'); $data['forms'] = $this->Form_model->getForms(); $data['users'] = $this->User_model->getAllUsers(); $data['units'] = $this->User_group_model->getGroups(); $data['myform'] =$this->Workflow_form_model->getFilledForm($id); $data['checked']=$this->Workflow_form_model->getFilledForm1($id); $data['workflowforms'] = $this->Workflow_model->getWorkflowForms(); $data['title']= $this->Workflow_form_model->getFormstitle($id); $data['years'] = $this->Academic_year_model->getAcademicYears(); $this->load->view('basetemplate', $data); } else { if($this->Workflow_form_model->editForm($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('workflow/workflow_form/listing'); } } else { redirect("login"); } } function revise($id) { if($this->session->userdata("user_id")) { if($this->input->post()) { if($this->Workflow_form_model->updateForm($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('workflow/workflow_form/listing'); } } else { redirect("login"); } } function rejectForm($id) { if($this->session->userdata("user_id")) { if($this->Workflow_form_model->updateFormApproveStatus($id,'Disagree')) $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); else $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); //echo json_encode($data); redirect('workflow/workflow_form/approval'); } else { redirect("login"); } } function approveForm($id) { if($this->session->userdata("user_id")) { if($this->Workflow_form_model->updateFormApproveStatus($id,'Agree' )) { $this->session->set_flashdata('success', $this->lang->line('action_performed_success')); } else { $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); } $data=$this->Workflow_form_model->getFormStatusDetails($id); // print_r($data);// die; $data1=$this->Workflow_form_model->getFormDetails($data['ff_id']); //print_r($data1); //echo "<br><br>"; $applicant=$this->Workflow_form_model->userDetails($data1['uid']); //print_r($applicant); //die; $filledworkflow=json_decode($data1['filledworkflow'],true); //print_r($filledworkflow);die; $workflow=json_decode($data1['workflow'],true); //print_r($workflow); $count=count($filledworkflow['workflow']) ; $checked=$filledworkflow['checkbox']; //echo $count; print_r($checked);die; // echo $workflow['workflow'][$data['level']]['approve']; /*If agree to next level is checked*/ if($workflow['workflow'][$data['level']]['approve']==1) { $alluser=$this->Workflow_form_model->getAllUserStatusDetails($data['ff_id'],$data['level']); // print_r($alluser); die; for ($i=0; $i <count($alluser); $i++) { $allStatus[]=$alluser[$i]['action']; } // print_r($allStatus);die; //all user approved if( !(in_array('Pending', $allStatus))) { $level=$data['level']+1; for ($i=$level; $i < $count; $i++) { $check='checked'.$i; // echo $check; if( !array_key_exists ($check , $checked )) { $users=$filledworkflow['workflow'][$i]['approver']; if(!empty($users)) { foreach ($users as $key => $value) { if($value == '-1' ){ /* $myform = $this->Workflow_form_model->getFilledFormdetails($id); $unit_head = $this -> User_group_model -> getGroupUsersUnitHead($myform['unit']); foreach ($unit_head as $unit_head_key => $unit_head_value){ $unit_head_id = $unit_head_value['id']; } */ }else{ $this->Workflow_form_model->addNextLevel($id,$value,'Pending',$i); $user=$this->Workflow_form_model->userDetails($value); $url = base_url().'workflow/workflow_form/approval'; $msg = 'New form has applied by '.$applicant['username'].', please check out this <a href="'.$url.'"> Link </a> for approval.</p></br></br>'; $this->send_mail($user,$applicant['username'],$msg,$url); } } } $users=$filledworkflow['workflow'][$i]['inform']; if(!empty($users)) { foreach ($users as $key => $value) { $user=$this->Workflow_form_model->userDetails($value); $url = base_url().'workflow/workflow_form/approval'; $msg = 'New form has applied by '.$applicant['username'].'. </p></br></br>'; $this->send_mail($user,$applicant['username'],$msg,$url); } } break; } } } } else { /*If agree to next level is unchecked*/ } redirect('workflow/workflow_form/approval'); } else { redirect("login"); } } function delete($id=0){ if($this->session->userdata("user_id")) { if(!$this->acl->hasPermission('APPLY_FORM')) show_error($this->lang->line('no_permission_error')); $data = $this->Workflow_form_model->getForm($id); if(empty($data)) show_error('No record found'); if($this->Workflow_form_model->deleteMyForm($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 cancel($id) { if($this->Workflow_form_model->cancelMyForm($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']); } function get($id=0) { if($this->session->userdata("user_id")) { $data = $this->Workflow_form_model->getFormworkflow($id); echo json_encode($data); } else { redirect("login"); } } function getWorkflowdetails($id) { if($this->session->userdata("user_id")) { $this->Workflow_form_model->getWorkflowDetail($id,$date); //echo json_encode($data); } else { redirect("login"); } } function getWorkflowdetails1($id,$date) { //echo $date; if($this->session->userdata("user_id")) { $this->Workflow_form_model->getWorkflowDetail1($id,$date); //echo json_encode($data); } else { redirect("login"); } } function getWorkflowUser($id=0) { if($this->session->userdata("user_id")) { $this->Workflow_form_model->getFormworkflow($id); //echo json_encode($data); } else { redirect("login"); } } function getWorkflowUseredit($id,$fid) { if($this->session->userdata("user_id")) { $this->Workflow_form_model->getFormworkflowedit($id,$fid); //echo json_encode($data); } else { redirect("login"); } } function send_mail($data , $user, $content, $url) { $message='<html><body><h3>'; $message.='Dear '.$data['username'].',</h3><br><p>'; $message .= $content; $message.='<p>Thanks!</p>'; $message.='</html></body>'; email($data['id'], ucfirst($user) . ' form waiting to approve', $message, $url,'WF'); } function downloadFormat($year) { if($this->session->userdata("user_id")) { $filename="myForms_csv_format.xls"; //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'); $filledForm =$this->Workflow_form_model->getAppliedForms($year); $outarray = array(); for($i=0;$i<count($filledForm);$i++) { $newarray=$filledForm[$i]; unset($newarray['id']); if($i==0) { $headerarr=array("date"=>"Date","title"=>"Forms","action"=>"Status","approval"=>"Last Approval"); $outarray[]=$headerarr; $outarray[]=array("date"=>date('Y-m-d', strtotime( $newarray['last_modified'] ) ), "title"=>$newarray['title'],"action"=>$newarray['action'],"approval"=>""); } else { //unset($newarray['id']); $outarray[]=array("date"=>date('Y-m-d', strtotime( $newarray['last_modified'] ) ), "title"=>$newarray['title'],"action"=>$newarray['action'],"approval"=>""); } } // 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"); } } function downloadFormApproval() { if($this->session->userdata("user_id")) { $filename="FormApproval_csv_format.xls"; //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'); $filledForm =$this->Workflow_form_model->getApprovalForms(); $users= $this->User_model->getAllUsers(); $outarray = array(); for($i=0;$i<count($filledForm);$i++) { $newarray=$filledForm[$i]; unset($newarray['id']); if($i==0) { $headerarr=array("date"=>"Date","applicant"=>"Applicant","title"=>"Forms","action"=>"Status"); $outarray[]=$headerarr; $outarray[]=array("date"=>date('Y-m-d', strtotime( $newarray['last_modified'] ) ), "applicant"=>$users[array_search($newarray['uid'],array_column($users,'id'))]['username'] , "title"=>$newarray['title'],"action"=>$newarray['action']); } else { //unset($newarray['id']); $outarray[]=array("date"=>date('Y-m-d', strtotime( $newarray['last_modified'] ) ), "applicant"=>$users[array_search($newarray['uid'],array_column($users,'id'))]['username'] , "title"=>$newarray['title'],"action"=>$newarray['action']); } } // 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"); } } function downloadAllForm() { if($this->session->userdata("user_id")) { $filename="AllForm_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'); $filledForm =$this->Workflow_form_model->getForms(); $users= $this->User_model->getAllUsers(); $outarray = array(); for($i=0;$i<count($filledForm);$i++) { $newarray=$filledForm[$i]; unset($newarray['id']); if($i==0) { $headerarr=array("date"=>"Date","title"=>"Forms","action"=>"Status","applicant"=>"Applicant","lastApproval"=>"Last Approval"); $outarray[]=$headerarr; $outarray[]=array("date"=>date('Y-m-d', strtotime( $newarray['last_modified'] ) ),"title"=>$newarray['title'],"action"=>$newarray['action'], "applicant"=>$users[array_search($newarray['uid'],array_column($users,'id'))]['username'],"lastApproval"=>" " ); } else { //unset($newarray['id']); $outarray[]=array("date"=>date('Y-m-d', strtotime( $newarray['last_modified'] ) ),"title"=>$newarray['title'],"action"=>$newarray['action'], "applicant"=>$users[array_search($newarray['uid'],array_column($users,'id'))]['username'],"lastApproval"=>" " ); } } // 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"); } } function display($id) { if($this->session->userdata("user_id")) { if(!$this->input->post()) { //if(!$this->acl->hasPermission('APPLY_FORM')) // may need to add view all form permission too //show_error($this->lang->line('no_permission_error')); $data = $this->data; $data['fid']=$id; $data['header'] = TRUE; $data['sidebar'] = TRUE; $data['_view'] = "workflow/form_display"; $data['quickbar'] = TRUE; $data['footer'] = TRUE; $data['top_menu'] = "wf_top"; //$data['sub_menu'] = "form_approval"; $data['pagetitle'] = $this->lang->line('display') . ' ' . $this->lang->line('form'); $data['forms'] = $this->Workflow_form_model->getForms(); $data['units'] = $this->User_group_model->getGroups(); $data['users'] = $this->User_model->getAllUsers(); $data['myform'] =$this->Workflow_form_model->getFilledFormdetails($id); $data['workflowforms'] = $this->Workflow_model->getWorkflowForms(); $data['form_status'] = $this->Workflow_form_model->getFormStatusDetails($id); $data['form_status_text'] = $this->Workflow_form_model->getFormStatusText($id); $this->load->view('basetemplate', $data); } else { // print_r($this->input->post());die; //if(!$this->acl->hasPermission('MANAGE_XXX')) // show_error($this->lang->line('no_permission_error')); $data = $this->Workflow_form_model->getForm($id); if(empty($data)) show_error('No record found'); // $this->form_validation->set_rules('title', 'Title', 'required'); //if ($this->form_validation->run()==false){ // $this->session->set_flashdata('error', $this->lang->line('action_performed_error')); //} //else //{ if($this->Workflow_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('workflow/workflow_form/listing'); } } else { redirect("login"); } } function downloadFormAnswer($id,$year) { if($this->session->userdata("user_id")) { $filename="formAnswer_csv_format.xls"; //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'); $filledForm = $this->Workflow_form_model->getFilledForms($id,$year); $outarray = array(); $data1=$filledForm[0]['answer']; //echo $data1."<br>"; $data= $filledForm[0]['structure']; // echo unescape($data);die; $dataarr=json_decode(unescape($data),true); // pr($dataarr); $headerarr=[]; $return= $this->generate_header($dataarr); $headerarr = $return[0]; //print_r($return); $allquestion = $return[1]; $newdata=array(); $bodyarray=array(); $outarray[]=$headerarr; $max_repeat = 1; for($i=0;$i<count($filledForm);$i++) { $newarray=$filledForm[$i]; $ans=''; $answer=json_decode($newarray['answer'],true); // print_r($answer); // print_r($newarray); $status = $this->Workflow_form_model->getFormStatusText($newarray['id']); $bodydata=array("form"=>$newarray['id'],"applicant"=>$newarray['name_english'],"unit"=>$newarray['unit'],"status"=>$status); $newdata = $this->load_answers($allquestion,$headerarr,$answer); // print_r($newdata); $answer_key = array(); if(!$this->is_multi2($newdata)) { $newdata=array_merge($bodydata,$newdata); $bodyarray[]=$newdata; } else { $new_merged_data = array(); foreach ($newdata as $onedata) { if(!is_array($onedata)) $onedata = array(0=>$onedata); $new_merged_data=array_merge($new_merged_data,$onedata); $answer_key = array_keys($onedata); $max_repeat++; } if(!$this->is_multi2($new_merged_data)) { $bodyarray[]=array_merge($bodydata,$new_merged_data); } else { foreach($new_merged_data as $onedata) { if(!is_array($onedata)) $onedata = array(0=>$onedata); $bodyarray[]=array_merge($bodydata,$onedata); } } } } // print_r($bodyarray);die; $outarray = array_merge($outarray,$bodyarray); // print_r($outarray); die; // read data to active sheet $this->excel->getActiveSheet()->fromArray($outarray); header("Content-type: application/xls"); header("Content-Disposition: attachment; filename=".$filename); $objWriter = PHPExcel_IOFactory::createWriter($this->excel, 'Excel5'); $objWriter->save('php://output'); } else { redirect("login"); } } function generate_header($dataarr) { $m=1; $l=1; $allquestion=[]; $headerarr=[]; $newarray=array( "id"=>"ID","applicant"=> "Applicant","unit"=>"Unit"); $headerarr=array_merge($headerarr, $newarray); 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++; $myarray = $this->generate_page_element($dataarr['pages'][$i]['elements'][$j],$l); $allquestion=array_merge($allquestion, $myarray); $l++; } } return array($headerarr,$allquestion); } function generate_page_element($element,$l) { // print_r($element); if($element['type']=='matrix'){ $myarray = array( "question$l"=> array("name"=>$element['name'],"type"=>$element['type'] ,"rows"=>$element['rows'] )); }elseif($element['type']=='matrixdropdown'){ $questions = $element['columns']; $myarray_array = []; foreach($questions as $x => $question){ if(!empty($question['title'])) $myarray_array[] = $question['title']; else $myarray_array[] = $question['name']; } $myarray = array( "question$l"=> array("name"=>$element['name'],"type"=>$element['type'] ,"items"=>$myarray_array, "rows"=>$element['rows'],"columns"=>$element['columns'] )); } elseif($element['type']=='matrixdynamic'){ $myarray = array( "question$l"=> array("name"=>$element['name'],"type"=>$element['type'] ,"columns"=>$element['columns'] )); } elseif($element['type']=='multipletext'){ $myarray = array( "question$l"=> array("name"=>$element['name'],"type"=>$element['type'] ,"items"=>$element['items'] )); } elseif($element['type']=='paneldynamic'){ $questions = $element['templateElements']; $myarray_array = []; foreach($questions as $x => $question){ $myarray_array = array_merge($myarray_array,$this->generate_page_element($question,($x+1))); } $myarray = array( "question$l"=> array("name"=>$element['name'],"type"=>$element['type'] ,"items"=>$myarray_array )); } else { $myarray = array( "question$l"=> array("name"=>$element['name'],"type"=>$element['type'] )); } return $myarray; } function load_answers($allquestion,$headerarr,$answer) { $n=1; $newdata=array(); $bodydata=array(); // echo $allquestion["question$n"]['type']; for ($j=0; $j <count($allquestion) ; $j++) { if($allquestion["question$n"]['type']=='checkbox'){ $ans=''; 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++) { 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' ){ //print_r($headerarr); //print_r($answer); 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']; // if(!empty($answer[$allquestion["question$n"]['name']][$text][$colm])) { // $ans.= $answer[$allquestion["question$n"]['name']][$text][$colm].','; // } else { // $ans.= ','; // } // } // } // $ans=rtrim($ans,','); // $bodydata=array("question$n"=>$ans); $matd=$allquestion["question$n"]['rows']; $columns=$allquestion["question$n"]['columns']; $ans= array(); for ($k=0; $k <count($matd); $k++) { $text=$matd[$k]; for ($x=0; $x <count($columns); $x++) { $colm=$columns[$x]['name']; if(!empty($columns[$x]['title'])) $colt=$columns[$x]['title']; else $colt=$columns[$x]['name']; if(!empty($answer[$allquestion["question$n"]['name']][$text][$colm])) { $ans[] = $answer[$allquestion["question$n"]['name']][$text][$colm]; } else { $ans[]= ''; } } } $bodydata=$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']; // $ans=''; // for ($k=0; $k <count($mat); $k++) { // $text=$mat[$k]; // $ans.= $answer["question$n"][$text].','; // } // $ans=rtrim($ans,','); // $bodydata=array("question$n"=>$ans); $mat=$allquestion["question$n"]['rows']; $ans=array(); for ($k=0; $k <count($mat); $k++) { $text=$mat[$k]; $ans["question$n_$k"] = $answer["question$n"][$text]; } $bodydata=$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']; // $ans=''; // for ($k=0; $k <count($que); $k++) { // $text=$que[$k]['name']; // $ans.= $answer["question$n"][$text].','; // } // $ans=rtrim($ans,','); // $bodydata=array("question$n"=>$ans); $que=$allquestion["question$n"]['items']; $ans=array(); for ($k=0; $k <count($que); $k++) { $text=$que[$k]['name']; $ans["question$n_$k"]= $answer["question$n"][$text]; } $bodydata=$ans; } else { $bodydata=array("question$n"=>''); } }elseif($allquestion["question$n"]['type']=='paneldynamic'){ //print_r($allquestion["question$n"]); $panel_questions = $allquestion["question$n"]['items']; $panel_headerarr = []; $p=1; foreach($panel_questions as $question) { $panel_headerarr = array_merge($panel_headerarr,array("question$p"=>$question['name'])); $p++; } $panels_answer = $answer[$headerarr["question$n"]]; foreach($panels_answer as $p=>$panel_answer) { // If panel dynamic question is added horizontally // $answer_arr = $this->load_answers($panel_questions,$panel_headerarr,$panel_answer); // If panel dynamic question is added vertically $answer_arr = array(); $answer_arr[] = $this->load_answers($panel_questions,$panel_headerarr,$panel_answer); $bodydata=array("question$n.$p"=>$answer_arr); $newdata=array_merge($newdata,$bodydata); } } 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++; } return $newdata; } function is_multi($a) { $rv = array_filter($a,'is_array'); if(count($rv)>0) return true; return false; } function is_multi2($a) { foreach ($a as $v) { if (is_array($v)) return true; } return false; } }
| ver. 1.4 |
Github
|
.
| PHP 7.2.34 | Generation time: 0.34 |
proxy
|
phpinfo
|
Settings