<?xml version="1.0" encoding="UTF-8"?>
<NeoAppBuilderPlugIn>
  <Title>neoPhp</Title>
  <Author>SinLios</Author>
  <Website>https://visualneo.com</Website>
  <EMail>info@sinlios.com</EMail>
  <Copyright>2022</Copyright>
  <Description>Version: 3.7
Server side php commands.
This plugin needs a neoPHP Server running in order to work properly.
Compile the app before testing!
Test from local server (localhost or local IP in URL).</Description>
  <Icon20>neophp-icon20.png</Icon20>
  <Icon32>neophp-icon32.png</Icon32>
  <CompiledName>C:\Users\sinli\OneDrive\CloudStation\visualneo\VisualNeoWeb\Plugins\neoPhp\neophp.nabp</CompiledName>
  <AutoInstall>no</AutoInstall>
  <Code>function neoPhpSetPath(neophppath){
    $App.NAB.NeoPhpPath=neophppath;
};
function neoPhpSetErrorSubroutine(errorFunc,timeout){
    $App.NAB.NeoPhpTimeOut=timeout;
    $App.NAB.NeoPhpErrorFunc=errorFunc;
};
function neoPhpCheckPath(){
    if (typeof $App.NAB.NeoPhpPath == 'undefined'){
       $App.NAB.NeoPhpPath="neofunctions.php";
    }
    if (typeof $App.NAB.NeoPhpTimeOut == 'undefined'){
       $App.NAB.NeoPhpTimeOut=10000;
    }
    if (typeof $App.NAB.NeoPhpErrorFunc == 'undefined'){
       $App.NAB.NeoPhpErrorFunc=function(){};
    }
};
function neoPhpExecSql(dbName,dbQuery,parameters,callbackFn){
   neoPhpCheckPath();
   $.ajax({
    type: 'POST',
    url: $App.NAB.NeoPhpPath,
    dataType: 'json',
    timeout: $App.NAB.NeoPhpTimeOut,
    data: {
        'funcname': 'execsql',
        'dbname': dbName,
        'dbquery': dbQuery,
        'parameters': parameters
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null) {
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
  });
};
function neoPhpUserLogin(user,pass,callbackFn){
   if(user=="" || pass==""){
     $App.NAB.NeoPhpErrorFunc="User name and Password can't be empty";
     return;
   }
   neoPhpCheckPath();
   $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'login',
        'user': user,
        'pass': pass
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
  });
};
function neoPhpUserChangePassword(userId,oldPassword,newPassword,callbackFn){
   neoPhpCheckPath();
   $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'changeuserpassword',
        'userid': userId,
        'oldpassword': oldPassword,
        'newpassword': newPassword
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
  });
};

function neoPhpUserLogOut(callbackFn){
   neoPhpCheckPath();
   $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'logout'
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
   });
};
function neoPhpUserInsert(userName,userEmail,userPassword,userLevel,callbackFn){
  if(userName=="" || userPassword==""){
     $App.NAB.NeoPhpErrorFunc="User name and Password can't be empty";
     return;
  }
  neoPhpCheckPath();
  $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'adduser',
        'username': userName,
        'useremail':userEmail,
        'userpassword':userPassword,
        'userlevel': userLevel
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
  });
};
function neoPhpUserErase(userId,callbackFn){
  neoPhpCheckPath();
  $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'eraseuser',
        'userid': userId
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
  });
};
function neoPhpFileCopy(sourceFileName,destinationFileName,callbackFn){
  neoPhpCheckPath();
  $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'filecopy',
        'sourcefilename': sourceFileName,
        'destinationfilename': destinationFileName
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
 });
};
function neoPhpFileErase(fileName,callbackFn){
  neoPhpCheckPath();
  $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'fileerase',
        'sourcefilename': fileName
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
 });
};
function neoPhpFileToVar(fileName,varName,callbackFn){
  neoPhpCheckPath();
  $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'filetovar',
        'filename': fileName
    },
    success: function(result){
      $App[varName]=result;
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        if(result!="Error"){
           result="True";
           callbackFn(result);
        }
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
 });
};
function neoPhpFileWrite(fileName,content,append,callbackFn){
  neoPhpCheckPath();
  if(append){
     append="True";
  }else{
     append="False";
  }
  $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'filewrite',
        'filename': fileName,
        'content': content,
        'append': append
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
  });
};
function neoPhpFileWriteFromBase64(fileName,content,callbackFn){
  neoPhpCheckPath();
  $.ajax({
    type: 'POST',
    timeout: $App.NAB.NeoPhpTimeOut,
    url: $App.NAB.NeoPhpPath,
    data: {
        'funcname': 'filewritefrombase64',
        'filename': fileName,
        'content': content
    },
    success: function(result){
      if (callbackFn != "" &amp;&amp; callbackFn !=undefined &amp;&amp; callbackFn !=null){
        callbackFn(result);
      }
    },
    error: $App.NAB.NeoPhpErrorFunc
  });
};</Code>
  <Files>
    <File>neofunctions.php</File>
  </Files>
  <ActionList>
    <Action Name="neoPhpUserLogin">
      <Hint>Login a registered user into the system
Returns a JSON object with user data:
id, username, email, level, error (wich would be empty if no error)</Hint>
      <Params>user|STRING|User name;pass|STRING|Password;callbackFn|FUNCTION|Callback subroutine (will get json user data as a parameter)</Params>
      <Template>neoPhpUserLogin(user,pass,callbackFn);</Template>
    </Action>
    <Action Name="neoPhpUserLogOut">
      <Hint>Log out current user.</Hint>
      <Params>callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpUserLogOut(callbackFn);</Template>
    </Action>
    <Action Name="neoPhpUserInsert">
      <Hint>Add a new user in the "users" table.
Will create database and table if they don't exist.
To be executed an admin user must be logged in (level 0)
Return "True" or error message.</Hint>
      <Params>userName|STRING|User name;userEmail|STRING|User email;userPassword|STRING|User password;userLevel|INTEGER|User level (0=admin, 1=can write, 2=can read);callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpUserInsert(userName,userEmail,userPassword,userLevel,callbackFn);</Template>
    </Action>
    <Action Name="neoPhpUserErase">
      <Hint>Erase a user in "users" table.
To be executed an admin user must be logged in (level 0)
Returns "True" or error message.</Hint>
      <Params>userId|INTEGER|User id;callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpUserErase(userId,callbackFn);</Template>
    </Action>
    <Action Name="neoPhpUserChangePassword">
      <Hint>Change the user password.
Returns "True" or error message
</Hint>
      <Params>userId|INTEGER|User id;oldPassword|STRING|Old password;newPassword|STRING|New password;callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpUserChangePassword(userId,oldPassword,newPassword,callbackFn);</Template>
    </Action>
    <Action Name="neoPhpFileCopy">
      <Hint>Copy a server file to another file name.
A user must be logged in (level 0)
Returns "True" or error message.</Hint>
      <Params>sourceFileName|STRING|The alias name of an existing file on the server with read permission.;destinationFileName|STRING|The alias name of a file on the server with write permission.;callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpFileCopy(sourceFileName,destinationFileName,callbackFn);</Template>
    </Action>
    <Action Name="neoPhpFileErase">
      <Hint>Erase a server file.
A user must be logged in (level 0)
Returns "True" or error message.
</Hint>
      <Params>fileName|STRING|File alias name with write permission (ie: myfile);callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpFileErase(fileName,callbackFn);</Template>
    </Action>
    <Action Name="neoPhpFileToVar">
      <Hint>Read the contents of a file into a variable.
File must have read permission.
Returns "True" or "Error" message.
</Hint>
      <Params>fileName|STRING|File alias name (ie: myfile);varName|VARNAME|Var to store the content;callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpFileToVar(fileName,varName,callbackFn);</Template>
    </Action>
    <Action Name="neoPhpFileWrite">
      <Hint>Writes text content to a server file
File must have write permission.</Hint>
      <Params>fileName|STRING|File alias name (ie: myfile);content|STRING|Content to write;append|BOOLEAN|Append content? (otherwise will replace);callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpFileWrite(fileName,content,append,callbackFn);</Template>
    </Action>
    <Action Name="neoPhpFileWriteFromBase64">
      <Hint>Create a server file from Base64 encoded content
</Hint>
      <Params>fileName|STRING|File name (ie: myfile.jpg);content|STRING|Base64 content (including data type);callbackFn|FUNCTION|Callback subroutine (optional)</Params>
      <Template>neoPhpFileWriteFromBase64(fileName,content,callbackFn)</Template>
    </Action>
    <Action Name="neoPhpSetPath">
      <Hint>Sets the path to php script (neofunctions.php by default)
This is useful if neofunctions.php is published in a remote hosting or you want to change it's name.
For remote, remember to uncomment: header("Access-Control-Allow-Origin: *");</Hint>
      <Params>neophppath|STRING|Path to neofunctions.php (ie https://mydomain.com/myapp/neofunctions.php)</Params>
      <Template>neoPhpSetPath(neophppath);</Template>
    </Action>
    <Action Name="neoPhpExecSql">
      <Hint>Executes an SQL query in a given database.
For SELECT queries, returns a JSON object with the query result.
For any other query returns True or error message.</Hint>
      <Params>dbName|STRING|Database name alias;dbQuery|STRING|SQL query name alias;"params|STRING|Query parameters. Use ""::"" as separator.";callBackFn|FUNCTION|Callback subroutine to get the result (optional)</Params>
      <Template>neoPhpExecSql(dbName,dbQuery,params,callBackFn);</Template>
    </Action>
    <Action Name="neoPhpSetErrorSubroutine">
      <Hint>Define the fucntion to be called when no connection is available.</Hint>
      <Params>errorFunc|FUNCTION|Subroutine to call if connection error;timeout|INTEGER|Timeout in milliseconds (Default 10000)</Params>
      <Template>neoPhpSetErrorSubroutine(errorFunc,timeout);</Template>
    </Action>
  </ActionList>
</NeoAppBuilderPlugIn>
