public function __construct($company_information, $customer_information, $filename)
 {
     $this->xml = new XMLWriter();
     $this->company_information = $company_information;
     $this->customer_information = $customer_information;
     $this->currency = Utils::getValue('currency');
     $this->parseInformation($filename);
 }
Exemple #2
0
 /**
  * Creates the SQL query to fetch the data required and stores it in the appropriate internal query
  * @param array $params The parameters of the query
  * @return mixed
  */
 protected function fetchQuery(&$params)
 {
     $value = Utils::getValue($params["id"], false);
     if ($value) {
         $this->addFetchQuery($this->db->from('recent_queries')->select('*')->where('id', $value));
     } else {
         $this->addFetchQuery($this->db->from('recent_queries')->select('*')->orderBy("id DESC")->limit(8));
     }
 }
 protected function fetchQuery(&$params)
 {
     $onlyNonEmpty = Utils::getValue($params["nonempty"], false);
     /* Query
           SELECT (site_name, site_id) FROM site
        */
     $query = $this->db->from(self::HABITAT_TABLE_NAME)->select([self::HABITAT_NAME, self::HABITAT_ID])->where('struc', 'habitat');
     if ($onlyNonEmpty) {
         $query->select("(SELECT COUNT(*) from classified\n            LEFT JOIN photo ON photo.photo_id = classified.photo_id\n            LEFT JOIN site ON photo.site_id = site.site_id\n            WHERE options.option_id = site.habitat_id) AS counted")->having("counted > 0");
     }
     /* Add the query */
     $this->addFetchQuery($query);
 }
Exemple #4
0
 /**
  * Exposes passed arguments for debugging and exits.
  */
 public static function show()
 {
     $method = Utils::getValue(@$_SERVER['REQUEST_METHOD'], 'GET');
     $method = Utils::getValue(@$_SERVER['HTTP_X_HTTP_METHOD'], $method);
     if (strtolower(trim($method)) === 'get') {
         self::_headers('text/html');
         self::_html(func_get_args());
     } else {
         self::_headers('application/json');
         self::_json(func_get_args());
     }
     exit;
 }
 protected function fetchQuery(&$params)
 {
     $onlyNonEmpty = Utils::getValue($params["nonempty"], false);
     /* Query
           SELECT (options_name,options_id) FROM options
        */
     $query = $this->db->from(self::OPTIONS_TABLE_NAME)->select([self::OPTION_NAME, self::OPTION_ID])->where('struc', ['mammal', 'bird', 'noanimal']);
     if ($onlyNonEmpty) {
         $query->select("(SELECT COUNT(*) from classified\n            WHERE classified.species = options.option_id) AS counted")->having("counted > 0");
     }
     /* Add the query */
     $this->addFetchQuery($query);
 }
 protected function updateQuery(&$params)
 {
     if (!Utils::keysExist(['imageId', 'result'], $params)) {
         throw new BadMethodCallException("You need to provide a value to imageId and the" . " query result before using this method.");
     }
     /* depending on whether we are storing/updating temporary scientist results
          or results in the public table we switch the table name accordingly
        */
     $classifiedTableName = Utils::getValue($params["scientist_dataset"], false) ? self::CLASSIFIED_SCIENTIST_TABLE_NAME : self::CLASSIFIED_TABLE_NAME;
     $evennessTableName = Utils::getValue($params["scientist_dataset"], false) ? self::EVENNESS_SCIENTIST_TABLE_NAME : self::EVENNESS_TABLE_NAME;
     /* firstly delete any previous classifications for image */
     $this->db->deleteFrom($classifiedTableName)->where("photo_id", $params["imageId"])->execute();
     $this->db->deleteFrom($evennessTableName)->where("photo_id", $params["imageId"])->execute();
     $this->store();
 }
 /**
  * MammalClassifier constructor.
  * @param null $settings A settings object to run the algorithm
  * @param bool $scientistDataset Switches between running on live data, or scientist data
  */
 public function __construct($settings = null, $scientistDataset = false)
 {
     $this->result = null;
     $this->imageId = null;
     try {
         $this->db = new ClassificationQuery();
     } catch (PDOException $exception) {
         trigger_error("Failure to create a database connection." . " Possibly database settings provided are wrong", E_USER_WARNING);
     }
     if (!$settings) {
         $settings = SettingsStorage::settings();
     }
     $this->scientistDataset = $scientistDataset;
     $this->CONSECUTIVE_EXPECTED = Utils::getValue($settings['consecutive_expected'], 8);
     $this->VOTES_BEFORE_CONSENSUS = Utils::getValue($settings['votes_before_consensus'], 15);
     $this->UNREASONABLE_NUMBER_OF_SPECIES_IN_IMAGE = Utils::getValue($settings['unreasonable_number_of_species_in_image'], 5);
     $this->EVENNESS_THRESHOLD_COUNT = Utils::getValue($settings['evenness_threshold_count'], 0.6899999999999999);
     $this->EVENNESS_THRESHOLD_SPECIES = Utils::getValue($settings['evenness_threshold_species'], 0.7);
     $this->NUMBER_OF_NOTHING_HERE_BEFORE_CLASSIFY = Utils::getValue($settings["number_of_nothing_here_before_classify"], 5);
 }
<?php

require "../core.php";
$onScientistData = Utils::getValue($_POST["scientist_dataset"], false);
$fromID = Utils::getValue($_POST["from_id"], 1);
$toID = Utils::getValue($_POST["to_id"], -1);
$settings = Utils::getValue($_POST["settings"], null);
if ($settings) {
    $settingsObj = json_decode($settings, true);
} else {
    $settingsObj = null;
}
$st = new JobStatusQuery();
$status = $st->fetch()->asArray();
$controller = new AlgorithmController();
/* if already running then abort */
if ($status["started"]) {
    return;
}
/* ignore user closing the connection */
ignore_user_abort(true);
/* allow infinite time */
set_time_limit(0);
$controller->runAlgorithmJobBatch($st, $settingsObj, $onScientistData, $fromID, $toID);
    <button data-remodal-action="close" class="remodal-close"></button>
    <h1 id="register-title">注册</h1>
    <div class="pure-form">
        <input class="pure-input" id="reg-uname" type="text" placeholder="用户名">
        <input class="pure-input" id="reg-passwd" type="password" placeholder="密码">
        <input class="pure-input" id="reg-passwd2" type="password" placeholder="确认密码">
        <br />
        <button id="register-button" class="pure-button pure-button-primary">注册</button>
    </div>
    <div id="msg" class="alert"></div>
</div>

<script type="text/javascript" src="./libs/jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="./libs/cookie.js"></script>
<script type="text/javascript" src="./libs/remodal/remodal.min.js"></script>
<script type="text/javascript" src="./libs/ply/ply.min.js"></script>
<script type="text/javascript" src="./assets/js/utils.js"></script>
<script type="text/javascript" src="./assets/js/index.utils.js"></script>
<?php 
if ($msg = Utils::getValue('msg', $_GET)) {
    ?>
<script type="text/javascript"> showAlert("<?php 
    echo $msg;
    ?>
"); </script>
<?php 
}
?>
</body>
</html>
Exemple #10
0
<?php

require '../../core.php';
$csv = Utils::getValue($_GET['id']);
if ($csv) {
    $q = new RecentQueries();
    try {
        $json = $q->with(["id" => $csv])->fetch();
        if ($json instanceof QueryResults) {
            $json->asArray()[0]["json"];
        } else {
            throw new Exception();
        }
        $params = json_decode($json, true);
        if (isset($params["page"])) {
            unset($params["page"]);
        }
        if (isset($params["limit"])) {
            unset($params["limit"]);
        }
        $filterQuery = new FilterQuery();
        header("Content-Type: text/csv");
        header("Content-Disposition: attachment; filename=output.csv");
        header("Cache-Control: no-cache, no-store, must-revalidate");
        // HTTP 1.1
        header("Pragma: no-cache");
        // HTTP 1.0
        header("Expires: 0");
        // Proxies
        $queryResults = $filterQuery->with($params)->fetch()->asCSV();
    } catch (Exception $e) {
$settings = (include_once 'config/settings.php');
$filename = '20151007110121.pdf';
$converted_file = '20151007110121.txt';
$filename = Utils::manageFileUpload();
if (!$filename) {
    $result = 'C\'&egrave; stato un problema durante l\'upload del file';
} else {
    if (strpos($filename, '.pdf') !== false) {
        if (Utils::getValue('template') == 'nestle') {
            $pdfToText = XPDF\PdfToText::create();
            // PDF text is now in the $text variable
            $sheetData = $pdfToText->getText(PROJ_ROOT . '/upload/' . $filename);
            echo $sheetData;
            die;
        } else {
            if (Utils::getValue('template') == 'monge') {
                $pdfToText = XPDF\PdfToText::create(array('-layout'));
                // PDF text is now in the $text variable
                $sheetData = $pdfToText->getText(PROJ_ROOT . '/upload/' . $filename);
                echo $sheetData;
                die;
            }
        }
        //
    }
}
/*
$pdfToText = XPDF\PdfToText::create(array(
    'pdftotext.binaries' => PROJ_ROOT.'/xpdf-3.04/xpdf/',
));*/
/*$options = '';
Exemple #12
0
include '../../core.php';
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");
if (isset($_POST['params'])) {
    try {
        $params = json_decode($_POST['params'], true);
        if (is_null($params)) {
            error("Invalid JSON input");
            return;
        }
        $lastId = null;
        /* store as recent query */
        if (Utils::getValue($params["query"], false) === true) {
            $recentQueries = new RecentQueries();
            $lastId = $recentQueries->with(["json" => $_POST['params']])->store();
        }
        $filterQuery = new FilterQuery();
        $queryResults = $filterQuery->with($params)->fetch();
        echo json_encode(["id" => $lastId, "results" => $queryResults->asArray()], JSON_PRETTY_PRINT);
    } catch (PDOException $e) {
        error("Failure in database connection.");
    }
} else {
    if (isset($_GET['csv'])) {
        $csvPath = SettingsStorage::settings()["csv_file_locations"];
        $filename = Utils::sanitizeFilename($_GET['csv']);
        FileStorage::downloadFile($filename, $csvPath);
    } else {
Exemple #13
0
                $fields_string .= $key . '=' . $value . '&';
            }
            rtrim($fields_string, '&');
            //open connection
            $ch = curl_init();
            //set the url, number of POST vars, POST data
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, 1);
            curl_setopt($ch, CURLOPT_POST, count($fields));
            curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
            //execute post
            $result = curl_exec($ch);
            //close connection
            curl_close($ch);
            echo json_encode(["success" => true, "log" => "Algorithm started."]);
        } else {
            if ($action === "empty") {
                $scientistDataset = Utils::getValue($_POST["scientist_dataset"], false);
                $controller->clearResults($scientistDataset);
                return json_encode(["success" => true]);
            }
        }
    } else {
        error("No action specified.");
    }
}
function error($status)
{
    echo json_encode(["error" => $status]);
}
Exemple #14
0
                if (strpos($filename, '.txt') !== false || strpos($filename, '.TXT') !== false) {
                    $sheetData = file_get_contents('upload/' . $filename);
                }
            }
        }
        if (Utils::getValue('template') && !empty(Utils::getValue('template'))) {
            $className = ucfirst(Utils::getValue('template')) . 'Xml';
            if (class_exists($className)) {
                if (Utils::getValue('template') == 'amazon') {
                    $sheetData = 'upload/' . $filename;
                }
                $templateXML = new $className($settings['company_information'], $settings[Utils::getValue('template')]['company_information'], $sheetData);
                $templateXML->createDocument();
                //setupdownload header
                header("Content-Type: text/html/force-download");
                header("Content-Disposition: attachment; filename=" . Utils::getValue('template') . $templateXML->rif_fattura . ".xml");
                header('Cache-Control: max-age=0');
                echo $templateXML->outputXml();
                //everything fine, delete old file
                @unlink('upload/' . $filename);
                $result = true;
            } else {
                $result = 'C\'&egrave; stato un problema durante la creazione del documento in formato DaneaXml';
            }
        } else {
            $result = 'C\'&egrave; stato un problema durante il recupero del template richiesto';
        }
    }
}
if ($result !== true) {
    ?>
Exemple #15
0
 protected function fetchQuery(&$params)
 {
     $usersToInclude = Utils::getValue($params["users_include"], []);
     $usersToExclude = Utils::getValue($params["users_exclude"], []);
     $speciesToInclude = Utils::getValue($params["species_include"], []);
     $speciesToExclude = Utils::getValue($params["species_exclude"], []);
     $hasSpeciesToInclude = count($speciesToInclude) > 0;
     $hasSpeciesToExclude = count($speciesToExclude) > 0;
     $hasUsersToInclude = count($usersToInclude) > 0;
     $hasUsersToExclude = count($usersToExclude) > 0;
     // date has to be YYYY-MM-DD HH:MM:SS
     $hasTimeStamps = Utils::keysExist(["taken_start", "taken_end"], $params);
     $hasFlagged = Utils::keysExist("flagged", $params);
     $hasSiteId = Utils::keysExist("site_id", $params);
     $hasHumans = Utils::keysExist("contains_human", $params);
     $hasNumberOfClassifications = Utils::keysExist("no_of_classifications", $params);
     $hasNumberOfSpecies = Utils::keysExist("no_of_species", $params);
     $hasHabitatType = Utils::keysExist("habitat_id", $params);
     $hasPhotoId = Utils::keysExist("photo_id", $params);
     $hasNumberOfClassificationsFrom = Utils::keysExist("no_of_classifications_from", $params);
     $hasNumberOfClassificationsTo = Utils::keysExist("no_of_classifications_to", $params);
     /* depending on whether we are filtering temporary scientist results
        or results in the public table we switch the table name accordingly */
     $classifiedTableName = Utils::getValue($params["scientist_dataset"], false) ? self::CLASSIFIED_SCIENTIST_TABLE_NAME : self::CLASSIFIED_TABLE_NAME;
     $evennessTableName = Utils::getValue($params["scientist_dataset"], false) ? self::EVENNESS_SCIENTIST_TABLE_NAME : self::EVENNESS_TABLE_NAME;
     // SELECT * FROM classified
     // WHERE species IN (?,?,?,...) AND NOT IN (?,?,...)
     $query = $this->db->from("{$classifiedTableName} AS classified_tbl")->select(['classified_tbl.photo_id', 'classified_tbl.species', 'classified_tbl.flagged', 'classified_tbl.timestamp AS time_classified'])->leftJoin('photo ON photo.photo_id = classified_tbl.photo_id')->select(['photo.taken', 'photo.person_id', 'photo.site_id', 'photo.filename', 'photo.contains_human'])->leftJoin('site ON site.site_id = photo.site_id')->select(['site.habitat_id', 'site.site_name'])->leftJoin('options ON options.option_id = classified_tbl.species')->select('options.option_name AS species_name')->leftJoin("{$evennessTableName} AS evenness_tbl ON evenness_tbl.photo_id = classified_tbl.photo_id")->select(['evenness_tbl.evenness_species', 'evenness_tbl.evenness_count'])->leftJoin('options AS options2 ON options2.option_id = site.habitat_id')->select('options2.option_name AS habitat_name');
     if ($hasNumberOfClassificationsFrom && $hasNumberOfClassificationsTo) {
         $classificationsFrom = $params["no_of_classifications_from"];
         $classificationsTo = $params["no_of_classifications_to"];
         $query->leftJoin('animal ON animal.photo_id = classified_tbl.photo_id')->select('COUNT(DISTINCT animal.person_id) AS no_of_classifications')->groupBy('classified_tbl.photo_id')->having("COUNT(DISTINCT animal.person_id) BETWEEN ? AND ?", $classificationsFrom, $classificationsTo);
     } else {
         if ($hasNumberOfClassifications) {
             $numberOfClassifications = $params["no_of_classifications"];
             $query->leftJoin('animal ON animal.photo_id = classified_tbl.photo_id')->select('COUNT(DISTINCT animal.person_id) AS no_of_classifications')->groupBy('classified_tbl.photo_id')->having("COUNT(DISTINCT animal.person_id) = ?", $numberOfClassifications);
         }
     }
     if ($hasNumberOfSpecies) {
         $numberOfSpecies = $params["no_of_species"];
         $query->innerJoin("(SELECT ct.photo_id,COUNT(*) as counted from {$classifiedTableName} AS ct GROUP by photo_id) c ON c.photo_id = classified_tbl.photo_id");
         $query->where("c.counted = ?", $numberOfSpecies);
     }
     if ($hasPhotoId) {
         $photoId = $params["photo_id"];
         $query->where('classified_tbl.photo_id', $photoId);
     }
     if ($hasHabitatType) {
         $habitatType = $params["habitat_id"];
         $query->where('site.habitat_id', $habitatType);
     }
     //$this->db->debug = true;
     if ($hasSpeciesToInclude) {
         $query->where("classified_tbl.species", $speciesToInclude);
     }
     if ($hasSpeciesToExclude) {
         $unknowns = Utils::generateUnknowns($speciesToExclude);
         $query->where("classified_tbl.species NOT IN ({$unknowns})", ["expand" => $speciesToExclude]);
     }
     if ($hasUsersToInclude) {
         $query->where("photo.person_id", $usersToInclude);
     }
     if ($hasUsersToExclude) {
         $unknowns = Utils::generateUnknowns($usersToExclude);
         $query->where("photo.person_id NOT IN ({$unknowns})", ['expand' => $usersToExclude]);
     }
     if ($hasTimeStamps) {
         $takenStart = $params['taken_start'];
         $takenEnd = $params['taken_end'];
         $query->where("photo.taken BETWEEN ? AND ?", $takenStart, $takenEnd);
     }
     if ($hasFlagged) {
         $flagged = $params['flagged'];
         $query->where("classified_tbl.flagged", $flagged);
     }
     if ($hasSiteId) {
         $siteId = $params['site_id'];
         $query->where("photo.site_id", $siteId);
     }
     if ($hasHumans) {
         $humans = $params['contains_human'];
         $query->where("photo.contains_human", $humans);
     }
     /* expand is a special keyword which says take the arguments from the list and bind them to unbound variables
           eg. Query is WHERE NOT IN (?,?)
                $args = [15,22]
                passing in ['expand' => $args]
                replaces the ?,? with 15,22 as in WHERE NOT IN (15,22)
        */
     $this->addFetchQuery($query);
 }
function checkFile()
{
    global $json;
    if (!(Utils::getValue('skin_file', $_FILES) || Utils::getValue('cape_file', $_FILES))) {
        $json['errno'] = 1;
        $json['msg'] = "什么文件都没有诶?";
        return false;
    }
    /**
     * Check for skin_file
     */
    if (Utils::getValue('skin_file', $_FILES)["type"] == "image/png" || Utils::getValue('skin_file', $_FILES)["type"] == "image/x-png") {
        // if error occured while uploading file
        if (Utils::getValue('skin_file', $_FILES)["error"] > 0) {
            $json['errno'] = 1;
            $json['msg'] = Utils::getValue('skin_file', $_FILES)["error"];
            return false;
        }
    } else {
        if (Utils::getValue('skin_file', $_FILES)) {
            $json['errno'] = 1;
            $json['msg'] = '错误的皮肤文件类型。';
            return false;
        } else {
            $json['skin']['errno'] = 0;
            $json['skin']['msg'] = '什么文件都没有诶?';
        }
    }
    /**
     * Check for cape_file
     */
    if (Utils::getValue('cape_file', $_FILES)["type"] == "image/png" || Utils::getValue('cape_file', $_FILES)["type"] == "image/x-png") {
        // if error occured while uploading file
        if (Utils::getValue('cape_file', $_FILES)["error"] > 0) {
            $json['errno'] = 1;
            $json['msg'] = Utils::getValue('cape_file', $_FILES)["error"];
            return false;
        }
    } else {
        if (Utils::getValue('cape_file', $_FILES)) {
            $json['errno'] = 1;
            $json['msg'] = '错误的披风文件类型。';
            return false;
        } else {
            $json['cape']['errno'] = 0;
            $json['cape']['msg'] = '什么文件都没有诶?';
        }
    }
    return true;
}