This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Creating a module
#7
RE: Creating a module
TGates,

controller.ext.php:
Code:
<?php
/*
*
* Alerts module for Sentora 1.0.0
* Version : 1
* Author :  Rafael (rafaht @ Sentora Forums)
* Email : rafael@rafatresbach.com
*/

class module_controller {

    static $done;
    static $error;
    static $emptytitle;
    static $emptymessage;
    static $ok;

   /* Load CSS and JS files */
    static function getInit() {
        global $controller;
        $line = '<link rel="stylesheet" type="text/css" href="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/alert.css">';
        $line .= '<script type="text/javascript" src="modules/' . $controller->GetControllerRequest('URL', 'module') . '/assets/alert.js"></script>';
        return $line;
    }

    /*
     * The 'worker' methods.
     */
    static function ListAlerts() {
        global $zdbh;
        $sql = "SELECT * FROM sentora_alerts";
        $numrows = $zdbh->prepare($sql);
        $numrows->execute();
        if ($numrows->fetchColumn() <> 0) {
            $sql = $zdbh->prepare($sql);
            $res = array();
            $sql->execute();
            while ($rowalerts = $sql->fetch()) {
        array_push($res, array('alert_id' => $rowalerts['alert_id'], 'alert_title' => runtime_xss::xssClean($rowalerts['alert_title']), 'alert_message' =>runtime_xss::xssClean($rowalerts['alert_message'])));
            }
            return $res;
        } else {
            return false;
        }
    }

    /*
     * End 'worker' methods.
     */

    static function getAlertsList() {
        global $zdbh;
        return self::ListAlerts();
    }

    static function CheckAlertsForErrors($title, $message) {
        global $zdbh;
        
        if (strlen(trim($title)) < 3) {
            self::$emptytitle = true;
            return false;
        }

        if (strlen(trim($message)) < 25) {
            self::$emptymessage = true;
            return false;
        }

        return true;
    }

    static function getCSFR_Tag() {
        return runtime_csfr::Token();
    }

    static function getModuleName() {
        $module_name = ui_module::GetModuleName();
        return $module_name;

    }

    static function getModuleIcon() {
        global $controller;
        $module_icon = "/modules/" . $controller->GetControllerRequest('URL', 'module') . "/assets/icon.png";
        return $module_icon;
    }


    static function getModuleDesc() {
        $message = ui_language::translate(ui_module::GetModuleDescription());
        return $message;
    }


   static function getAlertTitle(){
       global $controller;
       if ($controller->GetControllerRequest('FORM', 'alert_title') && (fs_director::CheckForEmptyValue(self::$done))){
            return $controller->GetControllerRequest('FORM', 'alert_title');
       } else {
            return "";
       }
   }

   static function getAlertMessage(){
       global $controller;
       if ($controller->GetControllerRequest('FORM', 'alert_message') && (fs_director::CheckForEmptyValue(self::$done))){
            return $controller->GetControllerRequest('FORM', 'alert_message');
       } else {
            return "";
       }
   }


   static function doAddAlert(){
       global $controller;
        
       runtime_csfr::Protect();
       $currentuser = ctrl_users::GetUserDetail();
       $formvars = $controller->GetAllControllerRequests('FORM');
                
       if (self::ExecuteAlerts($formvars)){
           self::$ok = true;
           return true;            
       } else {
           return false;
       }
       return;        
   }

    static function ExecuteAlerts($data) {
        global $zdbh;
        $retval = false;
        
    if (!fs_director::CheckForEmptyValue(self::CheckAlertsForErrors($data['alert_title'], $data['alert_message']))){
        
           $currentuser = ctrl_users::GetUserDetail();
           $sql = $zdbh->prepare("INSERT INTO sentora_alerts (alert_title, alert_message, alert_date) VALUES (:title,:message,:date)");
           $sql->bindParam(':title', $data['alert_title']);
           $sql->bindParam(':message', $data['alert_message']);
           $datetime = date("Y-m-d H:i");
           $sql->bindParam(':date', $datetime);
           $sql->execute();

          
                   self::$done = true;
          
            $retval = true;
    }
        

        return $retval;
    }


    static function getResult() {
        if (!fs_director::CheckForEmptyValue(self::$emptytitle)) {
            return ui_sysmessage::shout(ui_language::translate("Please enter a valid alert title and try again."), "zannounceerror");
        }
        if (!fs_director::CheckForEmptyValue(self::$emptymessage)) {
            return ui_sysmessage::shout(ui_language::translate("Alert message must be characters greater than 25."), "zannounceerror");
        }


        if (!fs_director::CheckForEmptyValue(self::$ok)) {
            return ui_sysmessage::shout(ui_language::translate("Alert added successfully."), "zannounceok");
        }

        if (!fs_director::CheckForEmptyValue(self::$error)) {
            return ui_sysmessage::shout(ui_language::translate("An error has occurred while executing your request, please check your input and try again."), "zannounceerror");
        }
        return;
    }

    /*
     * Webinterface sudo methods.
     */

}

?>

module.zpm:
Code:
<@ Init @>
<div class="zmodule_content panel" id="zmodule_header_<@ ModuleName @>">
    <div class="panel-heading">
        <img src="<@ ModuleIcon @>" width="35" height="35" border="0" alt="<@ ModuleName @>">

        <div class="zmodule_title">
            <@ ModuleName @>
        </div>

        <div class="zmodule_desc" id="zmodule_desc_<@ ModuleName @>"><@ ModuleDesc @></div>

    </div>

    <div class="zgrid_wrapper">
      
        <h3><: Alerts list :></h3>


    <br><br>
        <h3><: Add new alert :></h3>
        <@ Result @>
        <div id="alerts_msg" class="alert alert-danger" style="display: none;"></div>
        <form action="./?module=alerts&action=AddAlert" method="post" id="frm_alerts">
           <table class="table table-stripped">
              <tr>
                <th nowrap="nowrap"><: Title :>:</th>
                <td><input name="alert_title" type="text" id="alert_title" size="30" value="<@ AlertTitle @>" /></td>                
              </tr>
              <tr>
                <th nowrap="nowrap"><: Alert Message :>:</th>
                <td>
                   <textarea name="alert_message" id="alert_message" rows="3" cols="80" class="ckeditor" /><@ AlertMessage @></textarea>
                </td>
              </tr>
              <tr>
                   <th></th>
                   <td>
                    <button class="btn btn-primary" type="button" name="AddAlert" value="1" id="btn_addalert">Add alert</button>
                    </td>
                 </tr>
               </table>
           <@ CSFR_Tag @>
        </form>
    
    </div>
    
</div>
<script>
    var form_msgs = [];
    form_msgs['empty_alert_title'] = "<: Alert title cannot be less than 3 characters :>!";
    form_msgs['empty_alert_message'] = "<: Alert message cannot be less than 25 characters :>!";
</script>

This module is at initial development and piece of code isn't added... I'm trying to do work the basics do add the complex of this.
Thanks,
Reply
Thanks given by:


Messages In This Thread
Creating a module - by rafaht - 04-05-2015, 02:12 PM
RE: Creating a module - by Castey - 04-05-2015, 08:11 PM
RE: Creating a module - by rafaht - 04-05-2015, 10:59 PM
RE: Creating a module - by Castey - 04-06-2015, 01:52 AM
RE: Creating a module - by TGates - 04-06-2015, 02:30 AM
RE: Creating a module - by TGates - 04-06-2015, 03:00 AM
RE: Creating a module - by rafaht - 04-06-2015, 06:42 AM
RE: Creating a module - by TGates - 04-06-2015, 12:34 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Happy Holidays! New theme and module available :) TGates 2 7 ,833 12-25-2017, 09:52 PM
Last Post: dimnas

Forum Jump:


Users browsing this thread: 1 Guest(s)