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

user
object

Stores user data retrieved from the authentication model.

base_url
string

Stores the base URL of the application.

module_tables
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.

Returns

Renders the backend home page with widget data.

editSelected()

Handles editing of selected items based on their type.

Parameters
object

Expects POST data with item details.

Returns

JSON response indicating success or failure.

updatRepo()

Updates repository information for teaser images.

Parameters
object

Expects POST data with repository details.

Returns

JSON response indicating success.

zip()

Creates a zip file from selected images.

Parameters
object

Expects POST data with image sources.

Returns

JSON response with the path to the created zip file.

removeAny()

Removes an item from the database.

Parameters
object

Expects POST data with item details.

Returns

JSON response indicating success or failure.

files_relation(itemtype,item_type, item_id)

Manages file relations for different item types.

item_type
string

The type of item (e.g., ‘artefakte’, ‘ereignis’, ‘person’).

item_id
string

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.

Returns
array

An array containing widget data, including custom, default, and shop widgets.

export()

Exports selected items to a CSV file.

Parameters
object

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.

Parameters
object

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.

Parameters
object

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.

Parameters
object

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.

Parameters
object

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.

Adds a new quicklink for the user.

Parameters
object

Expects POST data with quicklink details (category, table, note).

Returns

JSON response indicating success.

Removes a quicklink for the user.

Parameters
object

Expects POST data with quicklink ID.

Returns

JSON response indicating success.

deleteParticipant()

Deletes a participant from the system.

Parameters
object

Expects POST data with participant ID.

Returns

JSON response indicating success or failure of the deletion.

editParticipant()

Edits details of a participant.

Parameters
object

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.

Parameters
object

Expects POST data with an array of items and their new order.

Returns

JSON response indicating success.

updateStartOrder()

Updates the starting order of items.

Parameters
object

Expects POST data with an array of items and their new starting order.

Returns

JSON response indicating success.

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

Renders a complete page with the specified content view and data.

content_view
string

The name of the view file to be rendered as the main content.

content_data
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.

Parameters
object

Expects POST data with item ID and image details.

Returns

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.

Parameters
object

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.

Parameters
object

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

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.