SOAP PHP and angular - javascript

I'm trying to consume a SOAP Web Service used in a PHP file.
When I access the PHP file directly, it works. (http://bacly.fr/baclymphp/getffbadsample.php)
When I try to access it from an AngularJS like this:
function loadwsffbad() {
var players={}
var urlphp="http://localhost/cordova/mbacly/www/php/";
$http.get(urlphp+"getffbadsample.php").then(function(data) {
players = data.data;
console.log(players);
},function(status) {
alert("pas d accès réseau");
});
}
I get this in console:
Fatal error: Class 'SoapClient' not found in C:\wamp\www\cordova\mbacly\www\php\getffbadsample.php on line 5
I saw in other posts that I need to check that SOAP is enabled on the server, which is the case (http://bacly.fr/baclymphp/info.php), As it works directly with the php file, I guess it is not the pb.
getffbadsample.php:
<?php
$clientSOAP = new SoapClient('http://ws.ffbad.com/FFBAD-WS.wsdl');
$Auth["Login"]="******";
$Auth["Password"]="*****";
//Encodage de vos identifiants en Json (sérialisation des objets)
$AuthJson = json_encode($Auth);
$Query["Function"]="ws_getresultbylicence";
$Query["Param"]["Licence"]="06468814";
$QueryJson = json_encode($Query);
//Appel de la fonction distante
$Return = $clientSOAP->getResult($QueryJson,$AuthJson);
echo $Return;
?>
Thank for your help.

Related

empty (blank) fetch data return from php

I am sending an id by fetch to php to fetch the name of a project. Now when I am sending this result to console to verify that it brings it correctly but it only brings a blank or empty space. Thank you very much if you got this far
Javascript, where you capture the id by clicking and sending the id by fetch
var enlaces=document.getElementsByClassName('enlace');
for(let el of enlaces){
el.addEventListener('click', obtener_id_proyecto);
}
function obtener_id_proyecto(e){
e.preventDefault();
console.log('presionaste en un proyecto');
var id_p=this.id;
//Enviando datos por Fetch
let datos=new FormData();
datos.append('id', id_p);
fetch('inc/funciones/funciones.php',{
method: 'POST',
headers:{'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify(datos)
})
.then(function(response) {
if(response.ok) {
return response.text();
} else {
throw "Error en la llamada Ajax";
}
})
.then(function(datosRecididos){console.log(datosRecididos)});
}
PHP
function obtenerNombreProyecto(){
$id_proyecto=$_POST['id'];
include 'conexion.php';
try{
$sql= mysqli_query($conexion,"SELECT nombre FROM proyectos WHERE id = {$id_proyecto}");
return json_encode($sql);
} catch(Exception $e){
echo "Error! : ". getMessage($e);
return false;
}
}
Console screenshot
https://prnt.sc/9Cr8fKRuqAX1
Probably there is a problem with this address: './inc/funciones/funciones.php'. Are you sure about that? Why you put a . in the beginning of it?

Codeigniter Can't change view page

I need your help with an issue that is dragging me crazy.
You have to know that My view page has 4 view pages called: Header, Menu, Sub menu and Content and I'm using SQL database to store the information the user fill in Content.
I want to change Content page after the user hit submit button.
The submit button will call a JS that arranges the information into an array and call a controller function that call a database function and fill the table and send a TRUE if the table was filled. After all that code, I take the created array and TRUE and send it to a new Content view and display the information that the user filled and tell him "upload success".
The main problem is the new content view isn't showing, I checked the database and the information is uploaded. This is part of the controller function that is sended to the database.
This is the Javascript, i'm using ajax.
$("#btn_enviar").click(function(){
var r = confirm("Los datos ingresados no podran ser modificados una vez enviados, presione aceptar si desea continuar");
if (r == true){
var url = base_url + "/inventario/insert_inventario";
$.ajax({
type: "POST",
url: url,
data: $("#form_inventario").serialize(),
success: function(data)
{
$("#contenido").html(data.mensaje);
}
});
var elem = document.getElementById('btn_enviar');
}
return false;
});
This is the Controller. array_db is the array with the user information.
$obj_inv = $this->Inventario_model->insert_inventario($array_db);
if($obj_inv){
$edit_view = $this->load->view(base_url()."inventario/edit",$array_db,TRUE);
$response = array('mensaje' => $edit_view
);
$this->output
->set_status_header(200)
->set_content_type('application/json', 'utf-8')
->set_output(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
->_display();
exit;
} else {
echo('ERROR: Uno o mas datos son incorrectos o no estan llenados.');
}
This is the model. Inventario_model is the function that calls the database and return a True or False is the information is inserted.
public function insert_inventario($array_data) {
$id = $this->db->insert('inventario',$array_data);
$obj_activo = $this->db->get('inventario');
return $id;
}
What I'm missing? Why the edit view isn't showing?
The only clue I have is, in development Console is throwing me this:
http://[IP]/Inventario_Remedy/inventario/insert_inventario Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Edited to show the error log
PHP 1. {main}() C:\Xampp\htdocs\Inventario_Remedy\index.php:0
PHP 2. require_once()
C:\Xampp\htdocs\Inventario_Remedy\index.php:293
PHP 3. call_user_func_array()
C:\Xampp\htdocs\Inventario_Remedy\system\core\CodeIgniter.php:514
PHP 4. Inventario->insert_inventario()
C:\Xampp\htdocs\Inventario_Remedy\system\core\CodeIgniter.php:514
PHP 5. Inventario_model->insert_inventario()
C:\Xampp\htdocs\Inventario_Remedy\application\controllers\Inventario.php:105
PHP 6. CI_DB_query_builder->insert()
C:\Xampp\htdocs\Inventario_Remedy\application\models\Inventario_model.php:29
PHP 7. CI_DB_driver->query()
C:\Xampp\htdocs\Inventario_Remedy\system\database\DB_query_builder.php:1608
PHP 8. CI_DB_driver->display_error()
C:\Xampp\htdocs\Inventario_Remedy\system\database\DB_driver.php:675
PHP 9. CI_Exceptions->show_error()
C:\Xampp\htdocs\Inventario_Remedy\system\database\DB_driver.php:1698
PHP 10. _error_handler()
C:\Xampp\htdocs\Inventario_Remedy\system\database\DB_driver.php:182
PHP 11. CI_Exceptions->show_php_error()
C:\Xampp\htdocs\Inventario_Remedy\system\core\Common.php:623
CI VERSION 3.0

Cant upload files from mobile version to classic version directory, same domain

im currently having an issue with the upload of files from the mobile version of the site im currently working with, I think the issue is related to the fact that the mobile version files are outside the public_hmtl folder inside a folder named m, this was done like this because the m.site.com link wouldnt work otherwise, since im using the classic site folder to store all the media, the problem starts here:
heres the path im working with:
/
/m
/public_html
the file in
/m/user/fnc/upload.php
is directed to save an img to
/public_html/photos/users/
here's a fragment of the code in upload.php
for the first line, I use a redirect variable called $img that leads to the index of the classic version, that would be
www.mysite.com/
so
$URL = $img.'photos/users/';
$NewFotoName = "misite_".$usuarioid."_".time().".jpg";
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$imagen = $_POST['Imagen'];
if ( isset($_POST['Imagen']) ) {
$image = base64_decode($imagen);
$im = imagecreatefromstring($image);
imagepng($im,$URL.$NewFotoName);
imagedestroy($im);
$query = "UPDATE Utenti SET foto = '$NewFotoName' WHERE id_utente = ".$usuarioid;
$result = $mysqli->query($query);
if(!$result){die($mysqli->error);}
echo "index2.php";
die();
} else {
echo "index2.php";
die();
}
} else {
echo "index2.php";
die();
}
and i call it from a file one folder above it called index2.php with this code:
$('.upload-result').on('click', function (ev) {
$uploadCrop.croppie('result', {
type: 'canvas',
size: 'original'
}).then(function (resp) {
$('#imagebase64').val(resp);
var imagen_cortada = $('#imagebase64').val();
var base64image = imagen_cortada;
var parametros = { "Imagen" : base64image };
$.ajax({
data: { "Imagen" : output },
url: 'fnc/upload.php',
method: 'POST', // or GET
success: function(msg)
{
alert("Imagen subida con exito.");
alert(msg);
},
error: function (jqXHR, textStatus, errorThrown)
{
alert("Error al Subir la Imagen.");
alert(errorThrown);
window.location.replace(msg);
}
});
now when the form is submited I get a succes alert but in the "alert(msg);" I get an error that says
imagepng(path/to/the/file.png): failed to open stream; no such file or
directory in /home/mysite/m/user/fnc/upload.php
So the name of the file gets saved into the database but the file doesnt.
I appreciate any suggestions, excuse any spelling mistakes.
//edit
I found a work arround and moved the subdomaind directory inside public_html, had to learn a bit about the .htacces, it seems this way i will not have all those pesky permision problems
I found a work arround and moved the subdomaind directory inside public_html, had to learn a bit about the .htacces, it seems this way i will not have all those pesky permision problems, the other workarrounds posted in the similar thread Vic Seedoubleyew posted didnt seem to do the trick for me

Parsing output of textarea in Javascript

I have a HTML form with a textarea in it.
When entering a text with some enters in it, my Javascript malformes and wont load.
The forms submits to a PHP script that outputs the javascript below.
How can I fix this?
function confirmsms() {
var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan");
if (redirect == true) {
window.location.href = 'send.phpregio=%&vakgebied=Loodgieter&disciplines=&bericht=aasdasd
asdasda
sdasdasd';
}
}
</script>
Change to this:
function confirmsms() {
var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan");
if (redirect == true) {
window.location.href = 'send.php?'
+ 'regio=%&vakgebied=Loodgieter&disciplines=&'
+ 'bericht=aasdasdasdasdasdasdasd';
}
}
UPDATE: It seems that your php variable $b‌​ericht has line returns in it. Let's sanitize the variable to remove spaces and line returns like so:
$bericht = str_replace(array(' ', "\n", "\t", "\r"), '', $bericht);
Then you can use your code as before. To be safe, I would sanitize all your php variables that are going to be dropped right into javascript.
<HTML>
<HEAD>
<script type=\"text/javascript\">
function confirmsms() {
var redirect = confirm(\"Er zullen $count smsjes worden verzonden, klik op OK om door te gaan\");
if (redirect == true) {
window.location.href = 'send.php?regio=$regio&vakgebied=$vakgebied2&disciplines=$disciplines&bericht=$b‌​ericht'; }
}
Looks like the problem is you are not encoding your URL! As in your problem you are passing data using GET method your data will be the part of the URL itself!
Simply use encodeURI() before sending! So your code should look like
function confirmsms() { var redirect = confirm("Er zullen 791 smsjes worden verzonden, klik op OK om door te gaan"); var encodedValue = encodeURI("YOUR TEXTAREA VALUE HERE"); if (redirect == true) { window.location.href = 'send.php?VAR1=VAL1&VAR2=VAL2'; }}
And at the back-end you can decode URL using string urldecode ( string $str )
Hope you this is what you are looking for!

How to call javascript function in the index of a controller in codeigniter?

I'm trying to call a javascript function inside my controller to display a warning message in page if a verification I do in the index function of this controller is false.
Here is my code:
<?php
public function index() {
$this->load->model('uploads_m');
$this->load->helper('form');
$template_vars = Array();
$this->load->vars($template_vars);
$data = Array();
$data['currentUploadId'] = $this->uploads_m->get_lastUploadId();
$data['fileTypes'] = $this->uploads_m->getAllFileTypes();
$data['existingFiles'] = Array();
if (isset($data['currentUploadId'])) {
$data['existingFiles'] = $this->uploads_m->get_UploadedFilesFromUploadId($data['currentUploadId']);
}else {
// TODO create warning message to tell that uploadid was not generated
}
$this->load->view('include/header');
$this->load->view('upload_files', $data);
$this->load->view('include/footer');
}
?>
I have a JS function stored in an extern js file that I wanted to call in this TODO.
It should be called this way :
show_msg_xajax("warning", "System was unable to find an Upload ID");
Since the check condition is being done in the index() of the controller, I don't know how to call this js function.
if it was being invoked by an event in the view, I'd create an ajax method to execute this function. but how can I call the javascript function it in the index()?
I already checked this answer: Calling javascript function from controller codeigniter but it didn't help me.
The solution I found was to send the function directly to the footer of that page... so I added a new variable to a footer template I have (where I call my javascripts).
in the index function in the controller I did:
if (isset($data['currentUploadId'])) {
$data['existingFiles'] = $this->uploads_m->get_UploadedFilesFromUploadId($data['currentUploadId']);
} else {
// TODO criar alerta de erro no sistema que não gerou UPLOADID
$template_vars['foot_javascripts_inline'] = 'show_msg_xajax("error", "System was unable to find an Upload ID");';
}
and in my footer template I added:
if (isset($foot_javascripts_inline)) { ?>
<script> <?php echo $foot_javascripts_inline ?> </script>
}
Thanks anyway for the help
You need to add your file with JS function as a view:
$this->load->view('path-to-js-message');

Categories

Resources