/* Enjoy!!! Dino Ciuffetti - dam2k@users.sourceforge.net
*
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program (COPYING); if not, go to http://www.fsf.org/ or write
* to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA.
*
*/
/* PUBLISH CLASS */
/**
* Everything about dynamic sections, publishing, dynamic form modules, and the like.
* Class instance: $cms->publish
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
class cmsdam_publish
{
/**
* You should not use this variable from your section.
*/
var $conf;
var $logs;
var $debug;
var $users;
var $groups;
var $sections;
var $dbms;
/**
* This is the class constructor. Here are automatically setted things.
* @return null
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function cmsdam_publish () {
return true;
}
/**
* Now, stop to joke! ;-) Things are getting hot!! Here we can use this method to get one form module (input, textarea, ecc...)
* For example, we can use it to build administration forms for dynamic sections. Cool! Form objects are stored on database.
*
* @return bool false on errors
* @param str module_name The name of the module you want to get
* @param str keyname Generally is the name of the object (input name="")
* @param str parameters Parameters or attributes of the form module
* @param str keyvalue Generally is the value of the form attribute (input value="")
* @param array arraykeyname Array of names of the form objects
* @param array arraykeyvalue Array of values of the form objects
* @param array arrayparameters Array of parameters of the form objects
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function get_form_module($module_name, $keyname, $parameters="", $keyvalue="", $arraykeyname="", $arraykeyvalue="", $arrayparameters="", $image="") {
// Get a form module (input, textarea, select, user defined, ...)
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
// Get module_type from the list of form modules
$query = "SELECT module_type from " . $this->dbms->DB_tbl_prefix . "publish_frm_modules where module_name = \"$module_name\"";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "get_form_module: DB error");
$this->logs->log_note(5, "get_form_module: DB error");
return false;
}
if ($this->dbms->dbnum_rows() == 0) { // No records found
$this->debug->debug_write(6, "get_form_module: no module_name named $module_name");
$this->logs->log_note(6, "get_form_module: no module_name named $module_name");
return false;
}
$data = $this->dbms->dbfetch_row();
$type = $data[0];
// Get module_type from the list of form array modules
$query = "SELECT module_type from " . $this->dbms->DB_tbl_prefix . "publish_frm_module_types_arr where module_type = $type";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "get_form_module: DB error");
$this->logs->log_note(5, "get_form_module: DB error");
return false;
}
if ($this->dbms->dbnum_rows() == 0) { // No records found
// THIS IS A SIMPLE KEY/VALUE OBECT
$this->debug->debug_write(7, "get_form_module: This is a simple object");
$this->logs->log_note(7, "get_form_module: This is a simple object");
// Get module details from DB
$query = "select keyname, module_value from " . $this->dbms->DB_tbl_prefix . "publish_frm_module_types where module_type = $type";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "get_form_module: DB error");
$this->logs->log_note(5, "get_form_module: DB error");
return false;
}
if ($this->dbms->dbnum_rows() == 0) { // No records found
$this->debug->debug_write(7, "get_form_module: module_name $module_name, type $type has no data associated");
$this->logs->log_note(7, "get_form_module: module_name $module_name, type $type has no data associated");
return false;
}
$data = $this->dbms->dbfetch_row();
// NAME and VALUE
$name = $data[0];
$value = $data[1];
// create the form module string, subsitute lables on DB with values picked as function parameters
$name = ereg_replace("%s", $keyname, $name);
$value = ereg_replace("%s", $name, $value);
$value = ereg_replace("%P", $parameters, $value);
$value = ereg_replace("%t", $keyvalue, $value);
$value = ereg_replace("%i", $image, $value);
//echo "DEBUG: name: $name, value: $value";
echo $value;
return true;
} else {
$this->debug->debug_write(7, "get_form_module: This is an array of objects");
$this->logs->log_note(7, "get_form_module: This is an array of objects");
// THIS IS AN ARRAY OF OBJECTS
// Get module details from DB
$query = "select keyname, module_value from " . $this->dbms->DB_tbl_prefix . "publish_frm_module_types where module_type = $type";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "get_form_module: DB error");
$this->logs->log_note(5, "get_form_module: DB error");
return false;
}
if ($this->dbms->dbnum_rows() == 0) { // No records found
$this->debug->debug_write(7, "get_form_module: module_name $module_name, type $type has no data associated");
$this->logs->log_note(7, "get_form_module: module_name $module_name, type $type has no data associated");
return false;
}
$data = $this->dbms->dbfetch_row();
// NAME and VALUE
$name = $data[0];
$value = $data[1];
$name = ereg_replace("%s", $keyname, $name);
$value = ereg_replace("%s", $name, $value);
$value = ereg_replace("%P", $parameters, $value);
$query = "select array_keyname, array_value from " . $this->dbms->DB_tbl_prefix . "publish_frm_module_types_arr where module_type = $type order by array_keyid";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "get_form_module: DB error");
$this->logs->log_note(5, "get_form_module: DB error");
return false;
}
$nrows = $this->dbms->dbnum_rows();
for ($rows = 0; $rows < $nrows; $rows++) { // Getting data from the database
$data = $this->dbms->dbfetch_row();
// Building the array
for ($element = 0; $element < count($arraykeyname); $element++) {
$arrayname[$rows][$element] = $data[0];
$arrayvalue[$rows][$element] = $data[1];
$arrayname[$rows][$element] = ereg_replace("%s", $arraykeyname[$element], $arrayname[$rows][$element]);
$arrayvalue[$rows][$element] = ereg_replace("%s", $arrayname[$rows][$element], $arrayvalue[$rows][$element]);
$arrayvalue[$rows][$element] = ereg_replace("%P", $arrayparameters[$element], $arrayvalue[$rows][$element]);
$arrayvalue[$rows][$element] = ereg_replace("%t", $arraykeyvalue[$element], $arrayvalue[$rows][$element]);
}
}
$tempstr = "";
for ($rows = 0; $rows < $nrows; $rows++) {
for ($element = 0; $element < count($arraykeyname); $element++) {
$tempstr .= $arrayvalue[$rows][$element];
}
}
// Print array data
$value = ereg_replace("%A", $tempstr, $value);
echo $value;
}
}
/**
* List form modules. Return an array with all form module's names
*
* @return array Array of names, false on errors
* @param str module_name Search for modules with name like this
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function list_form_modules($module_name="") {
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
// Get module_name from the list of form modules
$query = "SELECT module_name from " . $this->dbms->DB_tbl_prefix . "publish_frm_modules where module_name like \"%$module_name%\" order by module_name";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "list_form_modules: DB error");
$this->logs->log_note(5, "list_form_modules: DB error");
return false;
}
$nrows = $this->dbms->dbnum_rows();
for ($rows = 0; $rows < $nrows; $rows++) { // Getting data from the database
$data = $this->dbms->dbfetch_row();
$arrdata[] = $data[0];
// Building the array
}
return $arrdata;
}
/**
* Return form module type attribute for the given module name. If type is 1 then the module is single, 2 for array of objects.
*
* @return int Module type attribute: 1 for single objects, 2 for array of objects
* @param str module_name Name of the module to get the type attribute
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function get_module_type ($module_name) {
if ($module_name == "") {
$this->debug->debug_write(7, "get_module_attribute: module_name not passed as expected");
$this->logs->log_note(7, "get_module_attribute: module_name not passed as expected");
return false;
}
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
// Get module_type from the list of form modules
$query = "SELECT module_type from " . $this->dbms->DB_tbl_prefix . "publish_frm_modules where module_name = \"$module_name\"";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "get_module_type: DB error");
$this->logs->log_note(5, "get_module_type: DB error");
return false;
}
if ($this->dbms->dbnum_rows() == 0) { // No records found
$this->debug->debug_write(6, "get_module_type: no module_name named $module_name");
$this->logs->log_note(6, "get_module_type: no module_name named $module_name");
return false;
}
$data = $this->dbms->dbfetch_row();
$type = $data[0];
// Get module_type from the list of form array modules
$query = "SELECT module_type from " . $this->dbms->DB_tbl_prefix . "publish_frm_module_types_arr where module_type = $type";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "get_module_type: DB error");
$this->logs->log_note(5, "get_module_type: DB error");
return false;
}
if ($this->dbms->dbnum_rows() == 0) { // No records found
// THIS IS A SIMPLE KEY/VALUE OBECT
$this->debug->debug_write(7, "get_module_type: This is a simple object");
$this->logs->log_note(7, "get_module_type: This is a simple object");
return 1;
} else {
// THIS IS AN ARRAY OF OBJECTS
$this->debug->debug_write(7, "get_module_type: This is an array of objects");
$this->logs->log_note(7, "get_module_type: This is an array of objects");
return 2;
}
}
/**
* Get form module keyname
*
* @return str KeyName module
* @param str module_name The module's name
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function get_module_keyname($module_name) {
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
// Get module_name from the list of form modules
$query = "SELECT types.keyname from " . $this->dbms->DB_tbl_prefix . "publish_frm_module_types as types, " . $this->dbms->DB_tbl_prefix . "publish_frm_modules as mods where mods.module_type = types.module_type and mods.module_name = \"$module_name\"";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "list_form_modules: DB error");
$this->logs->log_note(5, "list_form_modules: DB error");
return false;
}
$nrows = $this->dbms->dbnum_rows();
for ($rows = 0; $rows < $nrows; $rows++) { // Getting data from the database
$data = $this->dbms->dbfetch_row();
$arrdata[] = $data[0];
// Building the array
}
return $arrdata[0];
}
/**
* Get form module keyvalue
*
* @return str KeyValue module
* @param str module_name The module's name
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function get_module_keyvalue($module_name) {
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
// Get module_name from the list of form modules
$query = "SELECT types.module_value from " . $this->dbms->DB_tbl_prefix . "publish_frm_module_types as types, " . $this->dbms->DB_tbl_prefix . "publish_frm_modules as mods where mods.module_type = types.module_type and mods.module_name = \"$module_name\"";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "list_form_modules: DB error");
$this->logs->log_note(5, "list_form_modules: DB error");
return false;
}
$nrows = $this->dbms->dbnum_rows();
for ($rows = 0; $rows < $nrows; $rows++) { // Getting data from the database
$data = $this->dbms->dbfetch_row();
$arrdata[] = $data[0];
// Building the array
}
return $arrdata[0];
}
/**
* Check if this module is given by default on cmsdAm or if it is a user one
*
* @return int If returncode is == 1 then this module is given with cmsdam.
* @param str module_name The module's name
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function get_module_locked($module_name) {
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
// Get module_name from the list of form modules
$query = "SELECT default_module from " . $this->dbms->DB_tbl_prefix . "publish_frm_modules where module_name = \"$module_name\"";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(5, "list_form_modules: DB error");
$this->logs->log_note(5, "list_form_modules: DB error");
return false;
}
$nrows = $this->dbms->dbnum_rows();
for ($rows = 0; $rows < $nrows; $rows++) { // Getting data from the database
$data = $this->dbms->dbfetch_row();
$arrdata[] = $data[0];
// Building the array
}
return $arrdata[0];
}
}
?>