<?php /* * To change this license header, choose License Headers in Project Properties. * To change this templates file, choose Tools | Templates * and open the templates in the editor. */ include_once '../dataAccess/pdoDAO.php'; include_once '../../classes/json.php'; $dao = new pdoDAO(); $action = $_REQUEST['action']; switch ($action) { case "initReports": \ZP\ZP::log('Opened Reports', 'Opened Reports', $_SESSION['user']->getID(), $_SESSION['module_number']); $obj = $dao->initReports(); json::sendJsonObj($obj); break; case "getReport": $mineID = trim($_POST['mineID']); $from = trim($_POST['from']); $to = trim($_POST['to']); $indicatorID = trim($_POST['indicatorID']); $report = $dao->getReport($mineID, $from, $to, $indicatorID); json::sendJsonObj($report); break; default: break; }
public function addLicence($licence) { \ZP\ZP::log('Add License', 'Add License', $_SESSION['user']->getID(), $_SESSION['module_number']); $_user = $_SESSION["user"]; //get user and company info // $entityType = ""; // $govtid = 'null'; // $TPIN = 'null'; // //check if user is from mine or government // if($_user->TPIN != null){ // $entityType = 'mine'; // $TPIN = $_user->TPIN; // }else{ // $entityType = 'gov'; // $govtid = $_user->entityID; // } $TPIN = $_user->getTPIN(); //var_dump($TPIN); //exit(); //set sql $sql = "INSERT INTO licence(licenceID, code, resources, area, location, status, type) VALUES"; foreach ($list as $value) { $sql .= "({$value->licenceID},'{$value->code}','{$value->resources}','{$value->area}','{$value->location}', '{$value->status}', '{$value->type}'),"; } $sql = chop($sql, ","); $sql .= "ON DUPLICATE KEY UPDATE code = VALUES(code), resources = VALUES(resources),area = VALUES(area), " . "location = VALUES(location), status = VALUES(status),type = VALUES(type)"; // mysqli_query($this->con, $sql); var_dump(mysqli_error($this->con), $sql); // try{ // $result = mysqli_query($this->con, $sql); // // // } // catch(Exception $e) { // echo 'Message: ' .$e->getMessage(); // } }
} else { $commit = $dbaccess->commitForm($templateID, $reportID, $obj, $entities, $delete); } if ($commit["success"]) { unset($_SESSION['re-commit']); \ZP\ZP::log('Report Upload', $templateID, $_SESSION['user']->getID(), $_SESSION['module_number']); print json_encode($dbaccess->getSubmittedReports(date('Y'))); } else { print json_encode($commit); } } else { print json_encode(['success' => false, 'message' => 'Failed to insert the report. Please check that you have input valid information.']); } break; case 'getMPDInitData': \ZP\ZP::log('Opened Manage Submissions', 'Opened Manage Submissions', $_SESSION['user']->getID(), $_SESSION['module_number']); print $dbaccess->getMPDInitData(); break; case 'getMPDReport': $data = json_decode($_REQUEST['data']); print json_encode($dbaccess->getMPDReport($data)); break; case 'getSubmittedReports': $period = isset($_REQUEST['period']) ? $_REQUEST['period'] : date('Y'); print json_encode($dbaccess->getSubmittedReports($period, $_REQUEST)); break; case 'deleteRow': $key = intval($_REQUEST['key']); $table = $_REQUEST['table']; $reportID = $_REQUEST['reportID']; //exit(json_encode(['success'=>false, 'req'=>$_REQUEST]));
$action = $_REQUEST['action']; $dbaccess = new ZP\MEDBAccess(); switch ($action) { case 'addEntity': $entity = json_decode($_REQUEST['entity']); $user = isset($_REQUEST['user']) ? json_decode($_REQUEST['user']) : false; $_REQUEST['success'] = false; //exit(json_encode($_REQUEST)); if ($user) { print json_encode($dbaccess->addEntity($entity, $user)); } else { print json_encode($dbaccess->addEntity($entity)); } break; case 'getEntities': \ZP\ZP::log('Opened Manage Entities', 'Opened Manage Entities', $_SESSION['user']->getID(), $_SESSION['module_number']); print json_encode($dbaccess->getEntities()); break; case 'getEntityDetails': $ID = json_decode($_REQUEST['ID']); print json_encode($dbaccess->getEntities($ID)); break; case 'findEntity': $queryString = $_REQUEST['queryString']; print json_encode($dbaccess->findEntity($queryString)); break; case 'deleteEntity': $ID = json_decode($_REQUEST['ID']); //exit(json_encode(['success'=>false, 'id'=>$ID])); print json_encode($dbaccess->deleteEntity($ID)); break;
<?php /* * To change this license header, choose License Headers in Project Properties. * To change this templates file, choose Tools | Templates * and open the templates in the editor. */ include_once '../dataAccess/pdoDAO.php'; include_once '../../classes/json.php'; require_once $_SERVER['DOCUMENT_ROOT'] . "/ZeitiPortal/resources/required_scripts.php"; session_start(); $dao = new pdoDAO(); $action = $_REQUEST['action']; switch ($action) { case "getReconciliation": \ZP\ZP::log('Opened Reconciliation', 'Opened Reconciliation', $_SESSION['user']->getID(), $_SESSION['module_number']); $mineID = trim($_POST['mineID']); $period = trim($_POST['period']); $report = $dao->getReconciliation($mineID, $period); json::sendJsonObj($report); break; default: break; }
} else { $commit = $dbaccess->commitForm($templateID, $reportID, $obj, $entities, $delete); } if ($commit["success"]) { unset($_SESSION['re-commit']); \ZP\ZP::log('Report Upload', $templateID, $_SESSION['user']->getID(), $_SESSION['module_number']); print json_encode($dbaccess->getSubmittedReports(date('Y'))); } else { print json_encode($commit); } } else { print json_encode(['success' => false, 'message' => 'Failed to insert the report. Please check that you have input valid information.']); } break; case 'getMPDInitData': \ZP\ZP::log('Opened Manage Past Data', 'Opened Manage Past Data', $_SESSION['user']->getID(), $_SESSION['module_number']); print $dbaccess->getMPDInitData(); break; case 'getMPDReport': //exit($data); $data = json_decode($_REQUEST['data']); print json_encode($dbaccess->getMPDReport($data)); break; case 'getSubmittedReports': $period = isset($_REQUEST['period']) ? $_REQUEST['period'] : date('Y'); print json_encode($dbaccess->getSubmittedReports($period, $_REQUEST)); break; case 'deleteRow': $key = intval($_REQUEST['key']); $table = $_REQUEST['table']; $reportID = $_REQUEST['reportID'];
public function deleteEntity($ID) { try { if (property_exists($ID, 'entityID')) { $sql = "DELETE ge " . "FROM governmententity ge " . "WHERE ge.entityID = :ID AND (ge.entityID != 1 OR ge.entityName NOT LIKE '%ZEITI Secretariat%');"; $key = $ID->entityID; $entity = ZP::getEntity($ID->entityID); //exit($sql.$key); } else { $sql = "DELETE ec " . "FROM extractivecompany ec " . "WHERE ec.TPIN = :ID"; $entity = ZP::getExtractiveCompany($ID->tpin); $key = $ID->tpin; } $query = $this->getConnection()->prepare($sql); $query->bindParam(":ID", $key, PDO::PARAM_INT); if ($query->execute()) { //exit(json_encode(['success'=>false, 'key'=>$key])); ZP::log('Delete Entity', json_encode($entity), $_SESSION['user']->getID(), $_SESSION['module_number']); return $this->getEntities(); } return ['success' => false, 'exception' => 'Could not delete entity.']; } catch (\PDOException $e) { return ['success' => false, 'exception' => $e]; } }
public function deleteRow($key, $table, $reportID) { try { switch ($table) { case 'minerals_export_details': $table = 'minerals_export_details'; $col = ["outputTypeID", "reportID"]; break; case 'minerals_production_details': $table = 'minerals_production_details'; $col = ["typeID", "reportID"]; break; case 'payment-payment_flow_details': $col = 't.paymentID'; $table = 'payment_flow_details'; break; case 'beneficiary_ownership_details': $col = 't.beneficialOwnerID'; $table = 'beneficiary_ownership_details'; break; case 'private_stakeholder_declaration': $table = 'private_stakeholder_declaration'; $col = 't.privateStakeholderID'; break; case 'politically_exposed_person': $col = 't.pepID'; $table = 'politically_exposed_person'; break; case 'transctions_iba_details': $col = 't.detailsID'; $table = 'transctions_iba_details'; break; case 'interests_in_extractives_details': $col = 't.interestID'; $table = 'interests_in_extractives_details'; break; case 'loans_to_extractivesector_details': $col = 't.loanID'; $table = 'loans_to_extractivesector_details'; break; case 'mandatory': $col = 't.paymentID'; $table = 'mandatory_payment'; break; case 'voluntary': $col = 't.paymentID'; $table = 'voluntary_payment'; break; default: $table = false; } if ($table) { ///$this->getConnection()->beginTransaction(); //exit('hereaaaaaavvvv'); if (is_array($col)) { $cols = ZP::FormatString("({0}) IN (", implode(",", $col)); foreach ($key as $k => $v) { $pair = ZP::FormatString("({0}, {1})", intval($v), intval($reportID)); $cols .= $k == 0 ? $pair : ", " . $pair; } $cols .= ")"; //exit(json_encode(['query'=>"DELETE t FROM $table t WHERE $cols;"])); $query = $this->getConnection()->prepare("DELETE t FROM {$table} t WHERE {$cols}"); $stmt = $this->getConnection()->prepare("SELECT * FROM {$table} t WHERE {$cols}"); $stmt->execute(); $deleted = $stmt->fetchAll(PDO::FETCH_OBJ); } else { $key = is_array($key) ? implode(",", $key) : $key; // need to find better fix for this if (preg_match("/[a-zA-Z]+/", $key) === 1) { exit(json_encode(['success' => false, 'error' => 'Could not delete rows. Please select valid row(s) to delete.'])); } $stmt = $this->getConnection()->prepare("SELECT * FROM {$table} t WHERE {$col} IN ({$key});"); $stmt->execute(); $deleted = $stmt->fetchAll(PDO::FETCH_OBJ); $query = $this->getConnection()->prepare("DELETE t FROM {$table} t WHERE {$col} IN ({$key});"); //exit(json_encode(['query'=>"DELETE t FROM $table t WHERE $col IN ($key);"])); } if ($query->execute()) { $deleted = json_encode($deleted); while (strlen($deleted) > 500) { $substr = substr($deleted, 0, 499); $deleted = substr($deleted, 500); ZP::log('Template Row Deletion', $substr, $_SESSION['user']->getID(), $_SESSION['module_number']); } ZP::log('Template Row Deletion', $deleted, $_SESSION['user']->getID(), $_SESSION['module_number']); // handle case of mandatory and voluntary payment if (strcasecmp($table, 'voluntary_payment') == 0 || strcasecmp($table, 'mandatory_payment') == 0) { $table = 'social_payment'; } $stmt = $this->getConnection()->prepare("SELECT t.reportID " . "FROM {$table} t " . "WHERE t.reportID = :reportID"); $stmt->bindValue(":reportID", $reportID, PDO::PARAM_INT); if ($stmt->execute()) { if (count($stmt->fetchAll(PDO::FETCH_OBJ)) == 0) { $stmt = $this->getConnection()->prepare("DELETE r FROM report r WHERE r.reportID = :reportID"); $stmt->bindValue(":reportID", $reportID, PDO::PARAM_INT); if (!$stmt->execute()) { exit(json_encode(["success" => false, 'error' => 'Internal error occurred, could not delete report.'])); } ZP::log('Report Deletion', 'Report deleted', $_SESSION['user']->getID(), $_SESSION['module_number']); } } else { exit(json_encode(["success" => false, 'error' => 'Internal error occurred, could not delete row(s). Invalid query statement.'])); } } else { exit(json_encode(["success" => false, 'error' => 'Internal error occurred, could not delete row(s)'])); } } else { exit(json_encode(["success" => false, 'error' => 'Internal error occurred, could not delete row(s). Invalid arguments specified.'])); } } catch (\PDOException $e) { //return 'Deletion error: '.$e->getMessage(); exit(json_encode(["success" => false, 'error' => 'Internal error occurred, could not delete row(s).', 'e' => $e])); } }
public function delete($data) { try { $user = $this->getUser($data->ID); $this->getConnection()->beginTransaction(); if (strcmp($data->type, 'user') == 0) { $sql = "DELETE u " . "FROM `user` u " . "WHERE u.userID = :ID"; $query = $this->getConnection()->prepare($sql); $query->bindValue(":ID", $data->ID, PDO::PARAM_INT); if ($query->execute()) { $this->getConnection()->commit(); if ($user['success']) { ZP::log('User Deletion', json_encode($user['user']), $_SESSION['user']->getID(), $_SESSION['module_number']); } return $this->getEntities(); } return ["success" => false, "exception" => "Internal error occurred. Could not delete user"]; } else { if (strcmp($data->type, 'group') == 0) { $group = (object) $this->getGroup($data->ID); $sql = "DELETE FROM `group` WHERE groupID = :ID; "; $query = $this->getConnection()->prepare($sql); $query->bindValue(":ID", $data->ID, PDO::PARAM_INT); if ($query->execute()) { $this->getConnection()->commit(); //var_dump($group); //exit(0); if ($group->success) { ZP::log('Group Deletion', json_encode($group->group), $_SESSION['user']->getID(), $_SESSION['module_number']); } return $this->getEntities(); //return ["success"=>false, "exception"=>"Internal error occurred. Could not delete user"]; } return ["success" => false, "exception" => "Internal error occurred. Could not delete user"]; } } return ["success" => false, "exception" => "Internal error occurred. Could not delete group"]; } catch (\PDOException $e) { $this->getConnection()->rollBack(); return ["success" => false, "exception" => $e]; } }