Skip to main content

Overview

The Backend 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

object
Stores user data retrieved from the authentication model.
string
Stores the base URL of the application.
array
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.
Renders the backend home page with widget data.

editSelected()

Handles editing of selected items based on their type.
object
Expects POST data with item details.
JSON response indicating success or failure.

updatRepo()

Updates repository information for teaser images.
object
Expects POST data with repository details.
JSON response indicating success.

zip()

Creates a zip file from selected images.
object
Expects POST data with image sources.
JSON response with the path to the created zip file.

removeAny()

Removes an item from the database.
object
Expects POST data with item details.
JSON response indicating success or failure.

files_relation(itemtype,item_type, item_id)

Manages file relations for different item types.
string
The type of item (e.g., ‘artefakte’, ‘ereignis’, ‘person’).
string
The ID of the item.
Renders the file relation page or displays an error.

widget_data()

Retrieves and prepares widget data for the dashboard.
array
An array containing widget data, including custom, default, and shop widgets.

export()

Exports selected items to a CSV file.
object
Expects POST data with export details.
JSON response with the path to the exported file or an error message.

Helper Methods

upload_image()

Handles image upload.
JSON response with upload details.

upload_file()

Handles file upload.
JSON response with upload details.

checkLoggedin()

Checks if the user is logged in.
JSON response indicating login status.

Additional Methods

add_delete_file_relation()

Manages the addition or deletion of file relations for different entity types.
object
Expects POST data with item details, file details, and relation status.
JSON response indicating success or failure of the operation.

get_update_file_order()

Updates the order of files associated with an entity.
object
Expects POST data with item details and new file order.
JSON response with updated file information or error details.

add_widget()

Adds a new widget to the user’s dashboard.
object
Expects POST data with widget details (category, table, icon, color, note).
JSON response indicating success.

remove_widget()

Removes a widget from the user’s dashboard.
object
Expects POST data with widget ID.
JSON response indicating success.

refresh_widgets()

Refreshes the widget data for the user’s dashboard.
JSON response with updated HTML for widgets.
Adds a new quicklink for the user.
object
Expects POST data with quicklink details (category, table, note).
JSON response indicating success.
Removes a quicklink for the user.
object
Expects POST data with quicklink ID.
JSON response indicating success.

deleteParticipant()

Deletes a participant from the system.
object
Expects POST data with participant ID.
JSON response indicating success or failure of the deletion.

editParticipant()

Edits details of a participant.
object
Expects POST data with updated participant details.
JSON response indicating success or failure of the edit operation.

updateSorting()

Updates the sorting order of items.
object
Expects POST data with an array of items and their new order.
JSON response indicating success.

updateStartOrder()

Updates the starting order of items.
object
Expects POST data with an array of items and their new starting order.
JSON response indicating success.

page(contentview,content_view, content_data = array())

Renders a complete page with the specified content view and data.
string
The name of the view file to be rendered as the main content.
array
Optional. An array of data to be passed to the content view.
This method handles the overall page structure, including:
  • 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.
object
Expects POST data with item ID and image details.
JSON response indicating success.

Custom Menu Handling

The page() 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:
  1. Retrieves Lecker areas using $this->bm->getLeckerAreas().
  2. For each area, it retrieves associated menus using $this->bm->getLeckerMenus($area_id).
  3. For each menu, it retrieves submenus using $this->bm->getLeckerSubmenus($menu_id).
  4. 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.
object
Expects POST data with:
  • filename: The original name of the file
  • uploadpath: The server path where the file should be uploaded
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.
object
Expects POST data with:
  • filename: The original name of the file
  • uploadpath: The server path where the file should be uploaded
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.
JSON response with:
  • success: Boolean indicating if the user is logged in
This method can be used for AJAX requests to verify user authentication status without reloading the page.

Error Handling and Validation

Throughout the controller, there are several instances of error checking and validation:
  1. Database table existence checks using $this->tableExists().
  2. Method existence checks using $this->methodExists().
  3. POST data validation using $this->postPropertiesExist().
These checks help ensure that the necessary database structures and methods are in place before operations are performed, reducing the risk of runtime errors.

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
These constants appear to control various aspects of the application’s behavior and appearance.

Integration with External Libraries

The constructor loads several external libraries:
  • FPDF
  • FPDI
  • PHPExcel
These libraries are likely used for PDF generation and Excel file manipulation, although the specific usage is not visible in the provided code snippet.
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.

Conclusion

The Backend controller serves as a central hub for various administrative and backend operations in the application. It handles user authentication, file management, custom menu generation, and various entity-specific operations. The controller makes extensive use of model methods for database operations and includes several utility methods for common tasks. For a complete understanding of the system, it’s crucial to review the associated models, views, and configuration files that interact with this controller.