diff --git a/.gitignore b/.gitignore index 1c40c95..78ddb01 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ Raw/* # exclude everything except directory application *.[oa] +*.zip *~ * !application @@ -18,5 +19,6 @@ application/* !application/models !application/controllers +!assets/* application/config/database.php application/config/config.php diff --git a/README.md b/README.md new file mode 100644 index 0000000..db545dc --- /dev/null +++ b/README.md @@ -0,0 +1,29 @@ +# OpenDuka + +Open Duka is a project designed by the [Open Institute](http://www.openinstitute.com/) that will provide a freely accessible database of information on Kenyan entities. + +This information will provide citizens, journalists, and civic activists with a practical and easy-to-use tool to understand the ownership structure of the world they live in, demonstrating the practical applications of open information for normal citizens. It will serve as a core dataset for citizens, journalists, and civic activists who want to build 3rd party public transparency and public accountability apps or services, by allowing them to cross reference the Open Duka company shareholder data against other datasets. + +The project aims to scrape data from various sources that range from shareholder information, procurement information, legal cases and company information. + +The current pilot is being launched in Kenya in partnership with the National Council of Law Reporting and funded by A.T.T.I. + +This will be expanded to other sources of corporate data and the site will incorporate visualizations that will be able to show linkages of the data. + + +# Installation + + * Install CodeIgnighter. Download it at https://github.com/EllisLab/CodeIgniter and follow installation documentation. + + * Download OpenDuka files to the CodIgniter instance folder. + + * Edit the config.php in the application/config folder to reflect the web instance you are running. + + * Upload and reconstruct the database from the openduka_alpha.sql file. + + * Edit the database.php in the application/config folder to reflect the database instance you are running. + + +# License + +Open Duka by Open Institute is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License. diff --git a/application/controllers/admin.php b/application/controllers/admin.php index 46eb985..7c8a4a9 100644 --- a/application/controllers/admin.php +++ b/application/controllers/admin.php @@ -292,6 +292,7 @@ function ListTable(){ } + function ListField(){ //$this->output->enable_profiler(TRUE); $stabs = $this->input->post('STab'); @@ -339,7 +340,7 @@ function ListFieldEdit(){ $representation = explode(",",(str_replace(" ","",(str_replace("`","",$doc_info[0]['representation']))))); //echo($stabs); //var_dump($doc_info); exit; - $list = "
"; + $list = ""; //$list .="
Document Name {2007_PublicAwardedTenders}
"; $list .= "
Select field to show Entity
"; @@ -349,16 +350,16 @@ function ListFieldEdit(){ $name = $kiwanja->name; $list .= "
"; if (in_array($name, $representation)) { - $list .= ""; + $list .= ""; } else { - $list .= ""; + $list .= ""; } $list .= $kiwanja->name ."
"; } } $list .= '
- +
'; $list .= '
'; @@ -369,29 +370,75 @@ function ListFieldEdit(){ } - function EntityExtract(){ - //$this->output->enable_profiler(TRUE); - - //$table_name = $this->input->post('tablename'); - $DocumentType = $this->input->post('DocumentType'); - //$Verb = $this->input->post('Verb'); - $DocName = str_replace(' ', '_', $this->input->post('DocName')); - $viwanja = $this->input->post('Extract'); + function ListFieldEntityEdit(){ + //$this->output->enable_profiler(TRUE); + $stabs = $this->input->post('STab'); + $doc_info = $this->admin_model->get_document_ref($stabs); + //$representation = explode(",",(str_replace(" ","",(str_replace("`","",$doc_info[0]['representation']))))); +//echo($stabs); + //var_dump($doc_info); exit; + $list = "
"; + //$list .="
Document Name {2007_PublicAwardedTenders}
"; - $this->admin_model->table_name_change('NewTable', $DocName); + $list .= "
Select at least 2 fields to extract Entity from. Please note that the content in the field will be taken as array having a comma as a delimeter.
"; + $viwanja = $this->admin_model->get_fields($stabs); - $DocID = $this->admin_model->get_document_entry($DocName) ? : $this->admin_model->insert_document($DocName, $DocumentType); + foreach ($viwanja as $kiwanja) {$name[] = $kiwanja->name;} + + //var_dump($name); + foreach ($viwanja as $kiwanja) { + if (substr($kiwanja->name, -3) != '_E_') { + $n = $kiwanja->name . '_E_'; + $list .= "
"; + if (in_array($n, $name)) { + $list .= ""; + } else { + $list .= ""; + } + $list .= $kiwanja->name ."
"; + } + } - //var_dump($viwanja); - //var_dump($Verb); + $list .= '
+ + + +
'; + $list .= '
'; + + $list = empty($list) ? "Sorry No Data" : $list; + + echo $list; + } + + + function EntityExtract(){ + //$this->output->enable_profiler(TRUE); + + $table_name = $this->input->post('tablename'); + $DocumentType = $this->input->post('DocumentType'); + //$Verb = $this->input->post('Verb'); + $DocName = (strlen(trim($this->input->post('DocName'))) >= 4) ? str_replace(' ', '_', $this->input->post('DocName')) : ''; + $viwanja = $this->input->post('Extract'); + + if (strlen($DocName) >= 4) { $this->admin_model->table_name_change('NewTable', $DocName); } + else { $DocName = $table_name; } + + $DocID = $this->admin_model->get_document_entry($DocName) ? : $this->admin_model->insert_document($DocName, $DocumentType); + $DocDetails = $this->admin_model->get_document_details($DocID); + $CountryID = $DocDetails[0]['CountryID']; + + //var_dump($viwanja); exit; + //var_dump($Verb); + //echo $DocumentType; exit; $list ="Records Submitted "; $l=0; for($i=0; $iadmin_model->fieldcheck($viwanja[$i], $DocName); - $l += $this->admin_model->extract_entity($viwanja[$i], $DocName, $DocID, $this->session->userdata('user_id'), $DocumentType); + $l += $this->admin_model->extract_entity($viwanja[$i], $DocName, $DocID, $this->session->userdata('user_id'), $DocumentType, $CountryID); } @@ -404,12 +451,12 @@ function EntityExtract(){ function DatasetEdit(){ // $this->output->enable_profiler(TRUE); - $tbl = $this->input->post('tablename'); - $DataField = $this->input->post('DataField'); - // echo $tbl; exit; + $tbl = $this->input->post('Entitytablename'); + $DataField = $this->input->post('DataEntityField'); + $flds = (count($DataField) > 0) ? "'".implode(',', $DataField) ."'" : '*'; $list ="Records Submitted "; - + //echo $flds; exit; $this->admin_model->dataset_edit($tbl, $flds); } @@ -439,9 +486,9 @@ function DatasetAdd(){ */ $fileElementName = 'fileToUpload'; //$msg .=$_FILES[$fileElementName]['error']; - - if(!empty($_FILES[$fileElementName]['error'])) - { + //echo $_FILES[$fileElementName]['error']; exit; + if(!empty($_FILES[$fileElementName]['error'])){ + switch($_FILES[$fileElementName]['error']) { @@ -472,6 +519,7 @@ function DatasetAdd(){ $msg = '';//'No error code avaiable'; } } + //$msg .= $_FILES[$fileElementName]['tmp_name']; if(empty($_FILES[$fileElementName]['tmp_name']) || $_FILES[$fileElementName]['tmp_name'] == 'none') { @@ -538,45 +586,45 @@ function DatasetAdd(){ //var_dump(explode($lineseparator,$csvcontent)); - foreach(explode($lineseparator,$csvcontent) as $line) { + foreach(explode($lineseparator,$csvcontent) as $line) { - $lines++; - $skipped=0; - if($lines>1){ - $line = trim($line," \t"); + $lines++; + $skipped=0; + if($lines>1){ + $line = trim($line," \t"); - $line = str_replace("\r","",$line); + $line = str_replace("\r","",$line); - /************************************ - This line escapes the special character. remove it if entries are already escaped in the csv file - ************************************/ - $line = str_replace("'","\'",$line); - /*************************************/ + /************************************ + This line escapes the special character. remove it if entries are already escaped in the csv file + ************************************/ + $line = str_replace("'","\'",$line); + /*************************************/ - $linearray = explode($fieldseparator,$line); - $linearray = str_replace(",", "\,", $linearray); - $linearray = str_replace("'\," ,"'," ,$linearray); - //$linearray = preg_replace( "#[^a-zA-Z0-9,.]#", "", $linearray); - $linemysql = implode("','",$linearray); - if (strlen($linemysql)>=1){ - if($addauto){ - $query = "insert into $TblName values('','$linemysql');"; - } - else - { - $query = "insert into $TblName values('$linemysql');"; + $linearray = explode($fieldseparator,$line); + $linearray = str_replace(",", "\,", $linearray); + $linearray = str_replace("'\," ,"'," ,$linearray); + //$linearray = preg_replace( "#[^a-zA-Z0-9,.]#", "", $linearray); + $linemysql = implode("','",$linearray); + if (strlen($linemysql)>=1){ + if($addauto){ + $query = "insert into $TblName values('','$linemysql');"; + } + else + { + $query = "insert into $TblName values('$linemysql');"; + } } - } - //$queries .= $query . "\n"; + //$queries .= $query . "\n"; - //echo $queries; exit; - $insert = $this->admin_model->populate_table($query); + //echo $queries; exit; + $insert = $this->admin_model->populate_table($query); - if(!$insert){ $skipped++; $msg .= " $skipped were not inserted";} + if(!$insert){ $skipped++; $msg .= " $skipped were not inserted";} - } - } + } + } //$q = "insert into DocUploaded (title, doc_id, DocTypeID,data_table) values('$TblName', '".date('Ymd')."-$TblName',$DocumentType,'$TblName');"; //$this->admin_model->populate_table($q); @@ -585,7 +633,7 @@ function DatasetAdd(){ // var_dump($_FILES['fileToUpload']['tmp_name']); @unlink($_FILES[$fileElementName]); - } + } } diff --git a/application/controllers/api.php b/application/controllers/api.php index 271a979..4aad188 100644 --- a/application/controllers/api.php +++ b/application/controllers/api.php @@ -78,6 +78,7 @@ public function search(){ } } public function entity(){ + //$this->output->enable_profiler(true); $this->load->model('api_m'); if((!isset($_GET['key']))||(!isset($_GET['id']))){ $result = array("error"=>"missing key and or entity id"); @@ -87,8 +88,10 @@ public function entity(){ if($this->api_m->valid_key($_GET['key'])) { $doc = array(); + // echo $_GET['id']; exit; $result = $this->api_m->get_entries('ID',$_GET['id']); $docmap = explode(',',$result[0]['DocID']); + //var_dump($docmap); exit; foreach($docmap as $k => $d){ if(!in_array($d, $doc)){ @@ -97,22 +100,24 @@ public function entity(){ } $maps= '{"data":['; - //var_dump($root_node); + //var_dump($doc); if(sizeof($doc)>0){ for($i=0; $iapi_m->get_doc($doc_ref); - //var_dump($dataset); + $maps.= '{"dataset_type":[{"'. $dataset[0]['DocTypeName'] .'": [{"dataset":'; $dt=$dataset[0]['data_table']; $dtID=$dataset[0]['DocTypeID']; if($dt!=""){ + $d=1; $ds=$dataset[0]['representation']; $q = ($ds=="")? '*' : $ds; $dta = $this->api_m->get_dataset($dt,$q,$_GET['id']); + var_dump($dta); $maps.= json_encode($dta); } diff --git a/application/controllers/homes.php b/application/controllers/homes.php index 781f134..63df43f 100644 --- a/application/controllers/homes.php +++ b/application/controllers/homes.php @@ -9,6 +9,7 @@ function __construct() $this->load->database(); $this->load->library('pagination'); $this->load->model('home'); + $this->load->helper('form'); } @@ -167,48 +168,90 @@ function entityDoclist($ent="",$page_num=1) function entitylist($ent="",$page_num=1) { $page_num=($this->uri->segment(4)!="") ? $this->uri->segment(4) : '1'; + $ent = ($this->uri->segment(3)!="") ? $this->uri->segment(3) : "~"; $sortment = ($this->uri->segment(5)!="") ? $this->uri->segment(5) : ""; -//echo $sortment; exit; + $countryid = 1; +//echo $ent;// exit; //$this->output->enable_profiler(TRUE); $data_head = array('page_title' => 'Search results'); - $EntityName = isset($_POST['search_name']) ? $_POST['search_name'] : $ent ; - // $EntityName = str_replace(' ','',$EntityName); + $EntityName = isset($_POST['search_name']) && ($_POST['search_name']!="") ? $_POST['search_name'] : $ent ; + //echo $EntityName; + // // echo $page_num; - $results_per_page=25; + $results_per_page=27; $config['use_page_numbers'] = TRUE; - $config['base_url'] = base_url() . index_page().'/homes/entitylist/'. $EntityName ; + $config['base_url'] = base_url() . index_page().'/homes/entitylist/'. $EntityName .'/' ; + + $EntityName = str_replace('~','',$EntityName); + $config['total_rows'] = $this->home->get_entry_count('Name',$EntityName); $config['per_page'] = $results_per_page; $config['full_tag_open'] = ''; - $config['first_link'] = 'First'; - $config['first_tag_open'] = '
'; - $config['first_tag_close'] = '
'; - /* - $config['next_link'] = ''; + $config['first_link'] = 'FIRST'; + $config['first_tag_open'] = '
  • '; + $config['first_tag_close'] = '
  • '; + + $config['last_link'] = 'LAST'; + $config['last_tag_open'] = '
  • '; + $config['last_tag_close'] = '
  • '; + + $config['prev_link'] = 'PREV'; + $config['prev_tag_open'] = '
  • '; + $config['prev_tag_close'] = '
  • '; + + $config['next_link'] = 'NEXT'; $config['next_tag_open'] = '
  • '; $config['next_tag_close'] = '
  • '; - */ - $config['cur_tag_open'] = '
  • '; - $config['cur_tag_close'] = '
  • '; + + $config['cur_tag_open'] = '
  • '; + $config['cur_tag_close'] = '
  • '; $config['num_tag_open'] = '
  • '; $config['num_tag_close'] = '
  • '; - $config['num_links'] = 20; - $config['uri_segment'] = 4; + $config['num_links'] = 5; + $config['uri_segment'] = 4; + $this->pagination->initialize($config); $pages = $this->pagination->create_links(); - $content = $this->home->get_entry_cont('Name',$EntityName,$page_num, $results_per_page, $sortment); + + $content = $this->home->get_entry_cont('Name', $EntityName, $countryid, $page_num, $results_per_page, $sortment); //echo $this->uri->segment(4); exit; - // var_dump($content[0]); + $list = ''; if (is_array($content)){ - for($i=0;$i< count($content);$i++) - { - $list .= "
    ". $content[$i]['Name'] . "
    "; - } + /*if ((count($content))<15){ + for($i=0;$i". $content[$i]['Name'] . ""; + $k++; + } + + } else { */ + $k=0; + for($i=0;$i < count($content);$i++) { + if ($k==3){$k=0;} + $countryid = explode(',', $content[$i]['CountryID']); + //echo $countryid; exit; + $countries = $this->home->get_country($countryid); + //var_dump($countries);exit; + $list .= "
    +
    ". $content[$i]['Name'] . ""; + + foreach($countries as $country){ + $list .= ""; + } + $list .= "
    +
    "; + $k++; + } + if ($k!=3) { + $list .= "
     
    "; + } + //} + } $this->load->view('header',$data_head); @@ -232,191 +275,211 @@ function clean_array($arr){ } function tree($v0) { - $this->output->enable_profiler(TRUE); + //$this->output->enable_profiler(TRUE); $noMerge = $this->home->get_entries('ID',$v0); + //echo sizeof($noMerge); exit; - if(sizeof($noMerge)>=1){ - $v0 = ($noMerge[0]['Merged']==1)? $noMerge[0]['MergedTo'] : $v0; - - $MostVisited = $this->home->mostvisited($v0); - //var_dump($MostVisited); exit; - $weed = array(); - $fruit = array(); - $tree_n = array(); - $tree_e = array(); - $tree_d = array(); - $nFilter = ""; - $node_arr = ""; - $tree_ee = ""; - $tree_nn = ""; - $alpha = 1; - $nodes = "{"; - $edges = "{"; - - - $dta = $this->home->get_entries('ID',$v0); - $docs = explode(',', $dta[0]['DocID']); - $docs = $this->clean_array($docs); - //var_dump($docs); exit; - $e=0; - foreach($docs as $d){ - $doc = $this->home->get_doc($d); - //echo $e; - foreach($doc as $row){ - $dt=$row['data_table']; - $q=$row['representation']; - //$tree_data = ($dt == "") ? $this->tree_init($v0,$weed) : $this->dataset_extract($dt,$v0); - $tree_data = $this->dataset_extract($dt,$v0); - //array_push($tree_d,$tree_data); - - $tree_n[] = $tree_data['nodes']; - $tree_e[] = $tree_data['edges']; + if(sizeof($noMerge)>=1){ + $v0 = ($noMerge[0]['Merged']==1)? $noMerge[0]['MergedTo'] : $v0; + + $this->home->mostvisited($v0); + + $weed = array(); + $fruit = array(); + $tree_n = array(); + $tree_e = array(); + $tree_d = array(); + $nFilter = ""; + $node_arr = ""; + $tree_ee = ""; + $tree_nn = ""; + $core_node=""; + $alpha = 1; + $nodes = "{"; + $edges = "{"; + + + $dta = $this->home->get_entries('ID',$v0); + $docs = explode(',', $dta[0]['DocID']); + $docs = $this->clean_array($docs); + $docexist = $this->home->get_doc($docs); + //var_dump($docexist); exit; + $e=0; + foreach($docexist as $doc){ + //$doc = $this->home->get_doc($d); + //var_dump($doc); exit; + // foreach($doc as $row){ + $dt = $doc['data_table']; + $q = $doc['representation']; + //$tree_data = ($dt == "") ? $this->tree_init($v0,$weed) : $this->dataset_extract($dt,$v0); + // echo $dt; //exit; + $tree_data = $this->dataset_extract($dt,$v0); + // var_dump($tree_data); exit; + //array_push($tree_d,$tree_data); + if(!empty($tree_data)){ + $tree_n[] = $tree_data['nodes']; + + // } + if ($e==0){ + $tree_e[] = $tree_data['edges']; + $pos = strpos($tree_data['edges'],"{"); + $phrase = substr($tree_data['edges'], 0, $pos+1); + //echo $phrase; + $core_node = '\''. str_replace(' ','_',str_replace('/','',$tree_data['nodeTitle'])) . '_' .$v0 . '\''; + $nodetitle = $tree_data['nodeTitle']; + } else { + + $tree_e[] = str_replace($phrase,",",$tree_data['edges']); + } + $e++; + + + } + //$tree_n = array_merge_recursive($tree_n); + //$tree_e=array_merge_recursive($tree_e); + + } - } - if ($e==0){ - $pos = strpos($tree_e[0],"{"); - $phrase = substr($tree_e[0], 0, $pos+1); - } else { - $tree_e[$e] = str_replace($phrase,",",$tree_e[$e]); - } - //$tree_n = array_merge_recursive($tree_n); - //$tree_e=array_merge_recursive($tree_e); + if (!empty($tree_e)){ + //var_dump($tree_e); exit; + //$pos = strpos($tree_e[0],"{"); + //$phrase = substr($tree_e[0], 0, $pos+1); + //echo $phrase; exit; + + //$tree_n = $this->flatten($tree_n); + foreach ($tree_n as $value) { + if (!$tree_n) + { + $tree_nn = $value; + } + else + { + $tree_nn .= $value; + //echo $value; + } + } - $e++; - } - //$pos = strpos($tree_e[0],"{"); - //$phrase = substr($tree_e[0], 0, $pos+1); - //echo $phrase; - //var_dump($tree_e); exit; - //$tree_n = $this->flatten($tree_n); + foreach ($tree_e as $value) { + if (!$tree_e) + { + $tree_ee = $value; + } + else + { + $tree_ee .= $value; + //echo $value; + } + } + // - foreach ($tree_n as $value) - { - if (!$tree_n) - { - $tree_nn = $value; - } - else - { - $tree_nn .= $value; - //echo $value; - } - } - //echo($tree_nn); exit; - foreach ($tree_e as $value) - { - if (!$tree_e) - { - $tree_ee = $value; - } - else - { - $tree_ee .= $value; - //echo $value; - } - } - // - - $core_node = '\''. str_replace(' ','_',$tree_data['nodeTitle']) . '_' .$v0 . '\''; - $tree_ee = str_replace('},'.$core_node.':{','',$tree_ee); - $tree_ee = str_replace('},,','',$tree_ee); - //echo $core_node; - //echo($tree_ee); - //exit; - - - //var_dump($tree_data); exit; - $nodetitle = $tree_data['nodeTitle']; - $node_arr .= $tree_nn;//$tree_data['nodes']; - - $edges .= $tree_ee;//$tree_data['edges']; - //echo $edges; - $cid[22]= array('col'=>'#808f5a', 'shape'=>'rectangle', 'img'=>'people.png','selectedimg'=>'people-dark.png'); - $cid[21]= array('col'=>'#ff5000', 'shape'=>'dot', 'img'=> 'organisations.png', 'selectedimg'=> 'organisations-dark.png'); - $node_arr= $this->clean_array(explode(',',$node_arr)); - //var_dump($node_arr); - for($k=0; $khome->get_entries('ID',$id); - //$nID[$id] = $id; - //var_dump($nd); - if ( !isset($nDate[$id]) ) { - $nDate[$id] = array(); - } + ///$core_node = '\''. str_replace(' ','_',str_replace('/','',$tree_data['nodeTitle'])) . '_' .$v0 . '\''; + //echo $core_node; exit; + $tree_ee = str_replace('},'.$core_node.':{','',$tree_ee); + $tree_ee = str_replace('},,', '', $tree_ee); + $tree_ee = str_replace(',},', '}', $tree_ee); + //echo $core_node; + //echo($tree_ee); + //exit; + //echo $tree_ee; exit; + + //var_dump($tree_data); exit; + + + $node_arr .= $tree_nn;//$tree_data['nodes']; + + $edges .= $tree_ee;//$tree_data['edges']; + //echo $edges; + $cid[22]= array('col'=>'#808f5a', 'shape'=>'rectangle', 'img'=>'people.png','selectedimg'=>'people-dark.png'); + $cid[21]= array('col'=>'#ff5000', 'shape'=>'dot', 'img'=> 'organisations.png', 'selectedimg'=> 'organisations-dark.png'); + $node_arr= $this->clean_array(explode(',',$node_arr)); + //var_dump($node_arr); exit; + for($k=0; $khome->get_entries('ID',$id); + //$nID[$id] = $id; + //var_dump($n); exit; + if ( !isset($nDate[$id]) ) { + $nDate[$id] = array(); + } + + $nDate[$id][] = (isset($nd[$dataset]))? $nd[$dataset] : '' ; - $NodeName = explode(':',$n[0]['Name']); - $nFilter .= ($shape == 'dot' ) ? str_replace(",","",str_replace(".","", str_replace(" ","_", str_replace("  ","",str_replace("/","_",$NodeName[0]))))) . "_".$id ."," : null; - //echo($nFilter); - $ne=(int)$n[0]['EntityTypeID']; - //echo $col[$cid] . ' - '. $nd['ID'] .' '; + $NodeName = explode(':',$n[0]['Name']); + $nFilter .= ($shape == 'dot' ) ? str_replace(",","",str_replace(".","", str_replace(" ","_", str_replace("  ","",str_replace("/","_",$NodeName[0]))))) . "_".$id ."," : null; + //echo($nFilter); + $ne=((int)$n[0]['EntityTypeID']==0) ? '22': (int)$n[0]['EntityTypeID']; + //echo $col[$cid] . ' - '. $nd['ID'] .' '; - if(!isset($nID[$id])){ - $nID[$id] = array(); - $nodeid[]=$id; - //str_replace(",","",str_replace(".","",str_replace(" ","_",$NodeName[0]))) - $node_name = preg_replace('/[^a-z\d ]/i', '', $NodeName[0]); - $node_name = str_replace(' ','_',$node_name); - if($id == $v0){ - //$col='#FF0000'; - $node[$id][] = "'". $node_name . "_".$id ."':{'color':'#FF0000','shape':'".$shape ."', 'radius':30, 'alpha': ".$alpha.",'nodeid':'".$id."','image':'".$cid[$ne]['selectedimg']."','image_h':30,'link':'', 'label': '". $NodeName[0] ."'}"; - } else { - $node[$id][] = "'". $node_name . "_". $id ."':{'color':'". $cid[$ne]['col'] ."','shape':'". $shape ."', 'radius':30, 'alpha': ".$alpha.", 'nodeid':'".$id."','image':'".$cid[$ne]['img']."','image_h':30,'link':'','image_w':30, 'label': '". $NodeName[0] ."'}"; - } + if(!isset($nID[$id])){ + $nID[$id] = array(); + $node[$id] = array(); + $nodeid[]=$id; + //str_replace(",","",str_replace(".","",str_replace(" ","_",$NodeName[0]))) + $node_name = preg_replace('/[^a-z\d ]/i', '', $NodeName[0]); + $node_name = str_replace(' ','_',$node_name); + if($id == $v0){ + //$col='#FF0000'; + $node[$id][] = "'". $node_name . "_".$id ."':{'color':'#FF0000','shape':'".$shape ."', 'radius':30, 'alpha': ".$alpha.",'nodeid':'".$id."','image':'".$cid[$ne]['selectedimg']."','image_h':30,'link':'', 'label': '". $NodeName[0] ."'}"; + } else { + $node[$id][] = "'". $node_name . "_". $id ."':{'color':'". $cid[$ne]['col'] ."','shape':'". $shape ."', 'radius':30, 'alpha': ".$alpha.", 'nodeid':'".$id."','image':'".$cid[$ne]['img']."','image_h':30,'link':'','image_w':30, 'label': '". $NodeName[0] ."'}"; + } + // var_dump($node[$id]); - } + } - } - //var_dump($nodeid); - - - for($k=0; $k'; - //echo $edges; - //exit; - //$timeline = $this->timeline_data($v0); - - $vis_filter = $this->filter_data($node_arr); - //'events' => $timeline['events'], 'sections' => $timeline['sections'], - $content = array('edges' => $edges,'nodes' => $nodes,'error' => 'Entity Map', 'root' => $v0, 'node_title' => $nodetitle, 'filter_form'=> $vis_filter, 'hidden_nodes'=> $nFilter, 'nodeid'=> $v0); - - $data_head = array('page_title' => 'Visualisation'); + $nodes .= "}"; + $edges .= "}"; + $nFilter.= "}"; + $nodes = str_replace(",}","}",$nodes); + $edges = str_replace(",}","}",$edges); + $nFilter = str_replace(",}","",$nFilter); + //echo $nodes .'
    '; + //echo $edges; + //exit; + //$timeline = $this->timeline_data($v0); + + $vis_filter = $this->filter_data($node_arr); + //'events' => $timeline['events'], 'sections' => $timeline['sections'], + $content = array('edges' => $edges,'nodes' => $nodes,'error' => 'Entity Map', 'root' => $v0, 'node_title' => $nodetitle, 'filter_form'=> $vis_filter, 'hidden_nodes'=> $nFilter, 'nodeid'=> $v0); - $this->load->view('header',$data_head); - $this->load->view('home',$content); - $this->load->view('footer'); + $data_head = array('page_title' => 'Visualisation'); - } //-----end of size of v0 --------- - //$data_head = array('page_title' => 'Visualisation'); - else { - $this->index(); + $this->load->view('header',$data_head); + $this->load->view('home',$content); + $this->load->view('footer'); + } else { + $this->home->disable_entity($v0); + $this->index(); + //echo "no data"; + } + //-----end of size of v0 --------- + } else { + $this->index(); } } @@ -535,7 +598,7 @@ function tree_build($branch,$stem,$alpha, $filter){ $stm[] = $stem; //$edge_name = str_replace(".","",str_replace(" ","_",$root_Name[0])); $edge_name = preg_replace('/[^a-z\d ]/i', '', $root_Name[0]); - $edge_name = str_replace(' ','_',str_replace('/','_',$edge_name)); + $edge_name = str_replace(' ','_',str_replace('/','_',str_replace('\r','',$edge_name))); $edges .= "'" . $edge_name ."_". $stm[0] . "':{"; } // echo sizeof($branch). ','; @@ -551,17 +614,34 @@ function tree_build($branch,$stem,$alpha, $filter){ $edge_name = preg_replace('/[^a-z\d ]/i', '', $child_Name[0]); $edge_name = str_replace(' ','_',$edge_name); $edges .= "'". $edge_name ."_". $child[$i]['ID']."':{},"; - $node_array .= $child[$i]['ID'] .'|'. $branch[$k]['dataset'] .'|' . $alpha . '|1,' ; + $node_array .= ($child[$i]['ID']>1) ? $child[$i]['ID'] .'|'. $branch[$k]['dataset'] .'|' . $alpha . '|1,' :'' ; + $fruit[] = $child[$i]['ID']; } } - if($k==10) break; + if($k==20) break; } if ( isset($stm) ) { $edges .= "},"; unset($stm); } + $node_array = substr($node_array,0,-1); + if (sizeof(explode(',',$node_array))<2) { + + echo "Sorry for the inconvinience. The entity in question seems to have a disconnect. + An Emaill has been disptched to the adminstrator. Please check later."; + + $emailTo = 'bugs@openinstitute.com'; // Put your own email address here + $subject = 'Open Duka Entity Error'; + $headers = 'From: bugs@openinstitute.com' ; + $headers .='Reply-To: bugs@openinstitute.com'; + $body = 'Entity ID: '.$stem .' has issues. Please check'; + + mail($emailTo, $subject, $body, $headers); + sleep(5); + redirect('/'); + } //var_dump(explode(',',$node_array)); $tree['filter'] = $filter; $tree['node_arr'] = $node_array; @@ -581,32 +661,47 @@ function dataset_extract($dt,$v0){ $flds= array(); $ids = array(); $valz = array(); - + $tr = array(); $dta = $this->home->get_dataset_map($dt,$v0); -//var_dump($dta); exit; - foreach($dta as $k => $d){ - foreach($d as $j => $f){ $flds[]= $j; } - break; - } - foreach($flds as $f){ - for($i=0; $i $d){ + + foreach($d as $j => $f){ $flds[]= $j; } + + break; } - } - $ids = $this->clean_array($ids); - foreach ($ids as $i){ - if($i != $v0){ - $valz[] = array('ID'=>$i,'dataset'=>'0'); - } - } + foreach($flds as $f){ + + for($i=0; $itree_build($valz,$v0,1,0); - //var_dump($one); exit; - $nt = $this->home->get_entries('ID',$v0); - $nodetitle = $nt[0]['Name']; - $tr = array('nodes'=>$one['node_arr'], 'edges'=>$one['edges'], 'nodeTitle' => $nodetitle, 'alpha'=>1, 'filter'=>$one['filter']); + $ids = $this->clean_array($ids); + //var_dump($ids); exit; + foreach ($ids as $i){ + if($i != $v0){ + $valz[] = array('ID'=>$i,'dataset'=>'0'); + } + } + + $one = $this->tree_build($valz,$v0,1,0); + //var_dump($one); exit; + $nt = $this->home->get_entries('ID',$v0); + $nodetitle = $nt[0]['Name']; + $tr = array('nodes'=>$one['node_arr'], 'edges'=>$one['edges'], 'nodeTitle' => $nodetitle, 'alpha'=>1, 'filter'=>$one['filter']); + //var_dump($tr); exit; + } return $tr; } @@ -689,6 +784,7 @@ function node_data(){ $n = $_POST['node']; $doc = array(); + $Entity_id = array(); //$cont=""; //echo $n; //$cont = "

    ". $root_node[0]['Name'] ."  1

    "; @@ -700,74 +796,124 @@ function node_data(){ // $arraymap = explode(',',$child_node[0]['EntityMap']); foreach($docmap as $k => $d){ - + // echo $d; exit; if(!in_array($d, $doc)){ $doc[] = ($d != "") ? $d : null ; } } //} - + //var_dump($doc); exit; //var_dump($doc); echo sizeof($doc); exit; $extraData=""; + $extraNav=""; $maps= '{"data":[{"posts":['; //var_dump($root_node); + if(sizeof($doc)>0){ + $extraNav .= '
    '; + for($i=0; $ihome->get_entries('ID',$id); + //$c_node = $this->home->get_entries('ID',$id); + //var_dump($c_node); exit; $doc_ref = $doc[$i]; //$doc_ids = explode(',',$c_node[0]['DocID']); $d=0; - if ($doc_ref!= null){ - //$doc_ref = $doc_ids[$i]; $dataset = $this->home->get_doc($doc_ref); + foreach($dataset as $row){ $dt=$row['data_table']; + //echo $dt; $dtID=$row['DocTypeID']; $dataCat = $this->home->get_docType($dtID); - //echo $dt; + + + //var_dump($dataCat); + //echo $n; if($dt!=""){ $d=1; $ds=$row['representation']; $q = ($ds=="")? '*' : $ds; - + //echo $dt; $dta = $this->home->get_dataset($dt,$q,$n); - //var_dump($dta); + //var_dump($dta); exit; //$k = (sizeof($dta[0])>11) ? 1 : (int)(12/sizeof($dta[0])) ; //$i=1; - //echo sizeof($dta); - - $extraData .= '
    '.$dataCat[0]['DocTypeName'].'
    '; + //echo sizeof($dta); exit; + + if (sizeof($dta)!= 0){ + //$extraData .= '
    '; + $dtype= str_replace(' ', '',$dataCat[0]['DocTypeName']); + $extraData .= ''; $extraData .= ''; $extraData .= ''; foreach($dta[0] as $key => $val){ if (substr($key,-3,3)=='_E_') { + $Entity_id[]= $key; - } - else{ - $extraData .= ''; + + } else { + + $extraData .= ''; + } - } $extraData .= ''; - + //echo($extraData); exit; for($j=0; $j $val){ + $fieldname = $key .'_E_'; if (substr($key,-3,3)=='_E_') { //$kd=$key; - $extraData .= '' ; + // $extraData .= '' ; } else { - $extraData .= '' ; + //if ($this->home->fieldcheck($fieldname,$dt)){ + //$extraData .= '' ; + //} else { + $extraData .= '' ; + //} } //if($i==12){break;} //++$i; @@ -776,14 +922,15 @@ function node_data(){ } $extraData .= '
    '. str_replace("_"," ", $key) .''. str_replace("_"," ", $key) .'
    '. $val .''. $val .''. $val .''. str_replace("\r","", $val) .''. str_replace("\r","", $val) .'
    '; //echo $extraData; - } + } + } } - //$maps .= ' {"ID":"'. $c_node[0]['ID'] .'", "ExtraData":"'. htmlspecialchars($extraData) .'"},'; } } - $maps .= ' { "ExtraData":"'. htmlspecialchars($extraData) .'"}'; + $maps .= ' { "ExtraData":"'. htmlspecialchars(str_replace( "\n", "
    ",str_replace( "\t", "",$extraData))) .'"},'; + $maps .= ' { "ExtraNav":"'. htmlspecialchars(str_replace( "\n", "
    ",str_replace( "\t", "",$extraNav))) .'"}'; } //else { @@ -801,7 +948,6 @@ function node_data(){ $maps = str_replace(",}","}",$maps); //echo $maps; exit; echo json_encode($maps); - } @@ -845,7 +991,7 @@ function timeline_data($n){ function filter_data($var){ //var_dump($var); - $this->output->enable_profiler(false); + //$this->output->enable_profiler(false); $form_filter = $this->home->get_mapped_entries($var); $form_f =""; @@ -857,6 +1003,101 @@ function filter_data($var){ return $form_f; } + + function excelDownload($n) { + //$this->output->enable_profiler(true); + + $child_node = $this->home->get_node($n); + + $docmap = explode(',',$child_node[0]['DocID']); + + $docmap = $this->clean_array($docmap); + +//var_dump($docmap); exit; + // Starting the PHPExcel library + $this->load->library('PHPExcel'); + $this->load->library('PHPExcel/IOFactory'); + + $objPHPExcel = new PHPExcel(); + $objPHPExcel->getProperties()->setTitle("export")->setDescription("none"); + + + if(sizeof($docmap)>0){ + + for($i=0; $icreateSheet($i); //Setting index when creating + //$objWorkSheet = $objPHPExcel->getActiveSheet();//$objPHPExcel->getSheet($i); + $objPHPExcel->setActiveSheetIndex($i); + $table_name = $this->home->get_doc($docmap[$i]); + //var_dump($table_name); + $tbl = $table_name[0]['data_table']; + $objPHPExcel->getActiveSheet()->setTitle($tbl); + // echo $table_name[0]['representation']; exit; + $q = ($table_name[0]['representation'] == "") ? "*" : $table_name[0]['representation']; + //echo $n; + $query = $this->home->get_dataset($tbl,$q,$n); + //var_dump($query);exit; + // echo sizeof($query); exit; + + //if (sizeof($query)>0) { + for($j=0; $j $val){ + if (substr($key,-3,3)=='_E_') { + $Entity_id[]= $key; + } + else{ + $fields[] = $key;//str_replace("_"," ", $key) ; + } + } + //var_dump($fields); exit; + // Field names in the first row + $col = 0; + foreach ($fields as $field) + { + $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, 1, $field); + $col++; + } + + } + + // Fetching the table data + $row = 2; + //foreach($query[$j] as $key => $data){ + for($k=0; $k $fdata) + { + // echo $fdata; exit; + if (substr($field,-3,3)!='_E_') { + $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($col, $row, $fdata); + } + $col++; + } + $row++; + } + // Create a new worksheet, after the default sheet + //$objPHPExcel->createSheet($i); + } + } + } + $objWriter = IOFactory::createWriter($objPHPExcel, 'Excel5'); + // Sending headers to force the user to download the file + $filename='OpenDuka_'. $n .'.xls'; //save our workbook as this file name + header('Content-Type: application/vnd.ms-excel'); //mime type + header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name + header('Cache-Control: max-age=0'); //no cache + + $objWriter->save('php://output'); + + } } /* End of file posts.php */ diff --git a/application/controllers/trees.php b/application/controllers/trees.php index 93d6a10..2e9961f 100644 --- a/application/controllers/trees.php +++ b/application/controllers/trees.php @@ -11,74 +11,28 @@ function __construct() $this->load->model('tree'); } - - function index1($start=0) - { - $data_head = array('page_title' => 'Open Duka'); - $docs=array(); - $organisations = $this->tree->get_number_entity_group('21'); - $persons = $this->tree->get_number_entity_group(22); - $docTypes = $this->tree->get_dataset_count(); - - //echo serialize($docs); exit; - - $latestlist = $this->tree->get_latest_entry(); - $list=""; - if (is_array($latestlist)){ - for($i=0;$i< count($latestlist);$i++) - { - $list .= "
  • ". $latestlist[$i]['Name'] . "
  • "; - } - } - - $popularlist = $this->tree->get_popular_entry(); - $Plist=""; - if (is_array($popularlist)){ - for($i=0;$i< count($popularlist);$i++) - { - $Plist .= "
  • ". $popularlist[$i]['Name'] . "
  • "; - } - } - - for($i=0;$i< count($docTypes);$i++) - { - $docs= array_merge(array($docTypes[$i]['DocType'] => $docTypes[$i]['CatTot'], $docTypes[$i]['DocType'].'ID' => $docTypes[$i]['DocTypeID'] ), $docs); - } - $docs = array_merge(array('organisations' => $organisations, 'persons' => $persons,'latest_list' => $list,'popular_list' => $Plist,'error' => ''), $docs); -//var_dump($docs); exit; - $this->load->view('header',$data_head); - $this->load->view('home', $docs); - $this->load->view('footer'); - } - - - function clean_array($arr){ - //var_dump($arr); - $new_arr = array(); - if(is_array($arr)){ - $arr = array_unique($arr); - $arr = array_filter($arr); - - foreach ($arr as $val){ - $new_arr[] = $val; - } - } - return $new_arr; - } - function index($v0) { + //$this->output->enable_profiler(TRUE); //$n = $_POST['node']; + $noMerge = $this->tree->get_entries('ID',$v0); + + if(sizeof($noMerge)>=1){ $v0 = ($noMerge[0]['Merged']==1)? $noMerge[0]['MergedTo'] : $v0; $MostVisited = $this->tree->mostvisited($v0); - + //var_dump($MostVisited); exit; $weed = array(); $fruit = array(); + $tree_n = array(); + $tree_e = array(); + $tree_d = array(); $nFilter = ""; $node_arr = ""; + $tree_ee = ""; + $tree_nn = ""; $alpha = 1; $nodes = "{"; $edges = "{"; @@ -86,45 +40,102 @@ function index($v0) { $dta = $this->tree->get_entries('ID',$v0); $docs = explode(',', $dta[0]['DocID']); + $docs = $this->clean_array($docs); //var_dump($docs); exit; - + $e=0; foreach($docs as $d){ $doc = $this->tree->get_doc($d); - + //echo $e; foreach($doc as $row){ $dt=$row['data_table']; $q=$row['representation']; - - $tree_data = ($dt == "") ? $this->tree_init($v0,$weed) : $this->dataset_extract($dt,$v0); - + //$tree_data = ($dt == "") ? $this->tree_init($v0,$weed) : $this->dataset_extract($dt,$v0); + $tree_data = $this->dataset_extract($dt,$v0); + //array_push($tree_d,$tree_data); + + $tree_n[] = $tree_data['nodes']; + $tree_e[] = $tree_data['edges']; + } - //var_dump($tree_data); exit; + if ($e==0){ + $pos = strpos($tree_e[0],"{"); + $phrase = substr($tree_e[0], 0, $pos+1); + } else { + $tree_e[$e] = str_replace($phrase,",",$tree_e[$e]); + } + //$tree_n = array_merge_recursive($tree_n); + //$tree_e=array_merge_recursive($tree_e); + + + $e++; } + //$pos = strpos($tree_e[0],"{"); + //$phrase = substr($tree_e[0], 0, $pos+1); + //echo $phrase; + //var_dump($tree_e); exit; + //$tree_n = $this->flatten($tree_n); + foreach ($tree_n as $value) + { + if (!$tree_n) + { + $tree_nn = $value; + } + else + { + $tree_nn .= $value; + //echo $value; + } + } + + foreach ($tree_e as $value) + { + if (!$tree_e) + { + $tree_ee = $value; + } + else + { + $tree_ee .= $value; + //echo $value; + } + } + // + + $core_node = '\''. str_replace(' ','_',str_replace('/','',$tree_data['nodeTitle'])) . '_' .$v0 . '\''; + //echo($core_node); exit; + $tree_ee = str_replace('},'.$core_node.':{','',$tree_ee); + $tree_ee = str_replace('},,', '', $tree_ee); + $tree_ee = str_replace(',},', '}', $tree_ee); + //echo $core_node; + //echo($tree_ee); //exit; +//echo $tree_ee; exit; //var_dump($tree_data); exit; + $nodetitle = $tree_data['nodeTitle']; - $node_arr = $tree_data['nodes']; - $edges .= $tree_data['edges']; + $node_arr .= $tree_nn;//$tree_data['nodes']; + $edges .= $tree_ee;//$tree_data['edges']; + //echo $edges; $cid[22]= array('col'=>'#808f5a', 'shape'=>'rectangle', 'img'=>'people.png','selectedimg'=>'people-dark.png'); $cid[21]= array('col'=>'#ff5000', 'shape'=>'dot', 'img'=> 'organisations.png', 'selectedimg'=> 'organisations-dark.png'); $node_arr= $this->clean_array(explode(',',$node_arr)); -//var_dump($node_arr); + //var_dump($node_arr); exit; for($k=0; $ktree->get_entries('ID',$id); //$nID[$id] = $id; - //$nd = explode('||',$n[0]['EffectiveDate']); - //var_dump($nd); + //var_dump($n); exit; if ( !isset($nDate[$id]) ) { $nDate[$id] = array(); } @@ -132,20 +143,25 @@ function index($v0) { $nDate[$id][] = (isset($nd[$dataset]))? $nd[$dataset] : '' ; $NodeName = explode(':',$n[0]['Name']); - $nFilter .= ($shape == 'dot' ) ? str_replace(",","",str_replace(".","",str_replace(" ","_",$NodeName[0]))) . "_".$id ."," : null; - //echo($NodeName[0]); - $ne=(int)$n[0]['EntityTypeID']; + $nFilter .= ($shape == 'dot' ) ? str_replace(",","",str_replace(".","", str_replace(" ","_", str_replace("  ","",str_replace("/","_",$NodeName[0]))))) . "_".$id ."," : null; + //echo($nFilter); + $ne=((int)$n[0]['EntityTypeID']==0) ? '22': (int)$n[0]['EntityTypeID']; //echo $col[$cid] . ' - '. $nd['ID'] .' '; if(!isset($nID[$id])){ $nID[$id] = array(); + $node[$id] = array(); $nodeid[]=$id; + //str_replace(",","",str_replace(".","",str_replace(" ","_",$NodeName[0]))) + $node_name = preg_replace('/[^a-z\d ]/i', '', $NodeName[0]); + $node_name = str_replace(' ','_',$node_name); if($id == $v0){ //$col='#FF0000'; - $node[$id][] = "'". str_replace(",","",str_replace(".","",str_replace(" ","_",$NodeName[0]))) . "_".$id ."':{'color':'#FF0000','shape':'".$shape ."', 'radius':30, 'alpha': ".$alpha.",'nodeid':'".$id."','image':'".$cid[$ne]['selectedimg']."','image_h':30,'link':'', 'label': '". $NodeName[0] ."'}"; + $node[$id][] = "'". $node_name . "_".$id ."':{'color':'#FF0000','shape':'".$shape ."', 'radius':30, 'alpha': ".$alpha.",'nodeid':'".$id."','image':'".$cid[$ne]['selectedimg']."','image_h':30,'link':'', 'label': '". $NodeName[0] ."'}"; } else { - $node[$id][] = "'". str_replace(".","",str_replace(" ","_",$NodeName[0])) . "_". $id ."':{'color':'". $cid[$ne]['col'] ."','shape':'". $shape ."', 'radius':30, 'alpha': ".$alpha.", 'nodeid':'".$id."','image':'".$cid[$ne]['img']."','image_h':30,'link':'','image_w':30, 'label': '". $NodeName[0] ."'}"; - } + $node[$id][] = "'". $node_name . "_". $id ."':{'color':'". $cid[$ne]['col'] ."','shape':'". $shape ."', 'radius':30, 'alpha': ".$alpha.", 'nodeid':'".$id."','image':'".$cid[$ne]['img']."','image_h':30,'link':'','image_w':30, 'label': '". $NodeName[0] ."'}"; + } + // var_dump($node[$id]); } @@ -177,20 +193,78 @@ function index($v0) { $vis_filter = $this->filter_data($node_arr); //'events' => $timeline['events'], 'sections' => $timeline['sections'], - $content = array('edges' => $edges,'nodes' => $nodes,'error' => 'Entity Map', 'root' => $v0, 'node_title' => $nodetitle, 'filter_form'=> $vis_filter, 'hidden_nodes'=> $nFilter); - - $data_head = array('page_title' => 'Visualisation'); - + $content = array('edges' => $edges,'nodes' => $nodes,'error' => 'Entity Map', 'root' => $v0, 'node_title' => $nodetitle, 'filter_form'=> $vis_filter, 'hidden_nodes'=> $nFilter, 'nodeid'=> $v0); + + $data_head = array('page_title' => 'Visualisation'); + $this->load->view('header_entity',$data_head); $this->load->view('tree',$content); $this->load->view('footer_entity'); + + } //-----end of size of v0 --------- + //$data_head = array('page_title' => 'Visualisation'); + + } + + function index1($start=0) + { + $data_head = array('page_title' => 'Open Duka'); + $docs=array(); + $organisations = $this->tree->get_number_entity_group('21'); + $persons = $this->tree->get_number_entity_group(22); + $docTypes = $this->tree->get_dataset_count(); + + //echo serialize($docs); exit; + + $latestlist = $this->tree->get_latest_entry(); + $list=""; + if (is_array($latestlist)){ + for($i=0;$i< count($latestlist);$i++) + { + $list .= "
  • ". $latestlist[$i]['Name'] . "
  • "; + } + } + $popularlist = $this->tree->get_popular_entry(); + $Plist=""; + if (is_array($popularlist)){ + for($i=0;$i< count($popularlist);$i++) + { + $Plist .= "
  • ". $popularlist[$i]['Name'] . "
  • "; + } + } + + for($i=0;$i< count($docTypes);$i++) + { + $docs= array_merge(array($docTypes[$i]['DocType'] => $docTypes[$i]['CatTot'], $docTypes[$i]['DocType'].'ID' => $docTypes[$i]['DocTypeID'] ), $docs); + } + $docs = array_merge(array('organisations' => $organisations, 'persons' => $persons,'latest_list' => $list,'popular_list' => $Plist,'error' => ''), $docs); +//var_dump($docs); exit; + $this->load->view('header',$data_head); + $this->load->view('home', $docs); + $this->load->view('footer'); + } + + + function clean_array($arr){ + //var_dump($arr); + $new_arr = array(); + if(is_array($arr)){ + $arr = array_unique($arr); + $arr = array_filter($arr); + + foreach ($arr as $val){ + $new_arr[] = $val; + } + } + return $new_arr; } + function tree_init($v0,$weed){ $edges = ""; - $one = $this->tree_schema($v0, $weed,"1"); + $one = $this->tree_schema($v0, $weed,"1","1"); $nodetitle = $one['nodetitle']; //$weed = $one['weed']; @@ -202,7 +276,7 @@ function tree_init($v0,$weed){ //echo sizeof($one['fruit']); if (sizeof($one['fruit'])>0) { for($i=0; $i< (sizeof($one['fruit'])); $i++){ - $two = $this->tree_schema($one['fruit'][$i],$weed,"1"); + $two = $this->tree_schema($one['fruit'][$i],$weed,"1","1"); array_push($weed, $one['fruit'][$i]); //var_dump($two); exit; $edges .= $two['edges']; @@ -211,7 +285,7 @@ function tree_init($v0,$weed){ //echo 'tuko '. var_dump($weed) .'second array';exit; for($j=0; $j< (sizeof($two['fruit'])); $j++){ - $three = $this->tree_schema($two['fruit'][$j], $weed,"0"); + $three = $this->tree_schema($two['fruit'][$j], $weed,"0","1"); //array_push($weed, $two['fruit'][$i]); $edges .= $three['edges']; $node_arr .= $three['nodearray']; @@ -232,14 +306,14 @@ function tree_init($v0,$weed){ } - function tree_schema($v, $weed,$alpha){ + function tree_schema($v, $weed,$alpha, $filter){ $fruit= array(); $valz = array(); $node_array = "";//$node_arr . ','; $nodes = ""; $edges = ""; //$node_arr = $this->clean_array($node_arr); - $child0_ = $this->tree->get_entries('ID',$v); + $child0_ = $this->home->get_entries('ID',$v); $nodetitle = $child0_[0]['Name']; $child0 = explode(',',$child0_[0]['EntityMap']); //var_dump($v); @@ -262,7 +336,7 @@ function tree_schema($v, $weed,$alpha){ } // var_dump($valz); //echo count($valz);//exit; - $tree = $this->tree_build($valz,$v,$alpha); + $tree = $this->tree_build($valz,$v,$alpha,$filter); $node_array = $tree['node_arr']; $edges = $tree['edges']; $fruit = $tree['fruit']; @@ -273,6 +347,7 @@ function tree_schema($v, $weed,$alpha){ $level= array(); $level['nodetitle']=$nodetitle; $level['nodearray']= $node_array; + $level['filter']=$filter; $level['alpha']=$alpha; $level['edges']=$edges; $level['fruit']=$fruit; @@ -281,7 +356,8 @@ function tree_schema($v, $weed,$alpha){ } - function tree_build($branch,$stem,$alpha){ + + function tree_build($branch,$stem,$alpha, $filter){ //var_dump($branch);// exit; //echo $stem; exit; $fruit= array(); @@ -296,11 +372,13 @@ function tree_build($branch,$stem,$alpha){ $edges = ""; //echo sizeof($branch); // echo (!in_array(array($stem), explode(',',$node_array)))? 'true - '.$stem: 'false'; - $node_array = $stem . '|0 |' . $alpha.','; + $node_array = $stem . '|0|' . $alpha.'|0,'; if ( !isset($stm) ) { $stm[] = $stem; - $edges .= "'" . str_replace(".","",str_replace(" ","_",$root_Name[0]))."_". $stm[0] . "':{"; - + //$edge_name = str_replace(".","",str_replace(" ","_",$root_Name[0])); + $edge_name = preg_replace('/[^a-z\d ]/i', '', $root_Name[0]); + $edge_name = str_replace(' ','_',str_replace('/','_',$edge_name)); + $edges .= "'" . $edge_name ."_". $stm[0] . "':{"; } // echo sizeof($branch). ','; for($k=0;$ktree->get_dataset_map($dt,$v0); //var_dump($dta); exit; foreach($dta as $k => $d){ + foreach($d as $j => $f){ $flds[]= $j; } + break; } foreach($flds as $f){ + for($i=0; $iclean_array($ids); + $ids = $this->clean_array($ids); + //var_dump($ids); exit; foreach ($ids as $i){ if($i != $v0){ $valz[] = array('ID'=>$i,'dataset'=>'0'); } } - $one = $this->tree_build($valz,$v0,1); + $one = $this->tree_build($valz,$v0,1,0); //var_dump($one); exit; $nt = $this->tree->get_entries('ID',$v0); $nodetitle = $nt[0]['Name']; - $tr = array('nodes'=>$one['node_arr'], 'edges'=>$one['edges'], 'nodeTitle' => $nodetitle); + $tr = array('nodes'=>$one['node_arr'], 'edges'=>$one['edges'], 'nodeTitle' => $nodetitle, 'alpha'=>1, 'filter'=>$one['filter']); return $tr; } diff --git a/application/controllers/user.php b/application/controllers/user.php index fc9e15d..d5198db 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -12,13 +12,13 @@ public function index() { if(($this->session->userdata('user_name')!="")) { - redirect('/admin'); + redirect('/bckend'); } else{ $data['page_title']= 'Home'; $this->load->view('header',$data); $this->load->view("registration_view.php", $data); - $this->load->view('footer',$data); + } } public function login() @@ -26,15 +26,18 @@ public function login() $email=$this->input->post('email'); $password=md5($this->input->post('pass')); $result=$this->user_model->login($email,$password); - if($result) redirect('/admin'); + if($result) redirect('/bckend'); else $this->index(); } public function thank() { - $data['page_title']= 'Thank'; - $this->load->view('header',$data); - $this->load->view('admin.php', $data); - $this->load->view('footer',$data); + $data['page_title']= 'Successful'; + $this->load->view('header',$data); + $this->load->view('headerbck'); + $this->load->view('sidebar_bck'); + $this->load->view('addUser'); + + } public function registration() diff --git a/application/models/admin_model.php b/application/models/admin_model.php index d644da9..ddaac4b 100644 --- a/application/models/admin_model.php +++ b/application/models/admin_model.php @@ -19,7 +19,6 @@ function get_document_ref($DocName) $this->db->from('DocUploaded'); $this->db->where('title', trim($DocName)); $query = $this->db->get(); - return $query->result_array(); } @@ -38,7 +37,17 @@ function get_document_entry($DocName) return null; } - + function get_document_details($DocID) + { + + $this->db->select(); + $this->db->from('DocUploaded'); + $this->db->where('ID ', $DocID); + $query = $this->db->get(); + return $query->result_array(); + + } + function insert_document($DocName, $DocType=1) { @@ -166,7 +175,7 @@ function get_gazID($gazID) $this->db->order_by("ID", "desc"); $query1 = $this->db->get(); - return $query1->result_array(); + return $query1->result_array(); } return null; @@ -187,12 +196,12 @@ function get_entity($ID) function update_entity($data) { - $this->db->where('ID', $data['ID']); + $this->db->where('ID', $data['ID']); $this->db->update('Entity', $data); } - function get_entries($tag,$var) + function get_entries($tag, $var) { $this->db->select(); $this->db->from($tag); @@ -336,11 +345,10 @@ function get_doctype() function fieldcheck($fil,$tab) { - if(!$this->db->field_exists($fil.'_E_',$tab)){ - $fieldname = $fil.'_E_'; - $this->db->query("ALTER TABLE $tab ADD COLUMN $fieldname VARCHAR(250)"); - } - + $fieldname = $fil .'_E_'; + if(!$this->db->field_exists($fieldname,$tab)){ + $this->db->query("ALTER TABLE $tab ADD COLUMN `$fieldname` VARCHAR(250) NOT NULL DEFAULT '0,'"); + } } function create_table($tbl, $flds) @@ -352,7 +360,7 @@ function create_table($tbl, $flds) function alter_table($fild,$tbl) { if(!$this->db->field_exists($fild,$tbl)){ - $this->db->query("ALTER TABLE $tbl ADD COLUMN $fild VARCHAR(250)"); + $this->db->query("ALTER TABLE $tbl ADD COLUMN `$fild` VARCHAR(250)"); } } @@ -371,34 +379,85 @@ function table_name_change($orig_name,$new_name) function populate_table($query) { - return $this->db->query($query); + return $this->db->query($query); } function dataset_edit($tbl, $rep) { $this->db->where('data_table', $tbl); - $this->db->set('representation', $rep, FALSE); - $this->db->update('DocUploaded'); + $this->db->set('representation', $rep, FALSE); + $this->db->update('DocUploaded'); } - function extract_entity($fild,$tab,$docid, $UID, $DocTypeID) + function extract_entity($fild,$tab,$docid, $UID, $DocTypeID,$CountryID) { - $fieldname = $fild.'_E_'; - $this->db->select($fild); - $this->db->distinct(); - $this->db->from($tab); - $this->db->where($fieldname,'0'); - $query = $this->db->get(); + $fieldname = $fild .'_E_'; + // echo "SELECT * FROM $tab WHERE `$fieldname` LIKE '0,'"; exit; + $query = $this->db->query("SELECT DISTINCT * FROM $tab WHERE `$fieldname` = '0,'"); + //$this->db->select(); + //$this->db->distinct(); + //$this->db->from($tab); + //$this->db->where($fieldname,); + //$query = $this->db->get(); $k=0; - if ($query->num_rows() > 0) - { - $entity=$query->result_array(); - for($i=0;$i<$query->num_rows(); $i++) - { + if ($query->num_rows() > 0) + { + $q=$query->result_array(); +//var_dump($q); exit; + for($i=0;$idb->select(); + $this->db->from('Entity'); + $this->db->where('Name', trim($entity)); + $this->db->where('Merged', 0); + $this->db->limit(1); + $query = $this->db->get(); + if ($query->num_rows() > 0) { + $Entity = $query->result_array(); + $EID .= $Entity[0]['ID'] .','; + //$docs = explode(',', $Entity[0]['DocID']; + $docid = $Entity[0]['DocID'] . $docid; + $docids= $this->clean_array(explode(',', $docid)); + + $doctypeid = $Entity[0]['DocTypeID'] . $DocTypeID; + $doctypeids= $this->clean_array(explode(',', $doctypeid)); + + $countryid = $Entity[0]['CountryID'] . $CountryID; + $countryids= $this->clean_array(explode(',', $countryid)); + + $this->db->set('DocTypeID', implode(',', $doctypeids) .','); + $this->db->set('DocID', implode(',', $docids) .','); + $this->db->set('CountryID', implode(',', $countryids) .','); + $this->db->set('CleanEntity', '1'); + $this->db->where('ID', $Entity[0]['ID']); + $this->db->update('Entity'); + } else { + + $data['DocID'] = $docid .","; + $data['DocTypeID'] = $DocTypeID .","; + $data['CountryID'] = $CountryID .","; + $data['CleanEntity'] = '1'; + $data['Name'] = trim($entity); + $this->db->insert('Entity', $data); + $EID .= $this->db->insert_id() .','; + } + } + $k++; + } + + $this->db->query("UPDATE $tab SET `$fieldname` = CONCAT(`". $fieldname."`,'". $EID ."') WHERE id =". $q[$i]['id'] ); + //exit; + } + + /* // echo($entity[2][$fild]); exit; $data['DocID'] = $docid . ","; @@ -416,11 +475,26 @@ function extract_entity($fild,$tab,$docid, $UID, $DocTypeID) $this->db->where($fild, $entity[$i][$fild]); $this->db->update($tab, $dta); $k++; - } - } + } */ + } return $k; } + + function clean_array($arr){ + //var_dump($arr); + $new_arr = array(); + if(is_array($arr)){ + $arr = array_unique($arr); + $arr = array_filter($arr); + + foreach ($arr as $val){ + $new_arr[] = $val; + } + } + return $new_arr; + } + } diff --git a/application/models/api_m.php b/application/models/api_m.php index e584892..cbd6e27 100644 --- a/application/models/api_m.php +++ b/application/models/api_m.php @@ -87,7 +87,7 @@ function get_entry_cont($tag,$entityname) function get_entries($field,$var) { - $this->db->where($field,$var); + $this->db->where($field,$var); $this->db->select(); $this->db->from('Entity'); $this->db->where('Merged', 0); @@ -125,10 +125,11 @@ function get_doc($docid) //} else {return '';} } - function get_dataset($tbl,$q,$id) + function get_dataset($tbl,$q,$id) { $ar=array(); $ra=array(); + $c=0; $flds = $this->db->field_data($tbl); foreach($flds as $f ) { if (substr($f->name,-3,3)=='_E_') { @@ -139,13 +140,30 @@ function get_dataset($tbl,$q,$id) $Entity_field[]= $f->name; } $qu = ($q=='*') ? implode(',',$Entity_field) : $q .','. implode(',',$Entity_id); - // echo $qu; + // echo $qu; $this->db->select($qu); $this->db->from($tbl); $this->db->limit(50); - foreach($Entity_id as $r){ - $this->db->or_where($r,$id); - } + + foreach($Entity_id as $f ) { + //echo $f; exit; + if (substr($f,-3,3)=='_E_') { + // $Entity_id[]= $f->name; + + if ($c==0) { + //$l = "where `".$f->name."` LIKE '%,".$id.",%'"; + $this->db->like($f,$id); + } else { + //$l .= " or `". $f->name. "` LIKE '%,".$id.",%'"; + $this->db->or_like($f,$id); + } + $c++; + } + } + + //foreach($Entity_id as $r){ + // $this->db->or_where($r,$id); + //} $query = $this->db->get(); return $query->result_array(); } diff --git a/application/models/home.php b/application/models/home.php index ca33f64..0829420 100644 --- a/application/models/home.php +++ b/application/models/home.php @@ -17,6 +17,7 @@ function get_number_entity_group($var) $this->db->select(); $this->db->from('Entity'); + $this->db->where('CleanEntity',1); $this->db->where('EntityTypeID', $var); // $query = $this->db->get(); return $this->db->count_all_results(); @@ -34,8 +35,9 @@ function get_dataset_count() //var_dump($cats); for($f=0; $fdb->select(); + $this->db->select(); $this->db->from('Entity'); + $this->db->where('CleanEntity',1); $this->db->like('DocTypeID', $cats[$f]['ID'].','); $catCount = $this->db->count_all_results(); @@ -51,8 +53,9 @@ function get_latest_entry() $this->db->select(); $this->db->from('Entity'); $this->db->order_by('ID','desc'); + $this->db->where('CleanEntity',1); $this->db->where('Merged', '0'); - $this->db->limit(10); + $this->db->limit(15); $query = $this->db->get(); return $query->result_array(); } @@ -61,8 +64,9 @@ function get_popular_entry() { $this->db->select(); $this->db->from('Entity'); + $this->db->where('CleanEntity',1); $this->db->order_by('MostVisited','desc'); - $this->db->limit(10); + $this->db->limit(15); $query = $this->db->get(); return $query->result_array(); } @@ -109,9 +113,11 @@ function insert_entity($tag, $data,$docid) function get_entries($field,$var) { + // var_dump($var); exit; is_array($var) ? $this->db->where_in($field,$var) : $this->db->where($field,$var); $this->db->select(); $this->db->from('Entity'); + $this->db->where('CleanEntity',1); $this->db->where('Merged', 0); //$this->db->limit(10); //if($this->db->count_all_results()>0){ @@ -139,7 +145,7 @@ function get_node($nodeid) is_array($nodeid) ? $this->db->where_in('ID',$nodeid) : $this->db->where('ID',$nodeid); $this->db->select(); - $this->db->from('Entity'); + $this->db->from('Entity'); //if (is_array($nid)){ echo 'true';} else { echo 'false';} /*if (is_array($nid)){ @@ -183,14 +189,19 @@ function get_node($nodeid) // "SELECT `ID`,EntityMap, Verb FROM `Entity` where `EntityMap` like '2717,%' or `EntityMap` like '%,2717,%' or `EntityMap` like ',2717|%' or `EntityMap` like '%|2717|%' or `EntityMap` like '%|2717' or `EntityMap` like '2717|%'" } - function get_entry_cont($tag,$entityname,$page_num=1, $results_per_page=15,$sortment) + function get_entry_cont($tag,$entityname, $countryid,$page_num=1, $results_per_page=15,$sortment) { - if ($page_num < 1) - { - $page_num = 1; + if ($page_num < 1) { $page_num = 1; } + + if ($sortment=="") {$sortment="";} else {$sortment = " AND Name like '$sortment%'";} + + if ($countryid ==0) { $cid = ""; } else { $cid = " AND countryid = ". $countryid; } + + if ($entityname=="") { + $result = $this->db->query("SELECT * FROM Entity WHERE CleanEntity=1 AND Merged=0 $cid $sortment ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); + } else { + $result = $this->db->query("SELECT * FROM Entity WHERE $tag LIKE '$entityname%' AND CleanEntity=1 AND Merged=0 $cid $sortment ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); } - - $result = $this->db->query("SELECT * FROM Entity WHERE $tag LIKE '%$entityname%' AND Merged=0 AND Name like '$sortment%' ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); return $query = $result->result_array(); } @@ -201,7 +212,7 @@ function get_entry_cont2($tag,$entityname,$page_num=1, $results_per_page=15, $so { $page_num = 1; } - $result = $this->db->query("SELECT * FROM Entity WHERE $tag like '$entityname,%' AND Name like '$sortment%' OR $tag like '%,$entityname,%' AND Name like '$sortment%' ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); + $result = $this->db->query("SELECT * FROM Entity WHERE $tag like '$entityname,%' AND Name like '$sortment%' OR $tag like '%,$entityname,%' AND CleanEntity=1 AND Name like '$sortment%' ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); return $query = $result->result_array(); } @@ -213,24 +224,28 @@ function get_entry_cont3($tag,$entityname,$page_num=1, $results_per_page=15, $so $page_num = 1; } - $result = $this->db->query("SELECT * FROM Entity WHERE $tag = $entityname AND Name like '$sortment%' ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); + $result = $this->db->query("SELECT * FROM Entity WHERE $tag = $entityname AND CleanEntity=1 AND Name like '$sortment%' ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); return $query = $result->result_array(); } function get_entry_count($tag,$entityname){ - $this->db->select(); + $this->db->select(); $this->db->from('Entity'); - $this->db->like($tag,$entityname); + $this->db->where('CleanEntity',1); + if ($entityname!=""){ + $this->db->like($tag,$entityname,'after'); + } $query = $this->db->get(); return $query->num_rows(); } function get_entry_count_b($tag,$entityname,$tag2, $sortment){ - $this->db->select(); + $this->db->select(); $this->db->from('Entity'); $this->db->where($tag,$entityname); + $this->db->where('CleanEntity',1); $this->db->like($tag2,$sortment,'after'); $query = $this->db->get(); return $query->num_rows(); @@ -241,6 +256,7 @@ function get_entry2($tag,$docid) $this->db->select(); $this->db->from($tag); $this->db->where('DocID',$docid); + $this->db->limit(6); $query = $this->db->get(); return $query->result_array(); @@ -249,10 +265,10 @@ function get_entry2($tag,$docid) function get_doc($docid) { - //is_array($var) ? $this->db->where_in($field,$var) : $this->db->where($field,$var); + is_array($docid) ? $this->db->where_in('ID',$docid) : $this->db->where('ID', $docid); $this->db->select(); $this->db->from('DocUploaded'); - $this->db->where('ID', $docid); + //$this->db->where('ID', $docid); //if($this->db->count_all_results()>0){ $query = $this->db->get(); return $query->result_array(); @@ -268,23 +284,28 @@ function get_dataset($tbl,$q,$id) $flds = $this->db->field_data($tbl); foreach($flds as $f ) { if (substr($f->name,-3,3)=='_E_') { - // $Entity_id[]= $f->name; + $Entity_id_E_[]= $f->name; - if ($c==0) { - $l = "where ".$f->name." LIKE '%".$qid."%'"; - } else { - $l .= " or ". $f->name. " LIKE '%".$qid."%'"; - } + if ($c==0) { + $l = "WHERE `". $f->name . "` LIKE '%,".$qid.",%'"; + } else { + $l .= " OR `". $f->name . "` LIKE '%,".$qid.",%'"; + } $c++; - } else { + } + /*else { $Entity_field[]= $f->name; - } - //$Entity_field[]= $f->name; - } - $qu = ($q=='*') ? implode(',',$Entity_field) : $q ; - //echo $qid; - $result = $this->db->query("SELECT $qu FROM $tbl $l "); - return $query = $result->result_array(); + }*/ + $Entity_field[]= $f->name; + } + //echo $l; + $qu = ($q=='*') ? implode(',',$Entity_field) : $q .','. implode(',', $Entity_id_E_) ; + $data ="SELECT $qu FROM $tbl $l "; + //echo $data; exit; + $result = $this->db->query( $data ); + // var_dump($result); + return $result->result_array(); + /*$this->db->select($qu); $this->db->from($tbl); $this->db->limit(50); @@ -308,18 +329,19 @@ function get_dataset_map($tbl, $id) $flds = $this->db->field_data($tbl); foreach($flds as $f ) { if (substr($f->name,-3,3)=='_E_') { - $Entity_name .= $f->name .","; - if ($c==0) { - $l = "where ".$f->name." LIKE '%".$id."%'"; - } else { - $l .= " or ". $f->name. " LIKE '%".$id."%'"; - } + $Entity_name .= "`". $f->name ."`,"; + if ($c==0) { + $l = "where `".$f->name."` LIKE '%," . $id . ",%'"; + } else { + $l .= " or `". $f->name. "` LIKE '%," . $id . ",%'"; + } $c++; - } - } - // echo $Entity_name ; - $Entity_name = substr($Entity_name,0,-1); - $result = $this->db->query("SELECT $Entity_name FROM $tbl $l "); + } + } + + $Entity_name = substr($Entity_name,0,-1); + // echo "SELECT $Entity_name FROM $tbl $l " ; exit; + $result = $this->db->query("SELECT $Entity_name FROM $tbl $l "); return $query = $result->result_array(); } @@ -342,5 +364,29 @@ function get_docType($id) return $query->result_array(); //} else {return '';} } + + function get_country($cid) + { + + is_array($cid) ? $this->db->where_in('CountryID',$cid) : $this->db->where('CountryID',$cid); + $this->db->select(); + + $this->db->from('Country'); + + $query = $this->db->get(); + return $query->result_array(); + } + + function disable_entity($id) { + $this->db->where('ID', $id); + $this->db->set('CleanEntity', '0',FALSE); + $this->db->update('Entity'); + } + + function fieldcheck($fil,$tab) + { + return $this->db->field_exists($fil,$tab); + + } } diff --git a/application/models/tree.php b/application/models/tree.php index a16c09e..959c7ad 100644 --- a/application/models/tree.php +++ b/application/models/tree.php @@ -23,7 +23,7 @@ function get_number_entity_group($var) //} else {return '';} } - function get_dataset_count() + function get_dataset_count() { $ar=array(); $this->db->select(); @@ -46,7 +46,7 @@ function get_dataset_count() } - function get_latest_entry() + function get_latest_entry() { $this->db->select(); $this->db->from('Entity'); @@ -116,11 +116,12 @@ function get_entries($field,$var) //$this->db->limit(10); //if($this->db->count_all_results()>0){ $query = $this->db->get(); + // $this->db->_error_message(); return $query->result_array(); //} else {return '';} } - function get_mapped_entries($var) + function get_mapped_entries($var) { is_array($var) ? $this->db->where_in('Entity.ID',$var) : $this->db->where('Entity.ID',$var); $this->db->select('EntityType.EntityTypeID, EntityType.EntityType'); @@ -137,48 +138,10 @@ function get_node($nodeid) is_array($nodeid) ? $this->db->where_in('ID',$nodeid) : $this->db->where('ID',$nodeid); $this->db->select(); $this->db->from('Entity'); - //if (is_array($nid)){ echo 'true';} else { echo 'false';} - /*if (is_array($nid)){ - $this->db->select(); - $this->db->from('Entity'); - foreach($nid as $nodeid ) { - $where = "EntityMap like '$nodeid|%' AND Merged = 0"; - $where .= " OR EntityMap like '$nodeid,%' AND Merged = 0"; - $where .= " OR EntityMap like '%,$nodeid,%' AND Merged = 0"; - $where .= " OR EntityMap like '%|$nodeid,%' AND Merged = 0"; - $where .= " OR EntityMap like '%|$nodeid|%' AND Merged = 0"; - $where .= " OR EntityMap like '%,$nodeid|%' AND Merged = 0"; - $where .= " OR EntityMap like '%|$nodeid' AND Merged = 0"; - } - $this->db->where($where); - $query = $this->db->get(); - return $query->result_array(); - } else { - - $this->db->select(); - $this->db->from('Entity'); - $where = "EntityMap like '$nid|%' AND Merged = 0"; - $where .= " OR EntityMap like '$nid,%' AND Merged = 0"; - $where .= " OR EntityMap like '%,$nid,%' AND Merged = 0"; - $where .= " OR EntityMap like '%|$nid,%' AND Merged = 0"; - $where .= " OR EntityMap like '%|$nid|%' AND Merged = 0"; - $where .= " OR EntityMap like '%,$nid|%' AND Merged = 0"; - $where .= " OR EntityMap like '%|$nid' AND Merged = 0"; - echo $where; - $this->db->where($where); - $query = $this->db->get(); - return $query->result_array(); - //} -*/ $query = $this->db->get(); return $query->result_array(); - //if($this->db->count_all_results()>0){ - - //} else {return '';} - - // "SELECT `ID`,EntityMap, Verb FROM `Entity` where `EntityMap` like '2717,%' or `EntityMap` like '%,2717,%' or `EntityMap` like ',2717|%' or `EntityMap` like '%|2717|%' or `EntityMap` like '%|2717' or `EntityMap` like '2717|%'" - } + } function get_entry_cont($tag,$entityname,$page_num=1, $results_per_page=15,$sortment) { @@ -187,7 +150,7 @@ function get_entry_cont($tag,$entityname,$page_num=1, $results_per_page=15,$sort $page_num = 1; } - $result = $this->db->query("SELECT * FROM Entity WHERE MATCH ($tag) AGAINST ('+$entityname' IN BOOLEAN MODE) AND Merged=0 AND Name like '$sortment%' ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); + $result = $this->db->query("SELECT * FROM Entity WHERE $tag LIKE '%$entityname%' AND Merged=0 AND Name like '$sortment%' ORDER BY Name LIMIT ". ($page_num - 1) * $results_per_page .", $results_per_page"); return $query = $result->result_array(); } @@ -202,7 +165,6 @@ function get_entry_cont2($tag,$entityname,$page_num=1, $results_per_page=15, $so return $query = $result->result_array(); } - function get_entry_cont3($tag,$entityname,$page_num=1, $results_per_page=15, $sortment) { // echo($page_num); if ($page_num < 1) @@ -247,48 +209,60 @@ function get_doc($docid) //} else {return '';} } - function get_dataset($tbl,$q,$id) + function get_dataset($tbl,$q,$id) { $ar=array(); $ra=array(); + $c=0; + $qid = (int)$id; $flds = $this->db->field_data($tbl); foreach($flds as $f ) { if (substr($f->name,-3,3)=='_E_') { - $Entity_id[]= $f->name; - }/* else { + // $Entity_id[]= $f->name; + + if ($c==0) { + $l = "where `".$f->name."` LIKE '%,".$qid.",%'"; + } else { + $l .= " or `". $f->name. "` LIKE '%,".$qid.",%'"; + } + $c++; + } + /*else { $Entity_field[]= $f->name; }*/ $Entity_field[]= $f->name; } - $qu = ($q=='*') ? implode(',',$Entity_field) : $q .','. implode(',',$Entity_id); - // echo $qu; - $this->db->select($qu); - $this->db->from($tbl); - $this->db->limit(50); - foreach($Entity_id as $r){ - $this->db->or_where($r,$id); - } - $query = $this->db->get(); - return $query->result_array(); + $qu = ($q=='*') ? implode(',',$Entity_field) : $q ; + $data ="SELECT $qu FROM $tbl $l "; + //echo $data; + $result = $this->db->query( $data ); + // var_dump($result); + return $result->result_array(); + } function get_dataset_map($tbl, $id) { $Entity_id=array(); - $Entity_name=array(); + $Entity_name= "";//array(); + $c=0; $flds = $this->db->field_data($tbl); foreach($flds as $f ) { if (substr($f->name,-3,3)=='_E_') { - $Entity_name[]= $f->name; + $Entity_name .= "`". $f->name ."`,"; + if ($c==0) { + $l = "where `".$f->name."` LIKE '%," . $id . ",%'"; + } else { + $l .= " or `". $f->name. "` LIKE '%," . $id . ",%'"; + } + $c++; } } - $this->db->select($Entity_name); - $this->db->from($tbl); - foreach($Entity_name as $r){ - $this->db->or_where($r, $id); - } - $query = $this->db->get(); - return $query->result_array(); + + $Entity_name = substr($Entity_name,0,-1); + // echo "SELECT $Entity_name FROM $tbl $l " ; exit; + $result = $this->db->query("SELECT $Entity_name FROM $tbl $l "); + return $query = $result->result_array(); } function mostvisited($id) diff --git a/application/views/about.php b/application/views/about.php index a7593f3..c20f4cf 100644 --- a/application/views/about.php +++ b/application/views/about.php @@ -1,4 +1,4 @@ -
    +

    About Us


    @@ -17,30 +17,9 @@ The current pilot is being launched in Kenya in partnership with the National Council of Law Reporting and funded by A.T.T.I.


    -
    -
    +

    This will be expanded to other sources of corporate data and the site will incorporate visualizations that will be able to show linkages of the data.

    - -
    - -
    -

    Developed by

    - - - -
    -
    -

    Launched in partnership with

    - - - - - - -
    -
    -
    diff --git a/application/views/admin.php b/application/views/admin.php index a9d1405..6f0acd1 100644 --- a/application/views/admin.php +++ b/application/views/admin.php @@ -14,9 +14,9 @@
    Entity Merge
    - +
    Entity Extract
    Entity Edit
    - +
    You can retrieve information on a particular entry by passing an id of an entity as a parameter as follows: -
    /api/entity?key={YOUR - API - KEY}&id={ID OF ENTITY};
    +
    /api/entity?key={YOUR - API - KEY}&id={ID OF ENTITY}
    The above query returns a list of results like so:
    [{"data":[{"dataset_type":[{"Gazette": [{"dataset":[{"Name":"National Council for Law Reporting","Name2":"Christine Agimba","Gazette_Number":"2013_GAZ8654","EffectiveDate":"10\/02\/13 : 10\/02\/16","Action":"0","Appointer":"Githu Muigai - Attorney General","Name_E_":"40","Name2_E_":"41"},{"Name":"Christine Agimba","Name2":"National Council for Law Reporting","Gazette_Number":"2013_GAZ8654","EffectiveDate":"10\/02\/13 : 10\/02\/16","Action":"appointed","Appointer":"","Name_E_":"41","Name2_E_":"40"}]}]}]}]}]
    +
    diff --git a/application/views/api/footer.php b/application/views/api/footer.php index 947da66..f840df1 100644 --- a/application/views/api/footer.php +++ b/application/views/api/footer.php @@ -1,25 +1,67 @@ - + + +
    +
    +
    +

    Sources

    +

    + Our database contains information on people, companies and organisations, as well as their linkages at specified periods of time. + While we make every attempt to make this information as accurate as possible, we take no responsibility for its authenticity. + The current information is derived from the Kenya Gazette, Handsards and procurement websites. + We will be incorporating more information from different sources soon. +

    +
    +
    +
    +

    Developed by

    +
    + oi +
    +
    +
    +

    In partnership with

    +
    + atti +
    +
    + klr +
    +
    + +
    +
    +
    +

    Mailing List

    +

    Open Duka is a work in progress (and a labour of love) for us and we shall continue to add new features and data. Sign up here if you want to keep in touch with the progress we make.

    +
    +
    + +
    +
    +
    + + + +
    + + - + - - - - - - - - - - - - - - + + + diff --git a/application/views/api/header.php b/application/views/api/header.php index b52892d..e1969aa 100644 --- a/application/views/api/header.php +++ b/application/views/api/header.php @@ -49,16 +49,19 @@ +
    diff --git a/application/views/contact.php b/application/views/contact.php index 923bc63..5a41bbb 100644 --- a/application/views/contact.php +++ b/application/views/contact.php @@ -1,60 +1,5 @@ -' . "\r\n" . 'Reply-To: ' . $email; - $body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments"; - - - mail($emailTo, $subject, $body, $headers); - $emailSent = true; - } -} -?> - - - - -
    +

    Feedback

    diff --git a/application/views/footer.php b/application/views/footer.php index 3d38dd0..071054f 100644 --- a/application/views/footer.php +++ b/application/views/footer.php @@ -3,17 +3,102 @@ + +
    +
    +
    +

    Sources

    +

    + Our database contains information on people, companies and organisations, as well as their linkages at specified periods of time. + While we make every attempt to make this information as accurate as possible, we take no responsibility for its authenticity. + The current information is derived from the Kenya Gazette, Handsards and procurement websites. + We will be incorporating more information from different sources soon. +

    +
    +
    +
    +

    Developed by

    +
    + oi +
    +
    +
    +

    In partnership with

    +
    + atti +
    +
    + klr +
    +
    + +
    +
    + +
    +

    Mailing List

    +

    Open Duka is a work in progress (and a labour of love) for us and we shall continue to add new features and data. Sign up here if you want to keep in touch with the progress we make.

    +
    +
    + +
    +
    + +
    + + + +
    - +
    diff --git a/application/views/footer_entity.php b/application/views/footer_entity.php index 02e8ac2..6c67a0f 100644 --- a/application/views/footer_entity.php +++ b/application/views/footer_entity.php @@ -2,31 +2,23 @@ - - + + - - - - - - - - - - - - - - + + + + + + diff --git a/application/views/header.php b/application/views/header.php index dfe6427..d64cbba 100644 --- a/application/views/header.php +++ b/application/views/header.php @@ -69,12 +69,20 @@ function showDiv() {
    + + diff --git a/application/views/header_entity.php b/application/views/header_entity.php index d8931e2..45030c4 100644 --- a/application/views/header_entity.php +++ b/application/views/header_entity.php @@ -5,18 +5,13 @@ <?php echo $page_title;?> - + - - - - - - - - - - + + + + + diff --git a/application/views/home.php b/application/views/home.php index 738fb22..93fe6db 100644 --- a/application/views/home.php +++ b/application/views/home.php @@ -10,142 +10,155 @@

    The freely accessible database of information on Kenyan entities

    -
    -
    -

    Providing citizens, journalists, and civic activists with a practical and easy-to-use tool to understand the ownership - structure of the world they live in, demonstrating the practical applications of open information for normal citizens

    -
    -
    - - - +

    -