#1 2015-08-24 19:18:39

CIS
Member
Registered: 2015-08-24
Posts: 3

Modify the Report Sample App to include functions (Add, Edit, Delete)?

Is it possible and can you please modify the sample app "Report" to include these functions (Add, Edit, and Delete) specific records from the "data.php" and "data.json" files after the app has been compiled and run? I want the end user to be able to modify (Add, Edit, and Delete) specific records from the "data.php" and "data.json" files in addition to what it currently does already, which is the ability to retrieve certain records from the "data.php" and "data.json" files via the search query after it has been compiled and run.

Offline

#2 2015-08-24 20:03:37

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Modify the Report Sample App to include functions (Add, Edit, Delete)?

Hello CIS,

Certainly we can prepare the required stuff to not only retrieve and show information from a webserver, allowing to add and edit information too, but probably this is out of the scope of the Report app sample. Maybe we can prepare an specific app sample to doing something like you wanted, however, in the meanwhile, note what are the required stuff in order to do something like that:

1º We firstly need a webserver capable to receive HTTP GET and POST requests and also to store the information in some kind of database like MySQL, for example.

2º We need to prepare some kind of API accesible by HTTP calls in URL like the below ones:

http://www.webserverurl.com/get.php
http://www.webserverurl.com/add.php
http://www.webserverurl.com/edit.php

3º We can use a Report control to process and show the JSON data provided by the "get.php" HTTP requests. Note we can add some arguments to the URL in order to retrieve specific information, for example, this URL:

http://www.webserverurl.com/get.php?page=1

... can produce different results than this other URL:

http://www.webserverurl.com/get.php?page=2

4º The "edit.php" script can be ready to accept some record specific ID, for example:

http://www.webserverurl.com/edit.php?recordID=1

The above URL can respond with a ready to parse variables list text like these:

RecordTitle=The record title
RecordDesc=The record description

We can use the "ParseVariables" action to get the variables from the response and show their content in a couple of Text input controls.

5º The same app view which show that Text input controls can have a Push button to made an HTTP POST request to the same "edit.php" script, providing the updated information of the edited record.

6º In order to add new records to the database we only need the appropiate Input controls and to made an HTTP POST request to the "add.php" script, providing the appropiate record information.

Probably this is not a complete answer since I do not add what you wanted to the Report control, but I tell you how something like that can be made using App Builder. Maybe in the near future we prepare an app sample around this.

Offline

#3 2015-08-24 20:11:05

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Modify the Report Sample App to include functions (Add, Edit, Delete)?

Hello,

As an addition to my previous message I want to say than the Report control is very powerful and right now App Builder include four different samples: Report, Report2, Report3 and Report4.

A Report control can be feed using their URL variable. Then the control automagically perform the HTTP request, retrieve the response and prepare the data to be show into the Report table.

Maybe we are a bit confusing with the samples "data.json" and "data.php" files. In fact we can include files like "data.json" in our apps in order to feed a Report control with the file app local URL.

"data.php", instead, is a sample of how the JSON data can provide from a webserver and therefore can be dinamically changed or updated in order to allow our apps to show the latest information.

On the other hand, the Report control can also be feed by using their "Data" variable instead their "URL" variable. And this can be made at least in two ways: load JSON data using an action like "SimpleGet" or prepare our own JSON object using the object related actions.

This last way is particularly interesting because we prepare the JSON object in runtime and therefore such object can contains different information in different scenarios. The App Builder's Report3 and Report4 show to us how to do something like this.

That's all! Hope this information can be useful!

Don't forget to play with the App Builder's app samples!

Offline

#4 2015-08-25 19:13:05

CIS
Member
Registered: 2015-08-24
Posts: 3

Re: Modify the Report Sample App to include functions (Add, Edit, Delete)?

Hello,

Yes i have extensively played with all 57 app samples in the App Builder including Report, Report2, Report3 and Report4 as you suggested. In fact, i am very confused with your latest message about "SimpleGet". In fact i have modified the code in the sample app "Report" to this:

InputBox "Edit/Modify" "Save|Delete" "" "info" "StrReplace [Record.ID] [Record.Name] [Sport]"
HttpExecute "app/files/data.php"
SimplePost "app/files/data.php" "Record.ID:InputBox" "[Report1.Query]"
SimpleGet "app/files/data.json"

What i really would like is to be able to allow the end user to modify (Add, Edit, and Delete) specific records locally (http://127.0.0.1:9999) from the "data.php" and "data.json" files in addition to what the Report sample app currently does already, which is the ability to retrieve certain records from the "data.php" and "data.json" files via the search query after it has been compiled and run. After i get that working locally first and fully functional, then i will connect it to an MySQL database in the Microsoft Azure Cloud via their "Mobile Services" feature. I can and have already compiled and ported the Report sample app to an Xcode project via Apache Cordova CLI where it works locally as a native iOS platform via the simulator just fine so far.

Last edited by CIS (2015-08-25 19:51:23)

Offline

#5 2015-08-25 20:40:32

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Modify the Report Sample App to include functions (Add, Edit, Delete)?

Hello CIS,

First of all, note than the "InputBox" action callback must be an app function, not an action like "StrReplace" as you write. Take a look at the InputBox app sample for more information. On the other hand, probably you need to decide what action execute next: "HttpExecute", "SimplePost" and "SimpleGet" probably cannot be called like you write above.

If you choose to use the HttpClient control to made an HTTP POST it's ok, but you no need to call "SimplePost" at all. On the other hand, "SimplePost" do not offer any feedback, then maybe it's not the right action in your case. Finally you call the "SimpleGet" action, but, again, probably you no need to do something like that CIS.

You can play with the app using a local webserver (*), just remember that if you want to use PHP and MySQL these stuff must be available and running in the local webserver too. We need to think our app is a act like a web page in these scenarios, and therefore we must made the appropiate HTTP GET and POST requests. We can need more or less calls, the Report control or others,  depending of the app we made.

If you start with the app I can help you in some particular points when you need! In other case I can't promise when I a possible app sample like you wanted can be ready since I am very busy right now with other App Builder stuff.

(*) Remember that App Builder debugger starts an HTTP local server, then, if you need to work with other local server you must use different ports. By default App Builder uses the 9999 port and this can be changed in the program options dialog from the Menu -> Edit -> Program options.

Offline

#6 2015-08-25 22:16:21

CIS
Member
Registered: 2015-08-24
Posts: 3

Re: Modify the Report Sample App to include functions (Add, Edit, Delete)?

Okay, i have created from scratch these 5 PHP files in Visual Studio Code and placed them in the folder directory of Report where "data.php" is located.

File #1 (Config.php):

<?php
$query=mysql_connect("localhost","root","");
mysql_select_db("cis_report_demo",$query);
?>

File #2 (Add.php):

<html>
<body>
<?php
include('config.php');
if(isset($_POST['submit']))
{
$name=mysql_real_escape_string($_POST['name']);
$age=mysql_real_escape_string($_POST['age']);
$query1=mysql_query("insert into addd values('','$name','$age')");
echo "insert into addd values('','$name','$age')";
if($query1)
{
header("location:list.php");
}
}
?>
<fieldset style="width:300px;">
<form method="post" action="">
Name: <input type="text" name="name"><br>
Age: <input type="text" name="age"><br>
<br>
<input type="submit" name="submit">
</form>
</fieldset>
</body>
</html>

File #3 (List.php):

<html>
<body>
<?php
include('config.php');
$query1=mysql_query("select id, name, age from addd");
echo "<table><tr><td>Name</td><td>Age</td><td></td><td></td>";
while($query2=mysql_fetch_array($query1))
{
echo "<tr><td>".$query2['name']."</td>";
echo "<td>".$query2['age']."</td>";
echo "<td><a href='edit.php?id=".$query2['id']."'>Edit</a></td>";
echo "<td><a href='delete.php?id=".$query2['id']."'>x</a></td><tr>";
}
?>
</ol>
</table>
</body>
</html>

File #4 (Edit.php):

<html>
<body>
<?php
include('config.php');
if(isset($_GET['id']))
{
$id=$_GET['id'];
if(isset($_POST['submit']))
{
$name=$_POST['name'];
$age=$_POST['age'];
$query3=mysql_query("update addd set name='$name', age='$age' where id='$id'");
if($query3)
{
header('location:list.php');
}
}
$query1=mysql_query("select * from addd where id='$id'");
$query2=mysql_fetch_array($query1);
?>
<form method="post" action="">
Name:<input type="text" name="name" value="<?php echo $query2['name']; ?>" /><br />
Age:<input type="text" name="age" value="<?php echo $query2['age']; ?>" /><br /><br />
<br />
<input type="submit" name="submit" value="update" />
</form>
<?php
}
?>
</body>
</html>

File #5 (Delete.php):

<html>
<body>
<?php
include('config.php');
if(isset($_GET['id']))
{
$id=$_GET['id'];
$query1=mysql_query("delete from addd where id='$id'");
if($query1)
{
header('location:list.php');
}
}
?>
</body>
</html>

With that in mind, how can i incorporate all this code (5 PHP files) that i have created from scratch into the Report app sample in App Builder via a detailed step by step instruction from you. I have installed fully the MySQL Server 5.7.8 and all of its associated products such as Workbench 6.3.4,  Notifier 1.1.16 and so forth

Offline

#7 2015-08-25 22:37:28

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Modify the Report Sample App to include functions (Add, Edit, Delete)?

Hello CIS,

I think your PHP do not look what we can expect. For example, your PHP scripts produce HTML code, which is something that your app do not expect. Your app provide all the required HTML, you no need to worry about it in the PHP scripts. These scripts must "act" when are requested and must responde with the appropiate data. No more.

You no need an HTML form to send information to your PHP scripts: you must use the Input controls what you need and then use the Http client control to perform the appropiate HTTP POST request. On the same way, you no need to list your database data by output it from PHP scripts. Your scripts must return JSON data that the Report control can parse and show automatically for you.

I am very sorry because this app sample are not trivial at all, probably take me several hours, and currently I am very busy with other project areas. Again, try to understand what you need and ask here for help when you needed. I am very sorry but I can't say other thing at this time. Just remember:

1º add.php - Need to receive POST data and their response can be, for example, just an "OK" or "Fail", in order to understand from our app the data has been added.

2º edit.php - Need to receive POST data and their response can be, again, just an "OK" or "Fail", in order to understand from our app the data has been updated or not.

3º list.php - Only need to return the appropiate data as a JSON object. This script must be very similar to the "data.php" you can found in the current app samples. That JSON object is parsed and show by the Report control.

4º delete.php - Need to receive POST data and their response can be the same than "add.php" and "edit.php".

On the other hand, remember we need to enable "CORS" requests in our PHP scripts. You can view how by read the "data.php" refered above and included into the Report app sample. This may are not needed for the local web served files (probably not) but "CORS" must be enabled for our PHP scripts when use a remote server.

Offline

#8 2015-10-20 14:02:47

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: Modify the Report Sample App to include functions (Add, Edit, Delete)?

Hello CIS,

Better late than never, App Builder include right now a new Database app sample wich show us how to use a Report control along with HTTP Client controls to retrieve and list information from a remote database and also update, delete and insert new information in such database. To this app sample we use PHP and MySQL in the server, and the PHP scripts and the MySQL database estructure are included in the app sample too.

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.