diff --git a/budgets_count.php b/budgets_count.php
new file mode 100644
index 0000000..c026c4e
--- /dev/null
+++ b/budgets_count.php
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/budgets_missing_elements.php b/budgets_missing_elements.php
new file mode 100644
index 0000000..4d0c79f
--- /dev/null
+++ b/budgets_missing_elements.php
@@ -0,0 +1,10 @@
+
+
+
+
diff --git a/processes/budgets_count.php b/processes/budgets_count.php
new file mode 100644
index 0000000..b066c32
--- /dev/null
+++ b/processes/budgets_count.php
@@ -0,0 +1,118 @@
+');
+ $results = get_count($dir);
+ //print_r($results);
+
+ if (!$results == NULL) {
+ if(!empty($results["results"])) {
+ echo "
Unable to get data.
Maybe there are no budgets in this data.
";
+ }
+
+ //Print a table of failing files
+ theme_bad_files($results["bad-files"],$url);
+
+ print("");//main content
+}
+
+
+
+
+
+
+function get_count ($dir) {
+ $bad_files = array();
+ if ($handle = opendir($dir)) {
+ /* This is the correct way to loop over the directory. */
+ while (false !== ($file = readdir($handle))) {
+ if ($file != "." && $file != "..") { //ignore these system files
+
+ if ($xml = simplexml_load_file($dir . $file)) {
+
+ if(!xml_child_exists($xml, "//iati-organisation")) {//ignore organisation files
+ //$count = $xml->count('.//transaction-date'); //php >5.3
+ //$count = count($xml->{'iati-activity'}->{'transaction'}); //php < 5.3
+ $result = $xml->xpath("//budget");
+ //print_r($result); die;
+ if (count($result)) {
+ foreach ($result as $value) {
+ if ($value->value == 0 ) {
+ $zero_transactions[] = $file;
+ //echo $file;
+ }
+ $codes[] = (string)$value->attributes()->type;
+ }
+ $results[$file] = count($result);
+ } else {
+ return NULL;
+ }
+ }
+ } else { //simpleXML failed to load a file
+ array_push($bad_files,$file);
+ }
+
+ }
+ }
+ }
+ $return = array("results" => $results,
+ "zeros" =>$zero_transactions,
+ "codes" => $codes,
+ "bad-files" => $bad_files);
+
+ return $return;
+}
+
+?>
+
diff --git a/processes/budgets_missing_elements.php b/processes/budgets_missing_elements.php
new file mode 100644
index 0000000..3c11205
--- /dev/null
+++ b/processes/budgets_missing_elements.php
@@ -0,0 +1,197 @@
+';
+ $tick = '1 ');
+ if($results['start'] || $results['end'] || $results['value'] || $results['value-date'] || $results['fails']) {
+ print('
Elements
');
+ echo count($results['start']) . " budget" . (count($results['start']) == 1 ? '' : 's') . " missing <period-start>";
+ echo '
';
+ echo count($results['end']). " budget" . (count($results['end']) == 1 ? '' : 's') . " missing <period-end>";
+ echo '
';
+ echo count($results['value']). " budget" . (count($results['value']) == 1 ? '' : 's') . " missing <value>";
+ echo '
';
+ echo count($results['value-date']). " budget" . (count($results['value-date']) == 1 ? '' : 's') . " missing @value-date";
+ echo '
';
+ echo count($results['fails']) . " activit" . (count($results['fails']) == 1 ? 'y' : 'ies') . " experiencing one or more problems";
+ }
+ if (!empty($results['fails'])){
+ print('
Table of elements with problems
');
+ print('
+
+
+ Id |
+ Start |
+ End |
+ Value |
+ @value-date |
+ File |
+ Validator |
+
+
+ '
+ );
+
+ foreach ($results['fails'] as $key => $value) {
+ //print_r($value); die;
+ echo '';
+ echo '' . $key . ' | ';
+ echo '' . (in_array("start",$value)? $cross:$tick) . ' | ';
+ echo '' . (in_array("end",$value)? $cross:$tick) . ' | ';
+ echo '' . (in_array("value",$value)? $cross:$tick) . ' | ';
+ echo '' . (in_array("value-date",$value)? $cross:$tick) . ' | ';
+
+ echo '' . $url . $value['file'] . ' | ';
+ echo 'Validator | ';
+ echo '
';
+
+ }
+ print('
+
');
+ }
+ //die;
+ if ($results['no-budgets']) {
+ echo "
Files with no budgets
";
+ print("
+
+
+
+ # |
+ File |
+ Validator |
+
+
+
+ ");
+ $files = array_unique($results['no-budgets']);
+ $i=0;
+ foreach ($files as $file) {
+ $i++;
+ print('
+
+ ' . $i . ' |
+ ' . $file . ' |
+ Validator |
+
'
+ );
+ }
+ print("
+
");
+ }
+
+ print('
');
+}
+
+
+function check_budget_elements ($dir) {
+ //global $dir;
+ //$missing= array();
+ $files = array();
+ //$rows = '';
+ $fails = array();
+ $fails_value = $fails_value_date = $fails_date = $fails_type = array();
+ if ($handle = opendir($dir)) {
+ /* This is the correct way to loop over the directory. */
+ while (false !== ($file = readdir($handle))) {
+ if ($file != "." && $file != "..") { //ignore these system files
+ if ($xml = simplexml_load_file($dir . $file)) {
+ if(!xml_child_exists($xml, "//iati-organisation")) { //ignore org files
+ if(xml_child_exists($xml, "//budget")) { //ignore org files
+ foreach ($xml as $activity) {
+ $id = (string)$activity->{'iati-identifier'};
+ foreach ($activity->{'budget'} as $budget) {
+ if (!xml_child_exists($budget, ".//period-start")) {
+ array_push ($fails_type, array($id,$file));
+ $fails[$id][] = "start";
+ $fails[$id]['file'] = $file;
+ }
+ if(!xml_child_exists($budget, ".//period-end")) {
+ array_push ($fails_date, array($id,$file));
+ $fails[$id][] = "end";
+ $fails[$id]['file'] = $file;
+ //$fails[$id] = "budget-date";
+ }
+ if(!xml_child_exists($budget, ".//value")) {
+ array_push ($fails_value, array($id,$file));
+ $fails[$id][] = "value";
+ $fails[$id]['file'] = $file;
+ //$fails[$id] = "value";
+ }
+ if (!$budget->xpath(".//value[@value-date]")) {
+ array_push ($fails_value_date, array($id,$file));
+ $fails[$id][] = "value-date";
+ $fails[$id]['file'] = $file;
+ //$fails[$id] = "value-date";
+ }
+ }
+ }
+ } else { //no budgets found
+ $files_with_no_budgets[] = $file;
+ }
+ } //end organisation file check
+ } else { //simpleXML failed to load a file
+ //echo $file . ' empty';
+ }
+
+ }// end if file is not a system file
+
+ } //end while
+ closedir($handle);
+
+ }
+ if (!isset($files_with_no_budgets)) {
+ $files_with_no_budgets = NULL;
+ }
+ return array("start" => $fails_type,
+ "end" => $fails_date,
+ "value" => $fails_value,
+ "value-date" => $fails_value_date,
+ "fails" => $fails,
+ "no-budgets" => $files_with_no_budgets
+ );
+
+}
+
+
+
+function validator_link($url,$file,$id = NULL) {
+ if ($id !=NULL) {
+ $link ='http://webapps.kitwallace.me/exist/rest/db/apps/iati/xquery/validate.xq?mode=view&type=activity&id=';
+ $link .=$id;
+ $link .= '&source=' . urlencode($url) . urlencode(preg_replace("/ /", "%20", $file));
+ } else {
+ $link ='http://webapps.kitwallace.me/exist/rest/db/apps/iati/xquery/validate.xq?type=activitySet&source=';
+ $link .= urlencode($url) . urlencode(preg_replace("/ /", "%20", $file));
+ $link .= '&mode=download';
+ }
+ return $link;
+}
+
+
+?>
+
+
+
diff --git a/variables/site_vars.php b/variables/site_vars.php
index eb119e9..a080f9e 100644
--- a/variables/site_vars.php
+++ b/variables/site_vars.php
@@ -50,5 +50,12 @@
"transactions_count" => array("link"=> "transactions_count.php", "title"=>"Count"),
"transactions_missing_elements" => array("link"=>"transactions_missing_elements.php","title"=>"Missing Elements"),
);
+
+$budgets_menu = array(//"transactions" => array("link"=>"transactions.php","title"=>"Overview"),
+ //"transactions_by_year" => array("link"=>"transactions_by_year.php","title"=>"By Year"),
+ //"transactions_list" => array("link"=>"transactions_list.php","title"=>"List"),
+ "budgets_count" => array("link"=> "budgets_count.php", "title"=>"Count"),
+ "budgets_missing_elements" => array("link"=>"budgets_missing_elements.php","title"=>"Missing Elements"),
+ );
-$menus = array("overview","validation","activities","elements","codelists","transactions");
+$menus = array("overview","validation","activities","elements","codelists","transactions","budgets");