示例#1
0
 }
 if (isset($_FILES['descriptor_xml_file']) && is_uploaded_file($_FILES['descriptor_xml_file']['tmp_name'])) {
     if (!move_uploaded_file($_FILES['descriptor_xml_file']['tmp_name'], 'temp.xml')) {
         error('Falha ao mover arquivo enviado.');
     }
     $experiment = simplexml_load_file('temp.xml');
 } else {
     if (isset($_POST['descriptor_xml'])) {
         $experiment = simplexml_load_string($_POST['descriptor_xml']);
     }
 }
 if (!$experiment) {
     error('Descritor de experimento inválido.');
 }
 elementToDB($experiment);
 $experiment_id = lastID();
 if (file_exists('temp.xml')) {
     rename('temp.xml', "experiment{$experiment_id}.xml");
 }
 $attributes = array('experiment_id' => $experiment_id);
 foreach ($experiment->children() as $child) {
     elementToDB($child, $attributes);
 }
 $experiment = first("SELECT * FROM experiment WHERE id = {$experiment_id}");
 if ($experiment === FALSE) {
     error('Falha ao carregar experimento do banco de dados.');
 }
 $evaluators = query("SELECT id FROM evaluator WHERE experiment_id = {$experiment_id}");
 if (empty($evaluators)) {
     error('Não há avaliadores cadastrados no banco de dados.');
 }
    //echo $_SESSION["nick"]."<br/>";
    $data = file_get_contents("php://input");
    // filtering and decoding code adapted from
    // http://stackoverflow.com/questions/11843115/uploading-canvas-context-as-image-using-ajax-and-php?lq=1
    // Filter out the headers (data:,) part.
    $filteredData = substr($data, strpos($data, ",") + 1);
    // Need to decode before saving since the data we received is already base64 encoded
    $decodedData = base64_decode($filteredData);
    // store in server
    $fic_name = 'fotoperfil' . rand(1000, 9999) . '.png';
    $fp = fopen(GALERIAAJAX . "/{$nick}/" . $fic_name, 'wb');
    $ok = fwrite($fp, $decodedData);
    fclose($fp);
    //elimina foto anterior (si la hay) base datos y fichero
    $imagenAnterior = getSelectP2("select lubri_imagenes.* from lubri_imagenes inner join lubri_usuarios on lubri_imagenes.id=lubri_usuarios.id_imagen_perfil")[0];
    //echo var_dump($imagenAnterior);
    if (isset($imagenAnterior["id"])) {
        getSelectP2("delete from lubri_imagenes where id=?", $imagenAnterior["id"]);
        unlink(GALERIAAJAX . "/{$nick}/" . $imagenAnterior["url"]);
    }
    //inserta foto base datos
    getSelectP2("insert into lubri_imagenes (id_usuario_creador,fecha_creacion,url) values (?,?,?)", $idUsuario, getFechaTime(), $fic_name);
    getSelectP2("update lubri_usuarios set id_imagen_perfil=? where id=?", lastID(), $idUsuario);
    if ($ok) {
        echo GALERIAVISTA . "/{$nick}/" . $fic_name;
    } else {
        echo "ERROR";
    }
} else {
    echo "Ocurrió un fallo con su cuenta";
}
function save_pages()
{
    global $wpdb;
    $id = lastID();
    $pageID = $_POST['publishpages'];
    if (!empty($pageID)) {
        if (sizeof($pageID) > 1) {
            $page = implode(",", $pageID);
        } else {
            $page = implode("", $pageID);
        }
        $result = $wpdb->update(SITEMAP_TABLE, array('sitemap_pages' => $page), array('sitemap_id' => $id));
        if ($result) {
            echo _e('Record updated succesfully');
        } else {
            echo 'Please try again ';
        }
    } else {
        echo 'Please select page';
    }
    wp_die();
}