Parsing an very complex array into simple user friendly view
<?php ini_set('display_errors', E_ALL); ini_set('memory_limit', '2048M'); ini_set('max_execution_time', '0'); include_once("xml2array.php"); //include class file mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("db_zorg") or die(mysql_error()); global $db; $db=true; //true if you want to run query $filename="~ALL_BHC~.xml"; $content = file_get_contents($filename); //Get the xml data as string // $content = iconv("utf-16","utf-8",$content); $content=str_replace("®","",$content); $content=str_replace("- <","<",$content); echo "<pre>"; $clsXML = new XMLToArray; //Create an instance of class XMLToArray $data= $clsXML->xml2array($content,1); //(String content, 1 or 0) If this is 0 the function will get the array value without attributes as well as the tag values. function getValue($arr) { $value=""; if(isset($arr['value']) && $arr['value']!='') { $value=value(utf8_decode($arr['value'])); } return $value; } // If this is 1 the function will get the array value with attributes. $bhc=array(); $bhc=$data['MEDIQUEST']['BHC']; //Getting Member array // echo "<pre>Arr(arr) = "; print_r($bhc); echo "</pre>"; exit; $ctr = 1; foreach($bhc as $bhcChild) { $bhcId=$bhcChild['attr']['BHCID']; // if($bhcId != '54100') { $ctr++; continue; } //-- mjv $check_member = "SELECT id FROM members where bhcid = '".$bhcId."'"; $rs_check_member = mysql_query($check_member); $count_member = mysql_num_rows($rs_check_member); $row = mysql_fetch_assoc($rs_check_member); $member_id = $row['id']; if($member_id <= 0) { echo "BHCID-".$bhcId; continue; } $bhcChildArray=array(); foreach($bhcChild as $k=>$v) { $bhcChildArray[strtolower($k)]=getValue($v); } $arr = $bhcChild; echo "<br/><br/>Counter > $ctr -- BHCID > ".$bhcId."($member_id) -- ".$arr['NAAM']['value']; if(isset($arr['SPECIALISMEN'])) { $arr_speciality = $arr['SPECIALISMEN']; foreach($arr_speciality as $key2 => $speciality) { foreach($speciality as $key3 => $val3) { $specialist_id = 0; if(isset($val3['attr'])) { $specialismeId = $val3['attr']['SPECIALISMEID']; // echo "<br/>-----Speciality If > $specialismeId($member_id) -- ".$val3['NAAM']['value']; $sql_check_speciality = "SELECT id FROM specialities where member_id = '".$member_id."' AND specialismeid = '".$specialismeId."'"; $rs_check_speciality = mysql_query($sql_check_speciality); $count_check_speciality = mysql_num_rows($rs_check_speciality); if($count_check_speciality > 0) { $row_check_speciality = mysql_fetch_assoc($rs_check_speciality); $specialist_id = $row_check_speciality['id']; } } else { if(!isset($val3['SPECIALISMEID'])) { continue; } $specialismeId = $val3['SPECIALISMEID']; // echo "<br/>-----Speciality Else > $specialismeId($member_id) -- ".$speciality['NAAM']['value']; $sql_check_speciality = "SELECT id FROM specialities where member_id = '".$member_id."' AND specialismeid = '".$specialismeId."'"; $rs_check_speciality = mysql_query($sql_check_speciality); $count_check_speciality = mysql_num_rows($rs_check_speciality); if($count_check_speciality > 0) { $row_check_speciality = mysql_fetch_assoc($rs_check_speciality); $specialist_id = $row_check_speciality['id']; } // echo "<pre>Arr(arr) = "; print_r($speciality); echo "</pre>"; exit; } if((isset($val3['AANDOENINGEN'])) && ($specialist_id > 0)) { $treatments = $val3['AANDOENINGEN']; foreach($treatments as $key4 => $treatment) { if(isset($treatment['attr'])) { $treatment_id = $treatment['attr']['AANDOENINGID']; // echo "<br/>----------Treatment MultiS > $treatment_id($specialist_id) -- ".$treatment['NAAM']['value']; getTreatment($treatment, $specialismeId, $specialist_id, $member_id); // echo "<pre>Arr(arr) = "; print_r($treatment); echo "</pre>"; } foreach($treatment as $key5 => $val5) { if(isset($val5['attr'])) { $treatment_id = $val5['attr']['AANDOENINGID']; // echo "<br/>-----------Treatment MultiM > $treatment_id($specialist_id) -- ".$val5['NAAM']['value']; getTreatment($val5, $specialismeId, $specialist_id, $member_id); } } } }else { if($specialist_id > 0) { if(isset($speciality['AANDOENINGEN']['AANDOENING'])) { $treatments = $speciality['AANDOENINGEN']['AANDOENING']; if(isset($treatments['attr'])) { $treatment_id = $treatments['attr']['AANDOENINGID']; // echo "<br/>----------Treatment Single > $treatment_id($specialist_id) -- ".$treatments['NAAM']['value']; getTreatment($treatments, $specialismeId, $specialist_id, $member_id); } else { foreach($treatments as $key4 => $treatment) { if(isset($treatment['attr'])) { $treatment_id = $treatment['attr']['AANDOENINGID']; // echo "<br/>----------Treatment MultiS2 > $treatment_id($specialist_id) -- ".$treatment['NAAM']['value']; getTreatment($treatment, $specialismeId, $specialist_id, $member_id); // echo "<pre>Arr(arr) = "; print_r($treatment); echo "</pre>"; } } } } } } // Ends -- isset($val3['AANDOENINGEN'] } } } $ctr++; } //Outer foreach end mysql_query("update treatments set title = 'Reumatoide artritis' where title = 'Reumatoïde artritis'"); //-- Reumatoïde artritis mysql_query("update treatments set title = 'Langzaamwerkende schildklier (Hypothyreoidie)' where title = 'Langzaamwerkende schildklier (Hypothyreoïdie)'"); //-- Langzaamwerkende schildklier (Hypothyreoïdie) mysql_query("update treatments set title = 'Paniekstoornissen en fobieen' where title = 'Paniekstoornissen en fobieën'"); //-- Paniekstoornissen en fobieën mysql_query("update treatments set title = 'Rontgen onderzoek' where title = 'Röntgen onderzoek'"); //-- Röntgen onderzoek mysql_query("update treatments set title = 'Snelwerkende schildklier (Hyperthyreoidie)' where title = 'Snelwerkende schildklier (Hyperthyreoïdie)'"); //-- Snelwerkende schildklier (Hyperthyreoïdie) mysql_query("update treatments set title = 'Sjogren, syndroom van' where title = 'Sjögren, syndroom van'"); //-- Sjögren, syndroom van echo "<br/><br>Total Records: ".count($bhc); function getTreatment($aandoeningChild, $specialismeid, $specialist_id, $member_id) { global $db; $aandoeningChildArray=array(); $aandoeningId=$aandoeningChild['attr']['AANDOENINGID']; foreach($aandoeningChild as $key=>$val) { if($key=='attr') continue; $aandoeningChildArray[strtolower($key)]=getValue($val); } extract($aandoeningChildArray); //INSERT DATA IN THE TREATMENT TABLE $sql_check_treatment = "SELECT id FROM treatments where specialismeid = '".$specialismeid."' AND aandoeningid = '".$aandoeningId."' AND clinic_id = '".$member_id."'"; $rs_check_treatment = mysql_query($sql_check_treatment); $count_check_treatment = mysql_num_rows($rs_check_treatment); if($count_check_treatment > 0) { $sql="UPDATE treatments set title='".$naam."', specialist_id='".$specialist_id."', wachttijdpoli='".$wt_polikliniek."', wt_behandeling='".$wt_behandeling."', wachttijdopname='".$wt_retro."', wachttijddag='".$wt_status."', kwic_eindscore='".$kwic_eindscore."', kwic_septielscore='".$kwic_septielscore."', kwic_transpasp='".$kwic_transpasp."', kwic_transpaspcat='".$kwic_transpaspcat."', rodevlag='".$rodevlag."', rodevlagtoelichting='".$rodevlagtoelichting."', modified='".date("Y-m-d H:i:s")."' WHERE aandoeningid='".$aandoeningId."' AND specialismeid = '".$specialismeid."' AND clinic_id = '".$member_id."'"; } else { $sql="INSERT INTO treatments set title='".$naam."', clinic_id='".$member_id."', specialist_id='".$specialist_id."', specialismeid='".$specialismeid."', wachttijdpoli='".$wt_polikliniek."', wt_behandeling='".$wt_behandeling."', wachttijdopname='".$wt_retro."', wachttijddag='".$wt_status."', kwic_eindscore='".$kwic_eindscore."', kwic_septielscore='".$kwic_septielscore."', kwic_transpasp='".$kwic_transpasp."', kwic_transpaspcat='".$kwic_transpaspcat."', rodevlag='".$rodevlag."', rodevlagtoelichting='".$rodevlagtoelichting."', created='".date("Y-m-d H:i:s")."', modified='".date("Y-m-d H:i:s")."', aandoeningid='".$aandoeningId."'"; } if($db) { // echo $sql; mysql_query($sql); } return ''; } ### Converts Database text value HTML compatible for text fields ### Don't use this function in case of getting values from textarea or editor as it strip the tags function value($val = '', $default = '', $arr = '') { $numargs = func_num_args(); // call_user_func_array - Call a user function given with an array of parameters if(gettype($arr) == 'object') { $arr = get_object_vars($arr); } if($numargs > 2) { if(is_array($arr) && (count($arr) > 0)) { if( (!empty($val)) && (isset($arr[$val])) && (trim($arr[$val] != '')) ) { return get_absolute_value($arr[$val], $default); } } return get_absolute_value($default); } return get_absolute_value($val, $default); } ### Converts Database text value HTML compatible for text fields function get_absolute_value($val ='', $default = '') { if(!empty($val)) { if(is_string($val) ) { // For Textbox and other fields return htmlspecialchars(strip_tags(stripslashes(trim($val))), ENT_QUOTES); } return $val; } else { if( ($val === 0) || ($val === '0') ) { return $val; } return $default; } return false; } ?> <?php echo $this->Html->css('dataTable'); ?> <?php echo $this->Html->script('dataTables/jquery.dataTables'); ?> <?php echo $this->Html->script('dataTables/colResizable.min'); ?> <?php echo $this->Html->script('jBreadCrumb.1.1'); ?> <?php echo $this->Html->script('cal.min'); ?> <?php echo $this->Html->script('jquery.collapsible.min'); ?> <?php echo $this->Html->script('jquery.ToTop'); ?> <?php echo $this->Html->script('jquery.listnav'); ?> <?php echo $this->Html->script('jquery.sourcerer'); ?> <?php echo $this->Html->script('wysiwyg/jquery.wysiwyg'); ?> <?php echo $this->Html->script('wysiwyg/wysiwyg.image'); ?> <?php echo $this->Html->script('wysiwyg/wysiwyg.link'); ?> <?php echo $this->Html->script('wysiwyg/wysiwyg.table'); ?> <?php echo $this->Html->script('flot/jquery.flot'); ?> <?php echo $this->Html->script('flot/jquery.flot.pie'); ?> <?php echo $this->Html->script('flot/excanvas.min'); ?> <?php echo $this->Html->script('selectunselect'); ?> <?php echo $this->Html->css('facebox'); ?> <?php echo $this->Html->script('facebox'); ?> <?php echo $this->Html->css('colorboxx'); ?> <?php echo $this->Html->script('jquery.colorboxx'); ?> <?php if(isset($status) && trim($status)!=""){ $url = array($status); $this->Paginator->options(array('url' => $url)); } ?> <script type="text/javascript"> <!-- function del(field) { if(!anyChecked(field)) { // alert('Please select atleast one record to perform any action.'); jAlert('Please select atleast one record to perform any action.', 'Alert::MyDementiaCare'); return false; } else { if(jQuery('#CareplusSuggestionStatus').val() != '') { if(jQuery('#CareplusSuggestionStatus').val() == 'delete'){ if(!confirm("Are you sure you want to perform this action?")){ return false; } } else { return true; } } else { jAlert('Please select any option from drop down to perform any action.', 'Alert::MyDementiaCare'); return false; } } } //--> </script> <script type="text/javascript"> <!-- function delete_suggestion(suggestion_id) { if(confirm("Are you sure you want to perform this action?")) { var actionurl = '<?php echo SITE_URL; ?>'+"admin/careplus/profile/delete_suggestion/"+tip_id+"/<?php echo date("Ymdhis"); ?>"; jQuery.ajax({ type: 'GET', url : actionurl, data:{}, datatype:"html", success: function(data, status) { var div = "#tr_"+suggestion_id; jQuery(div).html(''); }, error: function (data, status, e) { // alert('Status: '+status+'; Server Error: '+e+'; Action URL : '+actionurl); } }); } } //--> </script> <?php echo $this->Form->create(null ,array('url'=>'/admin/careplus/profile/suggestions/'.$tip_id, 'class'=>'mainForm')); ?> <div class="content"> <div class="title" style=""><h5>Manage Suggestions</h5></div> <div class="users index"> <?php if (($this->Session->check('Message.flash'))) { echo $this->Session->flash('flash', array('element' => 'flash')); } ?> <div align="right"> <a class="btnIconLeft mt5" href="<?php echo SITE_URL; ?>admin/careplus/profile/add_suggestion/<?php echo $tip_id."/".date("YmdHis"); ?>"><img class="icon" alt="" src="<?php echo SITE_URL; ?>img/icons/dark/presentation.png"><span>Add New Suggestion</span></a> </div> <div class="table"> <div class="head"><h5 class="iFrames">Suggestions</h5></div> <div class="dataTables_wrapper" id="example_wrapper"> <div class="" style="visibility:hidden;"> <div class="dataTables_filter" id="example_filter"> <label>Search: <input type="text" placeholder="type here..."> <div class="srch"></div> </label> </div> </div> <table cellspacing="0" cellpadding="0" border="0" id="" class="display"> <thead> <tr> <th rowspan="1" colspan="1" width="5%" id="none" class="none;"> <?php echo $this->Form->text('CareplusSuggestion.all', array('type'=>'checkbox', 'id'=>'data[CareplusSuggestion][all]', 'style' => 'display:block;', 'onclick'=>"selectDeselect('data[CareplusSuggestion][id][]', this.name);"));?> </th> <th class="ui-state-default" rowspan="1" colspan="1" width="3%" style="cursor:auto;"> <div style="padding-right:8px;">#</div> </th> <th class="ui-state-default" rowspan="1" colspan="1">Suggestion</th> <th class="ui-state-default" rowspan="1" colspan="1" style="width:110px; text-align:center;">Approval Status</th> </tr> </thead> <tbody> <?php $rowcount = 0; $countTips = count($tips); if($countTips > 0){ foreach ($tips AS $row) { $index = ((($page-1)*$limit) + ($rowcount+1)); $suggestion_id = $tips[$rowcount]['CareplusSuggestion']['id']; ?> <tr id="tr_<?php echo $suggestion_id; ?>" class="gradeA <?php if($rowcount%2==0) echo 'odd'; else echo 'even';?>"> <td align="center"> <?php echo $this->Form->text('CareplusSuggestion.id][', array('type'=>'checkbox', 'style' => 'display:block;', 'value'=>$tips[$rowcount]['CareplusSuggestion']['id'], 'onclick'=>"checkSelection('data[CareplusSuggestion][id][]', 'data[CareplusSuggestion][all]')"));?> </td> <td align="center"><?php echo $index;?></td> <td> <?php echo nl2br($tips[$rowcount]['CareplusSuggestion']['description']); ?> </td> <td align="center"> <a id="a_<?php echo $tips[$rowcount]['CareplusSuggestion']['id']; ?>" title="Click to change status" href="javascript:void(0);" onclick="change_status('<?php echo $tips[$rowcount]['CareplusSuggestion']['id']; ?>')"><?php echo ($tips[$rowcount]['CareplusSuggestion']['approved'] == "1") ? "Approved" : "Un Approved"; ?></a> </td> </tr> <?php $rowcount++; } } ?> </tbody> </table> <?php if($countTips > 0) { ?> <?php echo $this->element('admin/paginate')?> <div class="fg-toolbar ui-toolbar ui-corner-bl ui-corner-br ui-helper-clearfix"> <div id="example_length" class="dataTables_length"> <?php echo $this->Form->input('CareplusSuggestion.status', array( 'options' => $mode, 'empty' => '(action)', 'label' => false, 'class' => 'validate[required]', 'error' => false, 'div' => false, 'style' => 'width:95px;' )); ?> <input type="submit" value="Submit" class="redBtn" onclick="return del('data[CareplusSuggestion][id][]')" name="data[CareplusSuggestion][submit]"> </div> <div class="dataTables_paginate fg-buttonset ui-buttonset fg-buttonset-multi ui-buttonset-multi paging_full_numbers" id="example_paginate"> </div> </div> <?php } else { ?> <div class="fg-toolbar ui-toolbar ui-widget-header ui-corner-bl ui-corner-br ui-helper-clearfix"> <div class="dataTables_length" id="example_length"> <label>No Records Available Yet.</label></div> </div> <?php } ?> </div> </div> </div> </div> <?php echo $this->Form->end(); ?> <script type="text/javascript"> <!-- function change_status(suggestion_id) { if(confirm("Are you sure you want to change approval status?")) { var actionurl = '<?php echo SITE_URL; ?>'+"admin/careplus/profile/change_approval_status/"+suggestion_id+"/<?php echo date("Ymdhis"); ?>"; jQuery.ajax({ type: 'GET', url : actionurl, data:{}, datatype:"html", success: function(data, status) { var div = "#a_"+suggestion_id; jQuery(div).html(data); }, error: function (data, status, e) { // alert('Status: '+status+'; Server Error: '+e+'; Action URL : '+actionurl); } }); } } //--> </script> <?php /* AgreeYa Solutions R Systems Mind Genies Virtual Employee Classic Informatics Private Limited Xicom Technologies LLC A-1 Technology Sebiz Infotech SmartData Enterprises Infopro India Pvt. Ltd. Binary Semantics Ltd. BrickRed Technologies Pvt. Ltd. Ishir Infotech MagicBricks.com Headstrong Flexsin Technologies Pvt. Ltd Authorgen Technologies Nucleus Software Exports Ltd InterraIT Konstant Infosolutions Pvt. Ltd. Sapple Systems (P) Ltd. Octal Info Solution Pvt. Ltd. FCS Software Solutions Ltd. Rosmerta Technologies Limited Lime Labs Brain Technosys Pvt. Ltd. SDP Labs Avalon Information Systems Pvt. Ltd. SUVI Information Systems Saviance Technologies Nagarro Software Pvt. Ltd. Sapient Corporation Percept Knorigin Sisoft Technologies DivPlayers 4th Quarter Technologies IndiaMart InterMESH Ltd. RC & M Aar Ess Remedies Pvt. Ltd. SAIC Fiserv Xavient Information Systems Halosys Technologies Inc. Kale Consultants Ltd. BrainPulse Technologies Maniks Systems Pvt Ltd. Kairaus Software Pvt. Ltd. Grey Matter India Technologies Pvt. Ltd. Icreon Communications Neuronimbus Software Service Pvt. Ltd. Broadway Infotech Pvt. Ltd. Mosaic ITES Services Pvt. Ltd. Shriv ComMedia Solutions Pvt. Ltd UG Software Technologies Pvt. Ltd. eCognysys Technologies Caneum India Pvt. Ltd. Vinove Software and Services Pvt. Ltd. ITCons e- Solutions Pvt. Ltd. Compare Infobase Pvt. Ltd. Agile Technosys Symphony Services */
Parsing an very complex array into simple user friendly view
Comments
Add your comment