Create own module

    Introduction

    Starting with Screen Squid 1.15, it’s possible to expand the functionality of Screen Squid by adding new features and using them within a “single window”. Here is information on how to add a new module and, as an example, the "Hello World" module will be written in PHP.

    Development environment

    In order to start developing a module, you will need:

    • installed PHP interpreter> 5.3 version;
    • any convenient means for writing code (for example, Geany, Atom, Notepad, or others);
    • deployed on a web server distribution Screen Squid> = 1.15 version.

    Composition of the module

    A module necessarily consists of files:

    No. Name Description
    1 index.php Frontend for the user. Here it is necessary to display some text and / or functionality that the user will see by clicking on the module name on the "Manager modules" page.
    2 module.php This module class is described with the necessary functions and procedures.

    Important note : having come up with the name of the module, for example HelloWorld, you must create the HelloWorld directory in the / screensquid / modules directory.

    Important Note 2 : The class name must exactly match the name of the directory in which the module is located. For example, in the HelloWorld directory, in the module.php file, the class should be declared like this - class HelloWorld. The name is case sensitive.

    You can create additional files, for example, if you need them to navigate different pages of the module. In some modules, we add Perl scripts that are used in the backend, for example, to calculate traffic by alias in the Quotas module. In other words, you can create as many files as you like in the directory, in any programming language if your module needs them.

    Required Class Functions

    When creating a module class, the following functions are required:

    No. Function Name Description
    1 \ __ construct The module constructor is called when an instance of the object is created in the index.php of the module. It is recommended here to create a database connection and connect module language files.
    2 GetDesc Returns a description of the module. For example, "HelloWorld module that does nothing."
    3 Install Performs the necessary steps to install the module. Called from the module manager interface by clicking the "Install" link. After successful installation, reload the page. You will see the name of your module by expanding the list of "Manager modules" in the main menu.
    4 Uninstall Performs the necessary actions to remove the module. Called from the module manager interface by clicking the "Uninstall" link

    In order for Screen Squid to “know” that the module is installed, you need to enter the information in the scsq_modules table. An example of a SQL query to add a module to a table:

    INSERT INTO scsq_modules (name,link) VALUES ('HelloWorld','modules/HelloWorld/index.php');";
    

    Let's write the code

    module.php

    <?php
    
    class HelloWorld
    {
        #In array $variables we caught parameters to connect to database
    function __construct($variables){ // 
    
        $this->vars = $variables;
    
        $this->ssq = new ScreenSquid($variables); #get main class object
    
    }
    
      function GetDesc()
      {
    
          return "Module HelloWorld, which does nothing"; 
    
      }
    
      function Install()
      {
        #try update scsq_modules table
            $UpdateModules = "
            INSERT INTO scsq_modules (name,link) VALUES ('HelloWorld','modules/HelloWorld/index.php');";
    
            $result=$this->ssq->query($UpdateModules) or die ("Can`t update module table");
    
            $this->ssq->free_result($result);
    
            echo "Module installed<br /><br />";
         }
    
     function Uninstall() 
      {
        #try update scsq_modules table
            $UpdateModules = "
            DELETE FROM scsq_modules where name = 'HelloWorld';";
    
            $result=$this->ssq->query($UpdateModules) or die ("Can`t update module table");
    
            $this->ssq->free_result($result);
    
            echo "Module uninstalled <br /><br />";
    
      }
    
    }   #end of class
    ?>
    

    index.php

    <?php 
    
    include("../../config.php");
    include("module.php");
    
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    
    <!-- The themes file -->
    <link rel="stylesheet" type="text/css" href="../../themes/<?php echo $globaltheme;?>/global.css"/>
    
    </head>
    <body>
    
    <?php
    
    $start=microtime(true);
    
    if(isset($_GET['srv']))
      $srv=$_GET['srv'];
    else
      $srv=0;
    
    $addr=$address[$srv];
    $usr=$user[$srv];
    $psw=$pass[$srv];
    $dbase=$db[$srv];
    $dbtype=$srvdbtype[$srv];
    
    $variableSet = array();
    $variableSet['addr']=$addr;
    $variableSet['usr']=$usr;
    $variableSet['psw']=$psw;
    $variableSet['dbase']=$dbase;
    $variableSet['dbtype']=$dbtype;
    
    $variableSet['language']=$language;
    
    #include database drivers
    if($dbtype==0)
    include("../../lib/dbDriver/mysqlmodule.php");
    
    if($dbtype==1)
    include("../../lib/dbDriver/pgmodule.php");
    
    $module = new HelloWorld($variableSet);
    
    echo "<h2>Модуль HelloWorld</h2><br />";
    
    echo "<br><p>On this page you can see the functionality of the module that does nothing.</p>";
    
    $end=microtime(true);
    
    $runtime=$end - $start;
    
    #the necessary code to move from the module page to the report page.
    $newdate=strtotime(date("d-m-Y"))-86400;
    $newdate=date("d-m-Y",$newdate);
    
    ?>
    <form name=fastdateswitch_form>
        <input type="hidden" name=date_field_hidden value="<?php echo $newdate; ?>">
        <input type="hidden" name=dom_field_hidden value="<?php echo 'day'; ?>">
        <input type="hidden" name=group_field_hidden value=0>
        <input type="hidden" name=groupname_field_hidden value=0>
        <input type="hidden" name=typeid_field_hidden value=0>
        </form>
    </body>
    </html>
    

    After creating these two files, your first module for Screen Squid is ready. You can begin to supplement them with the functionality you need.

    Multilanguage support

    In the index.php file, the main configuration file config.php is connected, where there is a parameter $ language. You can use it to implement multilingual support in your module. Create the langs directory in the directory with the module and put the array of $ _lang variables there. An example of a file is the main language files, which are located in the screensquid / lang directory. Once you have created these files, include them through the include directive. It makes sense to give language files the semantic coloring of the form - ru - Russian, en - English and so on.

    Ideas, bugs, questions?

    Feel free to contact us http://t.me/screensquid