Overview
TheBackend
class extends MY_Controller
and handles various backend operations for a web application. It includes functions for user authentication, file management, widget handling, and data export.
Class Properties
Stores user data retrieved from the authentication model.
Stores the base URL of the application.
Stores an array of module tables.
Constructor
The constructor performs the following actions:- Checks if the user is logged in
- Loads necessary libraries (zip, form_validation, fpdf, FPDI, PHPExcel)
- Initializes the user data
Main Methods
index()
Displays the main backend dashboard.Returns
Renders the backend home page with widget data.
editSelected()
Handles editing of selected items based on their type.Expects POST data with item details.
Returns
JSON response indicating success or failure.
updatRepo()
Updates repository information for teaser images.Expects POST data with repository details.
Returns
JSON response indicating success.
zip()
Creates a zip file from selected images.Expects POST data with image sources.
Returns
JSON response with the path to the created zip file.
removeAny()
Removes an item from the database.Expects POST data with item details.
Returns
JSON response indicating success or failure.
files_relation(item_id)
Manages file relations for different item types.The type of item (e.g., ‘artefakte’, ‘ereignis’, ‘person’).
The ID of the item.
Returns
Renders the file relation page or displays an error.
widget_data()
Retrieves and prepares widget data for the dashboard.An array containing widget data, including custom, default, and shop widgets.
export()
Exports selected items to a CSV file.Expects POST data with export details.
Returns
JSON response with the path to the exported file or an error message.
Helper Methods
upload_image()
Handles image upload.Returns
JSON response with upload details.
upload_file()
Handles file upload.Returns
JSON response with upload details.
checkLoggedin()
Checks if the user is logged in.Returns
JSON response indicating login status.
Additional Methods
add_delete_file_relation()
Manages the addition or deletion of file relations for different entity types.Expects POST data with item details, file details, and relation status.
Returns
JSON response indicating success or failure of the operation.
get_update_file_order()
Updates the order of files associated with an entity.Expects POST data with item details and new file order.
Returns
JSON response with updated file information or error details.
add_widget()
Adds a new widget to the user’s dashboard.Expects POST data with widget details (category, table, icon, color, note).
Returns
JSON response indicating success.
remove_widget()
Removes a widget from the user’s dashboard.Expects POST data with widget ID.
Returns
JSON response indicating success.
refresh_widgets()
Refreshes the widget data for the user’s dashboard.Returns
JSON response with updated HTML for widgets.
add_quicklink()
Adds a new quicklink for the user.Expects POST data with quicklink details (category, table, note).
Returns
JSON response indicating success.
remove_quicklink()
Removes a quicklink for the user.Expects POST data with quicklink ID.
Returns
JSON response indicating success.
deleteParticipant()
Deletes a participant from the system.Expects POST data with participant ID.
Returns
JSON response indicating success or failure of the deletion.
editParticipant()
Edits details of a participant.Expects POST data with updated participant details.
Returns
JSON response indicating success or failure of the edit operation.
updateSorting()
Updates the sorting order of items.Expects POST data with an array of items and their new order.
Returns
JSON response indicating success.
updateStartOrder()
Updates the starting order of items.Expects POST data with an array of items and their new starting order.
Returns
JSON response indicating success.
page(content_data = array())
Renders a complete page with the specified content view and data.The name of the view file to be rendered as the main content.
Optional. An array of data to be passed to the content view.
- Loading user data
- Setting up CSS and JS files
- Loading menu points
- Setting up custom menus
- Rendering the header, menu, content, and footer views
save_images()
Saves image information for an artwork item.Expects POST data with item ID and image details.
Returns
JSON response indicating success.
Custom Menu Handling
Thepage()
method includes logic for setting up custom menus. Here’s a detailed breakdown of this process:
Custom Menu Generation
The controller retrieves and structures custom menu data using the following process:- Retrieves Lecker areas using
$this->bm->getLeckerAreas()
. - For each area, it retrieves associated menus using
$this->bm->getLeckerMenus($area_id)
. - For each menu, it retrieves submenus using
$this->bm->getLeckerSubmenus($menu_id)
. - The resulting structure is stored in
$data['custom_menus']
for use in the view.
The custom menu generation relies on the existence of
lecker_areas
, lecker_menus
, and lecker_submenus
tables in the database.File Upload Handling
The controller includes two methods for handling file uploads:upload_image()
Handles image file uploads.Expects POST data with:
- filename: The original name of the file
- uploadpath: The server path where the file should be uploaded
Returns
JSON response with:
- success: Boolean indicating if the upload was successful
- path: The server path where the file was saved
- filename: The new filename of the uploaded file
upload_file()
Handles general file uploads.Expects POST data with:
- filename: The original name of the file
- uploadpath: The server path where the file should be uploaded
Returns
JSON response with:
- success: Boolean indicating if the upload was successful
- path: The server path where the file was saved
- filename: The filename of the uploaded file
Both upload methods use the
move_uploaded_file()
PHP function to handle the actual file transfer.Authentication Handling
The controller includes a method for checking user authentication status:checkLoggedin()
Checks if the user is currently logged in.Returns
JSON response with:
- success: Boolean indicating if the user is logged in
Error Handling and Validation
Throughout the controller, there are several instances of error checking and validation:- Database table existence checks using
$this->tableExists()
. - Method existence checks using
$this->methodExists()
. - POST data validation using
$this->postPropertiesExist()
.
Constants and Configuration
The controller references several constants that are likely defined in a configuration file:BASEPATH
DB_NAME
NUMBER_OF_LANGUAGES
MAIN_LANGUAGE
IS_SHOP
ITEMS_COLOR
IMAGES_COLOR
FILES_COLOR
Integration with External Libraries
The constructor loads several external libraries:- FPDF
- FPDI
- PHPExcel
The use of external libraries may introduce dependencies and potential security risks. Ensure that these libraries are kept up-to-date and that their usage complies with your application’s security requirements.