progetto201 API
Functions | Variables
userplan.php File Reference

USERPLAN: manages user's plan (returns paths and names). More...

Functions

 get_userplan ($t_conn_res)
 This function returns data relative to the plan selected from the user. More...
 
 userplan_isvalid ($t_plan_data)
 Checks if plan data is valid. More...
 
 post_userplan ($t_conn_res)
 Sets user's desired plan. More...
 

Variables

 $response = array("errors" => array())
 Prepare default response array with no errors. More...
 
 $planspath = $_SERVER["DOCUMENT_ROOT"] . DIRECTORY_SEPARATOR . "static" . DIRECTORY_SEPARATOR . "img" . DIRECTORY_SEPARATOR . "maps"
 Plan's path (file system) More...
 

Detailed Description

USERPLAN: manages user's plan (returns paths and names).

Client perspective:

The script tries to connect to the database and then checks the request method.

If the method is GET get_userplan() is called. Else post_userplan() is called.

userplan_isvalid() is used to check if plan's data is correct

Error codes:

Since
01_01
Author
Stefano Zenaro (https://github.com/mario33881)

Function Documentation

◆ get_userplan()

get_userplan (   $t_conn_res)

This function returns data relative to the plan selected from the user.

The function selects the plan name from the options table inside the database, concatenates the expected plan path with the name and returns both path and name inside an array.

Errors list:

  • 510: The query returned an unexpected number of records
  • 511: Error during query execution
Since
01_01
Parameters
array$t_conn_resfile system path with plans
Returns
array $action_res array with errors or plans data

◆ post_userplan()

post_userplan (   $t_conn_res)

Sets user's desired plan.

First it checks if the client passed the plan name, then it checks if its expected path is valid using the userplan_isvalid() function.

After that it executes an UPDATE query to set the new plan.

Errors list:

  • 530: Unable to change the current plan for the new one
  • 531: Unable to execute UPDATE query
  • 532: Parameter 'name' wasn't set
Since
01_01
Parameters
array$t_conn_resarray with connection object or errors
Returns
array $action_res array with color data or errors

◆ userplan_isvalid()

userplan_isvalid (   $t_plan_data)

Checks if plan data is valid.

To do this first its existance is checked using file_exists() function, then the function checks the mime type (it must be "SVG") If data is valid the "data" value will be true. Else the returned array has errors data.

Errors list:

  • 520: file is not an SVG file
  • 521: file not found
Since
01_01
Parameters
array$t_plan_dataplan's data to validate
Returns
array $isvalid_res array with errors or true

Variable Documentation

◆ $planspath

$planspath = $_SERVER["DOCUMENT_ROOT"] . DIRECTORY_SEPARATOR . "static" . DIRECTORY_SEPARATOR . "img" . DIRECTORY_SEPARATOR . "maps"

Plan's path (file system)

◆ $response

$response = array("errors" => array())

Prepare default response array with no errors.