Posts: 78
Threads: 17
Joined: Aug 2014
Reputation:
2
Sex: Undisclosed
Thanks: 15
Given 7 thank(s) in 6 post(s)
Creating a module
04-05-2015, 02:12 PM
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,
Posts: 57
Threads: 3
Joined: Oct 2014
Reputation:
5
Sex: Male
Thanks: 6
Given 24 thank(s) in 15 post(s)
RE: Creating a module
04-05-2015, 08:11 PM
You get any errors droped to logs? Maybe add some debuging echos and chceck where your script stop working.
Posts: 78
Threads: 17
Joined: Aug 2014
Reputation:
2
Sex: Undisclosed
Thanks: 15
Given 7 thank(s) in 6 post(s)
RE: Creating a module
04-05-2015, 10:59 PM
(This post was last modified: 04-05-2015, 11:00 PM by rafaht.)
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,
Posts: 57
Threads: 3
Joined: Oct 2014
Reputation:
5
Sex: Male
Thanks: 6
Given 24 thank(s) in 15 post(s)
RE: Creating a module
04-06-2015, 01:52 AM
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).
Posts: 3 ,662
Threads: 241
Joined: May 2014
Reputation:
85
Sex: Male
Thanks: 408
Given 599 thank(s) in 464 post(s)
RE: Creating a module
04-06-2015, 02:30 AM
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
Posts: 3 ,662
Threads: 241
Joined: May 2014
Reputation:
85
Sex: Male
Thanks: 408
Given 599 thank(s) in 464 post(s)
RE: Creating a module
04-06-2015, 03:00 AM
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
Posts: 78
Threads: 17
Joined: Aug 2014
Reputation:
2
Sex: Undisclosed
Thanks: 15
Given 7 thank(s) in 6 post(s)
RE: Creating a module
04-06-2015, 06:42 AM
(This post was last modified: 04-06-2015, 06:42 AM by rafaht.)
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,
Posts: 3 ,662
Threads: 241
Joined: May 2014
Reputation:
85
Sex: Male
Thanks: 408
Given 599 thank(s) in 464 post(s)
RE: Creating a module
04-06-2015, 12:34 PM
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
-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
|