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
#1
Creating a module
Hey guys!
I'm trying to create a module, but some piece of code doesn't working and I don't know why, because doesn't have error.

See:
module.zpm
Code:
        <h3><: Alerts list :></h3>

        <% if AlertsList %>
            <table class="table table-striped">
                <tr>
                  <th><: ID :></th>               
                  <th><: Title  :></th>
                  <th><: Message :></th>                   
                </tr>
                <% loop AlertsList %>
                <tr>
                    <td><~ alert_id ~></td>
                    <td><~ alert_title ~></td>
                    <td><~ alert_message ~></td>                     
                </tr>
                <% endloop %>
            </table>
            <@ CSFR_Tag @>
        <% else %>
        <p><: There are currently no alerts to display! :></p>
        <% endif %>
I tried replace <~ and ~> for <& and &>, but doesn't worked too.

The module displays until this piece: <h3><: Alerts list :></h3>.

The controller.ext.php corresponding code:

Code:
    /*

     * 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();
    }

The database exists, the table and column names is correct. I verified.

Any ideas? :/
Thanks,
Reply
Thanks given by:
#2
RE: Creating a module
You get any errors droped to logs? Maybe add some debuging echos and chceck where your script stop working.
Reply
Thanks given by:
#3
RE: Creating a module
Castey,
I don't know where are the error logs for the Sentora panel.
I tried see the logs for /var/sentora/logs/sentora.log and /var/sentora/logs/sentora-error.log, but haven't anything about this code.
I tried see /var/log/apache2/error.log too, but haven't anything.
I'm using tail -f PATH and run the page of module at panel to see the errors.

And this guide: http://docs.sentora.org/public/files/Mod..._guide.pdf says to use &debug=true at url. I tried this too, but doesn't show any error.

Thanks,
Reply
Thanks given by:
#4
RE: Creating a module
Add Try and Catch to mysql request, and simply echo in several place in your code, to track down errors (find where code stops).
Error logs for sentora panel: /var/sentora/logs/sentora-error.log
Maybe you could use zlo (zpanel logging object).
Reply
Thanks given by:
#5
RE: Creating a module
1- you do not need the <@ CSFR_Tag @> as that is used for forms (Add before the closing </form> element)
2- <~ ~> should be <& &>

Looking at the code a bit closer, will reply again.
-TGates - Project Council

SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE

Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
Reply
Thanks given by:
#6
RE: Creating a module
I'd need to see the full code to check it out. I have an idea, but not 100% sure it will work.
-TGates - Project Council

SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE

Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
Reply
Thanks given by:
#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:
#8
RE: Creating a module
ZIP the entire module folder and PM a link for me to download it. I need to install it so i can test and see what is or is not happening Wink
-TGates - Project Council

SEARCH the Forums or read the DOCUMENTATION before posting!
Support Sentora and Donate: HERE

Find my support or modules useful? Donate to TGates HERE
Developers and code testers needed!
Contact TGates for more information
Reply
Thanks given by:


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

Forum Jump:


Users browsing this thread: 1 Guest(s)