function get_fork_data($job) { global $mysqli; $fork_encrypt_key = md5('huls0fjhslsshskslgjbtqcwijnbxhl2391'); $fork_raw_data = $job->workload(); $fork_metadata = json_decode(AESDecryptCtr(base64_decode($fork_raw_data), $fork_encrypt_key, 256), true); $fork_key = $fork_metadata['fork_key']; $token = $fork_metadata['token']; $inikoo_account_code = $fork_metadata['code']; if (!ctype_alnum($inikoo_account_code)) { print "cant fint account code\n"; return false; } include "gearman/conf/dns.{$inikoo_account_code}.php"; $mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } $mysqli->query("SET NAMES 'utf8'"); date_default_timezone_set('GMT'); $mysqli->query("SET time_zone='+0:00'"); $sql = sprintf("select `Fork Process Data` from `Fork Dimension` where `Fork Key`=%d and `Fork Token`=%s", $fork_key, prepare_mysql($token)); $res = $mysqli->query($sql); if ($row = $res->fetch_assoc()) { $fork_data = json_decode($row['Fork Process Data'], true); return array('fork_key' => $fork_key, 'inikoo_account_code' => $inikoo_account_code, 'fork_data' => $fork_data); } else { print "fork data not found"; return false; } }
function new_fork($type, $number_operations, $data, $account_code) { global $mysqli; $fork_encrypt_key = md5('huls0fjhslsshskslgjbtqcwijnbxhl2391'); $token = substr(str_shuffle(md5(time()) . rand() . str_shuffle('qwertyuiopasdfghjjklmnbvcxzQWERTYUIOPKJHGFDSAZXCVBNM1234567890')), 0, 64); $sql = sprintf("insert into `Fork Dimension` (`Fork Process Data`,`Fork Token`,`Fork Type`,`Fork Operations Total Operations`) values (%s,%s,%s,%d) ", prepare_mysql(json_encode($data)), prepare_mysql($token), prepare_mysql($type), $number_operations); $salt = md5(rand()); $mysqli->query($sql); $fork_key = $mysqli->insert_id; $fork_metadata = base64_encode(AESEncryptCtr(json_encode(array('code' => addslashes($account_code), 'token' => $token, 'fork_key' => $fork_key, 'salt' => $salt)), $fork_encrypt_key, 256)); $client = new GearmanClient(); $client->addServer('127.0.0.1'); $msg = $client->doBackground($type, $fork_metadata); return array($fork_key, $msg); }
function lookup_from_file($data) { global $mysqli; include 'libs/PHPExcel/Classes/PHPExcel/IOFactory.php'; $upload_key = $data['upload_key']; $sql = sprintf("select `Upload Content` from `Upload Content Dimension` where `Upload Key`=%d", $upload_key); $res = $mysqli->query($sql); if ($row = $res->fetch_assoc()) { $content = $row['Upload Content']; } else { $response = array('state' => 400, 'msg' => 'Error file content not found'); header('Content-Type: application/json'); echo json_encode($response); return; } $fp = tmpfile(); fwrite($fp, $content); rewind($fp); $metaDatas = stream_get_meta_data($fp); $tmpFilename = $metaDatas['uri']; $objPHPExcel = PHPExcel_IOFactory::load($tmpFilename); $sheetData = $objPHPExcel->getActiveSheet()->toArray(null, true, true, true); //print_r($sheetData); foreach ($sheetData as $row) { if (isset($row['A']) and $row['A'] != '') { $journals[] = $row['A']; } } $funders = parse_funders($data['funders']); $journals = parse_journals($journals); $request_data = array(); $number_journals = 0; foreach ($journals as $journal) { $request_data[] = array('journal_data' => $journal, 'funders_data' => $funders); $number_journals++; } $request_data = json_encode($request_data); list($fork_key, $msg) = new_fork('fact_api_request', $number_journals, $request_data, $account_code = 'FACT'); $sql = sprintf("update `Upload Dimension`set `Upload Status`='Processed',`Processed Date`=%s where `Upload Key`=%d", prepare_mysql(gmdate('Y-m-d H:i:s')), $upload_key); $mysqli->query($sql); $sql = sprintf("delete from `Upload Content Dimension` where `Upload Key`=%d", $upload_key); //$mysqli->query($sql); $response = array('state' => 200, 'fork_key' => $fork_key, 'msg' => $msg, 'formated_funders' => get_formated_funders($funders)); header('Content-Type: application/json'); echo json_encode($response); }
function save_result_to_db($fork_key, $result) { global $mysqli; //print_r($result); $sql = sprintf("insert into `Result Dimension` (\n\t`Date`,`Fork Key`,`Result Type`,`Query`,`Journal ISSN`,`Journal Name`,\n\t`Compilance`,`Compilance Type`,\n\t`Gold Compilance Code`,`Gold Compilance Report`,`Gold Compilance Reason`,`Gold Compilance Advice`,\n\t`Green Compilance Code`,`Green Compilance Report`,`Green Compilance Reason`,`Green Compilance Advice`\n\t)\n\tvalues (\n\tNOW(),%d,%s,%s,%s,%s,\n\t%s,%s,\n\t%s,%s,%s,%s,\n\t%s,%s,%s,%s\n\t)", $fork_key, prepare_mysql($result['result_type']), prepare_mysql($result['query']), prepare_mysql($result['journal']['issn']), prepare_mysql($result['journal']['title']), prepare_mysql($result['compilance']), prepare_mysql($result['compilance_type']), prepare_mysql($result['gold']['code']), prepare_mysql($result['gold']['report']), prepare_mysql($result['gold']['reason']), prepare_mysql($result['gold']['advice']), prepare_mysql($result['green']['code']), prepare_mysql($result['green']['report']), prepare_mysql($result['green']['reason']), prepare_mysql($result['green']['advice'])); //print $sql; $mysqli->query($sql); }
function update_request_data() { $number_requests = 0; $number_sessions = 0; $last_request = ''; $sql = sprintf("select count(*) as num_request, count(distinct `User Key`) as num_sessions , max(`Date`) as date from `User Request Dimension` where `User Key`=%d", $this->id); $res = $this->mysqli->query($sql); if ($row = $res->fetch_assoc()) { $number_requests = $row['num_request']; $number_sessions = $row['num_sessions']; $last_request = $row['date']; } $sql = sprintf("update `User Dimension` set `User Requests Count`=%d,`User Sessions Count`=%d, `User Last Request`=%s where `User Key`=%d ", $number_requests, $number_sessions, prepare_mysql($last_request), $this->id); $this->mysqli->query($sql); }
global $user, $mysqli; if (isset($_FILES['Filedata'])) { $file_data = $_FILES['Filedata']; if (!$file_data['error']) { $checksum = md5_file($file_data['tmp_name']); $filezise = filesize($file_data['tmp_name']); $sql = sprintf("select `Upload Key` from `Upload Dimension` where `Upload Checksum`=%s and `Upload User Key`=%d and `Upload Status`='Uploaded' ", prepare_mysql($checksum), $user->id); //$mysqli->query(sprintf("insert into debug (message) values(%s)",prepare_mysql($sql))); $res = $mysqli->query($sql); if ($row = $res->fetch_assoc()) { $upload_key = $row['Upload Key']; } else { $sql = sprintf("insert into `Upload Dimension` (`Upload Date`,`Upload User Key`,`Upload Checksum`,`Upload Filesize`,`Upload Filename`,`Upload File Type`) values (%s,%s,%s,%s,%s,%s)", prepare_mysql(gmdate('Y-m-d H:i:s')), $user->id, prepare_mysql($checksum), $filezise, prepare_mysql($file_data['name']), prepare_mysql($file_data['type'])); $mysqli->query($sql); $upload_key = $mysqli->insert_id; $fp = fopen($file_data['tmp_name'], 'r'); $content = fread($fp, filesize($file_data['tmp_name'])); fclose($fp); $sql = sprintf("insert into `Upload Content Dimension` (`Upload Key`,`Upload Content`) values (%d,%s)", $upload_key, prepare_mysql($content)); $mysqli->query($sql); } $response = array('state' => 'uploaded', 'upload_key' => $upload_key, 'msg' => '', 'filename' => $file_data['name'], 'size' => format_bytes_size($filezise)); echo json_encode($response); } else { $response = array('state' => 'error', 'upload_key' => '', 'msg' => $file_data['error']); echo json_encode($response); } } else { $response = array('state' => 'error', 'upload_key' => '', 'msg' => 'no uploaded files'); echo json_encode($response); }