<?php

require 'CURL.php';
require 'UTIL.php';
require 'secure.php';
$util = new Util();
$sql = new mysqli($mysql['host'], $mysql['user'], $mysql['passwd'], "weather_tracking");
if ($sql->connect_error) {
    die("Connection Failed: " . $sql->connect_error);
}
$location = $_GET['loc'];
$city_query = "SELECT location_id, owm_id FROM locations WHERE name = '{$location}'";
$loc_data = $sql->query($city_query);
$loc_assoc = $loc_data->fetch_assoc();
$loc_id = $loc_assoc['location_id'];
$curl = new Curly();
$data = $curl->getURL("http://api.openweathermap.org/data/2.5/forecast?id=" . $loc_assoc['owm_id'] . "&units=imperial");
$data_array = json_decode($data, 1);
foreach ($data_array['list'] as $day) {
    $dt = $day['dt'] * 1000;
    print $dt . "<br/>";
    print $day['main']['temp_max'] . "<br/>";
    //$util->dumper($day);
}
//$util->dumper($data_array);
exit;
$query = "\n    SELECT  weather.temp\n        ,   DATE_FORMAT(create_date, '%Y-%m-%d %H:%i:00') AS timekey\n    FROM weather\n    WHERE location_id = '{$loc_id}'\n    ORDER BY timekey DESC\n";
$rows = $sql->query($query);
$all_rows = array();
while ($row = $rows->fetch_assoc()) {
    $all_rows[] = $row;
            } elseif (has_capability('block/evalcomix:assessed', $context, $assessorid)) {
                $mode = 'peer';
            } else {
                print_error('EvalCOMIX: Wrong User');
            }
        }
        $url_instrument = webservice_evalcomix_client::get_ws_viewtool($toolid, $lang . '_utf8', $courseid, $module, $cmid, $studentid, $assessorid, $mode, $lms, $title);
    }
} elseif ($viewtemplate == '1') {
    //require_capability('block/evalcomix:edit', $context, $USER->id);
    require_capability('moodle/grade:viewhidden', $context, $USER->id);
    $url_instrument = webservice_evalcomix_client::get_ws_viewtool($toolid, $lang . '_utf8');
}
$vars = explode('?', $url_instrument);
include_once $CFG->dirroot . '/blocks/evalcomix/classes/curl.class.php';
$curl = new Curly();
$response = $curl->post($vars[0], $vars[1]);
if ($response && $curl->getHttpCode() >= 200 && $curl->getHttpCode() < 400) {
    echo $response;
} else {
    print_error('EvalCOMIX cannot get datas');
}
if ($viewtemplate == 0) {
    echo "<script>\n\t\n\twindow.opener.onunload=function(){\n\t\tdoWork('evalcomixtablegrade', 'servidor.php?id=" . $courseid . "&eva=" . $USER->id . "', 'courseid=" . $courseid . "&page=&stu=" . $studentid . "&cma=" . $cmid . "');\n\t\tsetTimeout(close, 1000);\n\t\t\n\t};\n\t\n\t/*window.opener.onbeforeunload(){\n\t\tdoWork('evalcomixtablegrade', 'servidor.php?id=" . $courseid . "&eva=" . $USER->id . "', 'courseid=" . $courseid . "&page=&stu=" . $studentid . "&cma=" . $cmid . "');\n\t\tclose();\n\t};*/\n\t\n\t/*function testParent() {\n\t\tif (window.opener != null && !window.opener.closed){\n\t\t\tsetTimeout(\"testParent()\",1);\n\t\t}\n\t\telse {\n\t\t\talert('Parent closed/does not exist.');\n\t\t\tdoWork('evalcomixtablegrade', 'servidor.php?id=" . $courseid . "&eva=" . $USER->id . "', 'courseid=" . $courseid . "&page=&stu=" . $studentid . "&cma=" . $cmid . "');\n\t\t\twindow.close();\n\t\t}\n}  \n\ttestParent()¨*/\n</script>";
}
//$report_evalcomix->process_data($datapost);
/*$o = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="moodle, evalcomix" />
<link rel="stylesheet" type="text/css" href="../styles/main.css" />
    {
        defined('GET_TOOLS2') || die('EvalCOMIX is not configured');
        global $CFG;
        $serverurl = GET_TOOLS2 . '?format=xml';
        if (!isset($params['courseid'])) {
            throw new Exception('Missing Params');
        }
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix_tool.php';
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/evalcomix.php';
        $xml = '<?xml version="1.0" encoding="utf-8"?>
		<assessments>';
        if ($block = evalcomix::fetch(array('courseid' => $params['courseid']))) {
            if ($tools = evalcomix_tool::fetch_all(array('evxid' => $block->id))) {
                foreach ($tools as $tool) {
                    $xml .= '<tool>';
                    $xml .= $tool->idtool;
                    $xml .= '</tool>';
                }
            }
        }
        $xml .= '</assessments>';
        include_once $CFG->dirroot . '/blocks/evalcomix/classes/curl.class.php';
        $curl = new Curly();
        $response = $curl->post($serverurl, $xml);
        if ($response && $curl->getHttpCode() >= 200 && $curl->getHttpCode() < 400) {
            $result = simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NSCLEAN);
            return $result;
        } else {
            throw new Exception('Page: Bad Response');
        }
Exemple #4
0
<?php

// project: Curly.php
// author: nsimaria - Nuno Simaria - nsimaria@gmail.com
//
// license: Use at your own will and risk. It would be nice of you to credit the author of the code, but hey, no pressure. Some feedback would be awesome as well.
//
// description: Curly.php is a simple curl wrapper for curl requests on PHP. It is not intended to be a complete, fully featured wrapper. Its a light weight class to quickly try API Requests.
//
// SiMA - Software is Modern Art
require_once 'Curly.php';
// requests http://api.twitter.com/users/_nsimaria_.json and returns the json string
$curly = new Curly();
$curly->home('http://api.twitter.com/');
$curly->action('users/_nsimaria_');
$curly->format('json');
$curly->request();
// requests http://your.api.home.com/statuses/home_timeline.xml?count=5 with basic authentication
// non-working example!
$curly = new Curly();
$curly->home('http://your.api.home/');
$curly->login('username', 'password');
$curly->action('statuses/home_timeline');
$curly->format('xml');
$curly->data('count', 5);
$curly->request('post');
// asking for the info on how it went:
$curly->info();