/* 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.
*
*/
/* SECTIONS */
/**
* This is the most important class of cmsdAm. Here are defined methods you can use to handle PHP/HTML
* pieces of code (templates) mapped into section names. Each section can be included from another
* section (for example from template index.php, the first section). Remember that sections can be
* mapped to cmsdAm users and/or groups to grant or deny web users from directly viewing the
* requested section.
* Class instance: $cms->sections
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
class cmsdam_sections
{
/**
* You should not use this variable from your section.
* Configuration class instance.
*/
var $conf;
/**
* You should not use this variable from your section.
* i18n class instance.
*/
var $i18n;
/**
* You should not use this variable from your section.
* Memcache class instance.
*/
var $memcache;
/**
* You should not use this variable from your section.
* HTTP class instance.
*/
var $http;
/**
* You should not use this variable from your section.
* DBMS class instance.
*/
var $dbms;
/**
* You should not use this variable from your section.
* Users class instance.
*/
var $users;
/**
* You should not use this variable from your section.
* Groups class instance.
*/
var $groups;
/**
* This is the name of the section from where you get this variable.
* It is automagically setted by cmsdAm. If you want to get the name of the included section
* where you are, use this variable.
* @type str
*/
var $section_included;
/**
* You should not use this variable from your section.
* General class instance.
*/
var $general;
/**
* You can set this variable to 1 if you want to force cmsdAm NOT to cache this section.
* The value [0 or 1] is taken from the external variable n_c
* @type int
*/
var $section_cached;
/**
* This is the name of the requested section.
* You can change its value from template/index.php (for example).
* It is automagically setted by cmsdAm. If you want to change the requested section
* at runtime from one of your sections, remember to call sections->cmsdam_sections() without
* parameters after you change this variable.
* @type str
*/
var $section_requested;
/**
* This is the level of subsections (if any) of the requested section.
* @type int
*/
var $n_subsections;
/**
* This is the number of defined sections.
* @type int
*/
var $n_sections;
/**
* This array contains the splitted path for the requested (sub)section.
* 0:s1,1:s1/s2,2:s1/s2/s3,ecc...
* @type array
*/
var $subsections;
/**
* This is the short description for the requested section.
* @type str
*/
var $description;
/**
* This is the long description for the requested section.
* @type str
*/
var $longdescription;
/**
* This is the filename for the requested section.
* @type str
*/
var $filename;
/**
* cmsdAm relative path for template files. No leading nor trailing slash.
* @type str
*/
var $templates_relpath;
/**
* cmsdAm relative path for template files for the given language. No leading nor trailing slash.
* @type str
*/
var $templates_lang_relpath;
/**
* Absolute path for this cmsdam installation
*/
var $http_urlpath;
/**
* This is the class constructor. Here are automatically setted things.
* @return null
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function cmsdam_sections () {
$this->n_sections = count($this->conf->Section_arr);
if (is_array($this->conf->Section_arr)) {
$j = array_search($this->section_requested, $this->conf->Section_arr);
} else {
return false;
}
// Now $j is the section identifier
$_language = $this->i18n->cmsdam_get_preferred_lang();
$this->conf->Shortdescription_arr_def = $this->conf->Shortdescription_arr;
//print_r($this->conf->Section_langs_arr); $a as $k => $v
$seclang = array();
foreach ($this->conf->Section_langs_arr as $k => $v) {
foreach ($v as $kk => $vv) {
if (array_search($vv, $seclang) === false) {
// A new language was found
$seclang[] = $vv;
$this->logs->log_note(9, "UNUSEFUL NOTE: found a new language: $vv");
}
}
}
$this->conf->lang_list = $seclang;
if (@array_search ($_language, $this->conf->lang_list) === false) {
// Search if there are sections written in a language that the cmsdam_lang can speak.
// Here it seems that there are no sections with a language like cmsdam_lang.
// Trying to search the browser user agent list of favourite languages for a language
// that match the list
foreach ($this->http->browser_languages() as $k => $v) {
if (array_search($v, $this->conf->lang_list)) {
// It seems that there is at least one section language that match the browser user agent lang list
// SET IT UP!!
$this->logs->log_note(5, "NOTE: there are no sections that match the language $_language. Switching to lang $v");
$this->i18n->cmsdam_set_preferred_lang($v);
$this->templates_lang_relpath = "template/lang/$v";
$_language = $v;
break;
}
}
} /* else {
$this->i18n->cmsdam_set_preferred_lang("def");
$cms->templates_lang_relpath = "template/lang/def";
} */
if (@array_key_exists ($_language, $this->conf->Shortdescription_arr)) {
$this->conf->Shortdescription_arr = $this->conf->Shortdescription_arr[$_language];
} else {
$this->conf->Shortdescription_arr = $this->conf->Shortdescription_arr["def"];
}
$this->conf->Longdescription_arr_def = $this->conf->Longdescription_arr;
if (@array_key_exists ($_language, $this->conf->Longdescription_arr)) {
$this->conf->Longdescription_arr = $this->conf->Longdescription_arr[$_language];
} else {
$this->conf->Longdescription_arr = $this->conf->Longdescription_arr["def"];
}
$this->conf->Section_file_arr_def = $this->conf->Section_file_arr;
if (@array_key_exists ($_language, $this->conf->Section_file_arr)) {
$this->conf->Section_file_arr = $this->conf->Section_file_arr[$_language];
} else { // This only affect requests with ANY template defined for the language requested!!!
$this->conf->Section_file_arr = $this->conf->Section_file_arr["def"];
}
if ($j > 0) {
$this->subsections = @explode("/", $this->section_requested);
$this->n_subsections = @count($this->subsections) - 1;
//echo "DEBUG: $_language";
// This is the section selected by the user and the user is able to view it
$this->description = $this->conf->Shortdescription_arr[$j];
$this->longdescription = $this->conf->Longdescription_arr[$j];
$this->filename = $this->conf->Section_file_arr[$j];
} else {
// The user selected the root or an invalid section
//$this->section_requested = $this->conf->Section_arr[0];
$this->filename = $this->conf->Section_file_arr[0];
$this->subsections = @explode("/", $this->conf->Section_arr[0]);
$this->n_subsections = @count($this->subsections) - 1;
}
}
/**
* Private function. Don't use it.
* @return str
* @author dAm2K (Dino Ciuffetti) <dam2000@gmail.com>
*/
function _private_getsmartlink ($section, $http_params) {
if ($this->general->smartlink == true) {
$html_text = $this->http_urlpath . "index.php/uri/section-" . $section;
if ($http_params != "") {
$html_text .= "?$http_params";
}
}
return $html_text;
}
/**
* This method returns the navigation bar HTML string for the requested section. This is not
* a scalable way to do things, for example because you can not modify html output, but sometime
* it can be very useful. You can use the method section_navigator_arr if you want a more scalable
* way of making navigation bar for requested section.
* @return str The navigation bar HTML string for the requested section
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_navigator () { // This method returns the navigation bar string. Not so scalable,
// but sometimes it can be useful!
$cmsdam_http_cache = 1;
$separation_char = ">";
if ($this->n_subsections > 0) { // This is a subsection
$nbar = $this->section_nslink(0, "", $cmsdam_http_cache) . " $separation_char ";
for ($i = 1; $i <= $this->n_subsections; $i++)
{
// Scan all the subsections to create the navigation bar
for ($j = 0; $j < $this->n_sections; $j++)
{
if ($i == 1) { // This is the first entry, the section name is not composed
if ($this->conf->Section_arr[$j] == $this->subsections[$i-1]) {
// We have found the ID of this section, is $j!
$partsect = $this->subsections[$i-1];
break;
}
} else { // This is not the first entry, the section name is composed
$partsect = "";
for ($z = 1; $z <= $i; $z++)
{
if ($z == $i) { // This is the last
$partsect .= $this->subsections[$z-1];
} else { // This is not the last
$partsect .= $this->subsections[$z-1] . "/";
}
}
if ($this->conf->Section_arr[$j] == $partsect) {
// We have found the ID of this section, is $j!
break;
}
}
}
$nbar .= $this->section_slink($partsect, "", $cmsdam_http_cache) . " $separation_char ";
if ($i == $this->n_subsections) { // This is the last subsection
$nbar .= $this->description;
}
}
} else { // This is not a subsection, it's a section
$nbar = $this->section_nslink(0, "", $cmsdam_http_cache) . " $separation_char " . $this->description;
$key = array_search($this->section_requested, $this->conf->Section_arr);
if ($key == 0) { // This is the Home Page!
$nbar = $this->section_nslink(0, "", $cmsdam_http_cache);
}
}
return $nbar;
}
/**
* This is the scalable way to create the section navigation bar.
* This method returns an array with the splitted path for the given section.
* Useful to make the navigation bar.
* @return array The navigation bar array
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_navigator_arr () { // This method returns the navigation bar array. More scalable :-)
if ($this->n_subsections > 0) { // This is a subsection
$nbar_counter = 0;
$nbar_arr[$nbar_counter] = $this->conf->Section_arr[0];
$nbar_counter++;
for ($i = 1; $i <= $this->n_subsections; $i++)
{
// Scan all the subsections to create the navigation bar
for ($j = 0; $j < $this->n_sections; $j++)
{
if ($i == 1) { // This is the first entry, the section name is not composed
if ($this->conf->Section_arr[$j] == $this->subsections[$i-1]) {
// We have found the ID of this section, is $j!
$partsect = $this->subsections[$i-1];
break;
}
} else { // This is not the first entry, the section name is composed
$partsect = "";
for ($z = 1; $z <= $i; $z++)
{
if ($z == $i) { // This is the last
$partsect .= $this->subsections[$z-1];
} else { // This is not the last
$partsect .= $this->subsections[$z-1] . "/";
}
}
if ($this->conf->Section_arr[$j] == $partsect) {
// We have found the ID of this section, is $j!
break;
}
}
}
$nbar_arr[$nbar_counter] = $partsect;
$nbar_counter++;
if ($i == $this->n_subsections) { // This is the last subsection
$nbar_arr[$nbar_counter] = $this->section_requested;
$nbar_counter++;
}
}
} else { // This is not a subsection, it's a section
$nbar_counter = 0;
$nbar_arr[$nbar_counter] = $this->conf->Section_arr[0];
$nbar_counter++;
$nbar_arr[$nbar_counter] = $this->section_requested;
$key = array_search($this->section_requested, $this->conf->Section_arr);
if ($key == 0) { // This is the Home Page!
$nbar_arr[0] = $this->conf->Section_arr[0];
unset ($nbar_arr[$nbar_counter]);
}
}
return $nbar_arr;
}
/**
* Return a sorted array with all the section names like a directory tree.
* You can use it for example to create a section graphic representation tree.
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
* @return array Sorted array with all section names.
*/
function section_sorted_tree() {
$_sect_arr = $this->conf->Section_arr;
sort($_sect_arr);
return $_sect_arr;
}
/**
* Return the tree level for the given (sub)section.
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
* @param str cmsdam_section The section name
* @return int cmsdam section level
*/
function section_treelevel($cmsdam_section) {
if (array_search($cmsdam_section, $this->conf->Section_arr) === false) {
// Section not valid
return false;
}
$_treelevel = explode("/", $cmsdam_section);
$_treelevel = count($_treelevel);
return $_treelevel;
}
/**
* Include a section into the page.
* This is the most important method of this class, useful to include other sections into the
* requested one. WARNING: You must use this method!! Don't try to use the "include" PHP directive
* to include sections, you have to do most checks and setting variables!!
* @param str cmsdam_section The section name you want to include into the requested one
* @param null param Not used at this time
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
* @return bool True on success, False on errors
*/
function section_include($cmsdam_section, $param = null) { // Include a section into the page.
// We set PHP error reporting like user want by configuration file
error_reporting($this->conf->ERROR_reporting_sections);
// Define custom global templates variables, costants and functions
include ("etc/add_template_variables.php");
// Warning!! These variables are visible to the templates!!
Global $cms; // This global keyword is mandatory to auto prepare cms class instance to included sections
$_language = $this->i18n->cmsdam_get_preferred_lang();
if ($this->section_isvalid($cmsdam_section)) {
if ($this->conf->PHPWarn_on_sectioninclude == "YES") {
$cms->logs->log_note(6, "NOTE: Including section: \"" . $cmsdam_section . "\", PHPWarn: ON, Lang: $_language");
$cms->debug->debug_write(6, "NOTE: Including section: \"" . $cmsdam_section . "\", PHPWarn: ON, Lang: $_language");
echo "\n";
$_cmsdam_callersection = $this->section_included;
$this->section_included = $cmsdam_section;
include ($this->section_filename($cmsdam_section));
$this->section_included = $_cmsdam_callersection;
echo "\n";
} else {
$cms->logs->log_note(6, "NOTE: Including section: \"" . $cmsdam_section . "\", PHPWarn: OFF, Lang: $_language");
$cms->debug->debug_write(6, "NOTE: Including section: \"" . $cmsdam_section . "\", PHPWarn: OFF, Lang: $_language");
$_cmsdam_callersection = $this->section_included;
$this->section_included = $cmsdam_section;
@include ($this->section_filename($cmsdam_section));
$this->section_included = $_cmsdam_callersection;
}
return true;
} else {
$cms->logs->log_note(6, "NOTE: Including section: \"" . $cmsdam_section . "\", Lang: $_language, but section is not valid");
$cms->debug->debug_write(6, "NOTE: Including section: \"" . $cmsdam_section . "\", Lang: $_language, but section is not valid");
return false;
}
}
/**
* Check if the given section exists and is valid for the logged in user.
* @param str section The section name to check
* @return bool True if the section is valid, False if not
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_isvalid($section) {
$User = $this->users->logged_user;
$flag = 0;
if ($User == "") { // Anonymous user
$User = "anonymous";
}
$count = 0;
if (is_array($this->conf->Section_arr)) {
$i = array_search($section, $this->conf->Section_arr); // Now $i is the section identifier
} else {
return false;
}
if ($i === false) { // The section is not defined
$this->debug->debug_write(7, "section_isvalid: section $section is NOT defined");
$this->logs->log_note(6, "section_isvalid: section $section is NOT defined");
return false;
}
// Users array valid for this section
$users_arr = split (',', $this->conf->Section_users_arr[$i]);
// This array contains all valid groups for the requested section
$users_arr_cnt = count ($users_arr);
$groups_arr = split(',', $this->conf->Section_groups_arr[$i]);
// Fill in the users array for each group user
$_grps_arr_count = count($groups_arr);
for ($cnt = 0; $cnt<$_grps_arr_count; $cnt++) { // for each group...
// Take all the users for that group
$temp = trim($groups_arr[$cnt]);
$usrs = $this->groups->group_users_name($temp);
for ($tmp = 0; $tmpn_sections) { // The section is not defined
$this->debug->debug_write(7, "section_isvalid: section $section is NOT defined");
$this->logs->log_note(5, "section_isvalid: section $section is NOT defined");
return false;
}
if ($this->conf->Section_file_arr[$i] == "") { // No file defined for that section and the language selected
$this->debug->debug_write(7, "section_isvalid: section $section has NOT a template file defined, trying with default lang");
$this->logs->log_note(5, "section_isvalid: section $section has NOT a template file defined, trying with default lang");
$this->conf->Section_file_arr[$i] = $this->conf->Section_file_arr_def["def"][$i];
if ($this->conf->Section_file_arr[$i] == "") { // No file defined for that section
$this->debug->debug_write(7, "section_isvalid: section $section has NOT a template file defined, nor the default one");
$this->logs->log_note(5, "section_isvalid: section $section has NOT a template file defined, not the default one");
return false;
} else {
// Default language found!!
$this->conf->Section_file_arr[$i] = $this->conf->Section_file_arr_def["def"][$i];
$this->conf->Shortdescription_arr[$i] = $this->conf->Shortdescription_arr_def["def"][$i];
$this->conf->Longdescription_arr[$i] = $this->conf->Longdescription_arr_def["def"][$i];
$this->debug->debug_write(7, "section_isvalid: section $section has a default language template");
$this->logs->log_note(5, "section_isvalid: section $section has a default language template");
}
}
if ($flag<=0) { // This section is NOT valid for that user
$this->debug->debug_write(7, "section_isvalid: user not granted for section $section");
$this->logs->log_note(5, "section_isvalid: user not granted for section $section");
return false;
}
$filename = $this->templates_lang_relpath . "/" . $this->conf->Section_file_arr[$i];
if ((!file_exists($filename)) || (!is_file($filename))) {
// Section file does NOT exists
$this->debug->debug_write(7, "section_isvalid: section $section: the template file was NOT found: ".$filename);
$this->logs->log_note(5, "section_isvalid: section $section: the template file was NOT found: ".$filename);
$this->debug->debug_write(7, "section_isvalid: trying the default template language");
$this->logs->log_note(5, "section_isvalid: trying the default template language");
//$filename = $this->templates_relpath . "/" . $this->conf->Section_file_arr[$i];
$filename = $this->templates_relpath . "/" . $this->conf->Section_file_arr_def["def"][$i];
if ((!file_exists($filename)) || (!is_file($filename))) {
// Section file does NOT exists
$this->debug->debug_write(7, "section_isvalid: section $section: the default template file was NOT found: ".$filename);
$this->logs->log_note(5, "section_isvalid: section $section: the default template file was NOT found: ".$filename);
return false;
}
// Using the default section instead
$this->conf->Section_file_arr[$i] = $this->conf->Section_file_arr_def["def"][$i];
$this->conf->Shortdescription_arr[$i] = $this->conf->Shortdescription_arr_def["def"][$i];
$this->conf->Longdescription_arr[$i] = $this->conf->Longdescription_arr_def["def"][$i];
}
$this->debug->debug_write(8, "section_isvalid: section=$section - the file was found: ".$filename);
$this->logs->log_note(8, "section_isvalid: section=$section - the file was found: ".$filename);
return true;
}
/**
* Returns a section array with all valid section names for the logged user
* @return array Section array
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_valid_arr() {
// Returns a section array with all valid section names for that user
$User = $this->users->logged_user;
if ($User == "") { // Anonymous user
$User = "anonymous";
}
$count = 0;
for ($i=0; $i<$this->n_sections; $i++) { // Section cycle
unset ($users_arr);
$flag=0;
// Users array valid for this section
$users_arr = split (',', $this->conf->Section_users_arr[$i]);
$users_arr_cnt = count ($users_arr);
$groups_arr = split(',', $this->conf->Section_groups_arr[$i]);
// Fill in the users array for each group user
$_grp_arr_count = count($groups_arr);
for ($cnt = 0; $cnt<$_grp_arr_count; $cnt++) { // for each group...
// Take all the users for that group
$temp = trim($groups_arr[$cnt]);
$usrs = $this->groups->group_users_name($temp);
$_usrs_arr_count = count($usrs);
for ($tmp = 0; $tmp<$_usrs_arr_count;$tmp++) { // users for the group $groups_arr[$cnt]
// Add this user of that group in the users array
$users_arr[$users_arr_cnt] = $usrs[$tmp];
$users_arr_cnt++;
}
}
// Check if the loggedin user is in the list of allowed users for this section
// Case insensitive, trimmed!!
$_usrs_arr_count = count($users_arr);
for ($k=0; $k<$_usrs_arr_count; $k++) {
if ((strtolower(trim($users_arr[$k])) == "*") && ($User != "anonymous")) { // All users are granted!!
$flag++;
break;
}
if (strtolower(trim($users_arr[$k])) == strtolower(trim($User))) { // The user is granted ;-)
$flag++;
break;
}
}
if (($flag>0) && ($this->conf->Section_arr[$i] != "") &&
($this->conf->Section_file_arr[$i] != "") &&
($this->section_isvalid($this->conf->Section_arr[$i]))) {
// This section is valid for that user
$sections_valid[$count] = $this->conf->Section_arr[$i];
$count ++;
}
}
return $sections_valid;
}
/**
* This method create a html link that points to the specified section $section.
* You can use the link text $text if you don't want to use the LongDescription
* defined with the section.
* If $httpcache == 0 or if $httpcache is null the section will be cached.
* @param str section The section you want to link
* @param str linktext The link text if you don't want the LongDescription
* @param int httpcache If httpcache == 1 you want NOT to HTTP cache this section
* @return bool True on success, False on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_link ($section, $linktext = "", $httpcache = 0)
{ /* This method create a html link that points to the specified section $section.
You can use the link text $text if you don't want to use the Longdescription
defined with the section.
If $httpcache == 0 or if $httpcache is null the section will be cached.
*/
$isSection = array_search("$section", $this->conf->Section_arr);
if ((trim ($section) != "") && ($isSection > -1)) { // The section id is valid
if ((!$httpcache) || (strlen($httpcache) == 0) ||
($httpcache == 0))
{ // HTTP cache the section
if ($this->general->smartlink == true) {
echo "_private_getsmartlink($section, "") . "\">";
} else {
echo "";
}
} else { // Don't HTTP cache the section
echo "";
}
if ($linktext != "") { // Use $linktext instead of $Longdescription[$isSection]
echo "$linktext";
} else { // link text don't defined
if ($this->conf->Longdescription_arr[$isSection] != "") { // Use section long description
echo $this->conf->Longdescription_arr[$isSection];
} else { // section long description not defined!
echo "$section";
}
}
echo "";
return true;
} else { // The section id is not valid
return false;
}
}
/**
* This method returns a html link that points to the specified section number.
* You can use the link text $text if you don't want to use the ShortDescription
* defined with the section.
* If $httpcache == 0 or if $httpcache is null the section will be cached.
* @param int sectionid The number of the section you want to link
* @param str linktext The link text if you don't want the LongDescription
* @param int httpcache If httpcache == 1 you want NOT to HTTP cache this section
* @return str The html link string with short description for the section $section
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_nslink ($sectionid, $linktext = "", $httpcache = 0, $http_params = "")
{
// This var will contain the link text to be returned
$html_text = "";
if ((array_key_exists($sectionid, $this->conf->Section_arr)) && ($sectionid >= 0)) { // The section id is valid
if ((!$httpcache) || (strlen($httpcache) == 0) ||
($httpcache == 0))
{ // HTTP cache the section
if ($this->general->smartlink == true) {
$html_text = "_private_getsmartlink($this->conf->Section_arr[$sectionid], "") . "\">";
} else {
$html_text = "conf->Section_arr[$sectionid] . "&$http_params" ."\">";
}
} else { // Don't HTTP cache the section
$html_text = "conf->Section_arr[$sectionid] ."\">";
}
if ($linktext != "") {
$html_text = $html_text . "$linktext";
} else { // link text don't defined
if ($this->conf->Shortdescription_arr[$sectionid] != "") { // Use section short description
$html_text = $html_text . $this->conf->Shortdescription_arr[$sectionid];
} else { // section short description not defined!
$html_text = $html_text . $this->conf->Section_arr[$sectionid];
}
}
$html_text = $html_text . "";
return $html_text;
} else { // The section id is not valid
return "";
}
}
/**
* This method returns a html link that points to the specified section $section.
* You can use the link text $text if you don't want to use the ShortDescription
* defined with the section.
* If $httpcache == 0 or if $httpcache is null the section will be cached.
* @param str section The section you want to link
* @param str linktext The link text if you don't want the LongDescription
* @param int httpcache If httpcache == 1 you want NOT to HTTP cache this section
* @return str The html link string with short description for the section $section
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_slink ($section, $linktext = "", $httpcache = 0, $http_params = "")
{ /* This method return a html link that points to the specified section $section.
You can use the link text $text if you don't want to use the Shortdescription
defined with the section.
If $httpcache == 0 or if $httpcache is null the section will be cached.
*/
// This var will contains the link text to be returned
$html_text = "";
$isSection = array_search($section, $this->conf->Section_arr);
if ((trim ($section) != "") && ($isSection >= 0)) { // The section id is valid
if ((!$httpcache) || (strlen($httpcache) == 0) ||
($httpcache == 0))
{ // HTTP cache the section
if ($this->general->smartlink == true) {
$html_text = "_private_getsmartlink($section, "") . "\">";
} else {
$html_text = "";
}
} else { // Don't HTTP cache the section
$html_text = "";
}
// echo "DEBUG: section_slink: " . $html_text;
if ($linktext != "") { // Use $linktext instead of $Longdescription[$isSection]
$html_text = $html_text . "$linktext";
} else { // link text don't defined
if ($this->conf->Shortdescription_arr[$isSection] != "") { // Use section long description
$html_text = $html_text . $this->conf->Shortdescription_arr[$isSection];
} else { // section short description not defined!
$html_text = $html_text . "$section";
}
}
$html_text = $html_text . "";
return $html_text;
} else { // The section id is not valid
return "";
}
}
/**
* This method returns a html link that points to the specified section $section.
* You can use the link text $text if you don't want to use the LongDescription
* defined with the section.
* If $httpcache == 0 or if $httpcache is null the section will be cached.
* @param str section The section you want to link
* @param str linktext The link text if you don't want the LongDescription
* @param int httpcache If httpcache == 1 you want NOT to HTTP cache this section
* @return str The html link string with long description for the section $section
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_llink ($section, $linktext = "", $httpcache = 0, $http_params = "")
{ /* This method return a html link that points to the specified section $section.
You can use the link text $text if you don't want to use the Longdescription
defined with the section.
If $httpcache == 0 or if $httpcache is null the section will be cached.
*/
// This var will contains the link text to be returned
$html_text = "";
$isSection = array_search("$section", $this->conf->Section_arr);
if ((trim ($section) != "") && ($isSection > -1)) { // The section id is valid
if ((!$httpcache) || (strlen($httpcache) == 0) ||
($httpcache == 0))
{ // HTTP cache the section
if ($this->general->smartlink == true) {
$html_text = "_private_getsmartlink($section, "") . "\">";
} else {
$html_text = "";
}
} else { // Don't HTTP cache the section
$html_text = "";
}
if ($linktext != "") { // Use $linktext instead of $Longdescription[$isSection]
$html_text .= "$linktext";
} else { // link text don't defined
if ($this->conf->Longdescription_arr[$isSection] != "") { // Use section long description
$html_text .= $this->conf->Longdescription_arr[$isSection];
} else { // section long description not defined!
$html_text .= "$section";
}
}
$html_text .= "";
return $html_text;
} else { // The section id is not valid
return "";
}
}
/**
* This method return the long description string of the specified section "$section".
* If the requested section is not valid this method returns the passed string.
* @param str section The section name you want the long description
* @return str Section long description
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_ldesc ($section)
{
// This var will contains the text to be returned
$html_text = "";
$isSection = array_search("$section", $this->conf->Section_arr);
if ((trim ($section) != "") && ($isSection > -1)) { // The section id is valid
if ($this->conf->Longdescription_arr[$isSection] != "") { // Use section long description
$html_text .= $this->conf->Longdescription_arr[$isSection];
} else { // section long description not defined!
$html_text .= "$section";
}
} else {
$html_text .= "$section";
}
return $html_text;
}
/**
* This method return the short description string of the specified section "$section".
* If the requested section is not valid this method returns the passed string.
* @param str section The section name you want the short description
* @return str Section short description
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_sdesc ($section)
{
// This var will contains the text to be returned
$html_text = "";
$isSection = array_search("$section", $this->conf->Section_arr);
if ((trim ($section) != "") && ($isSection > -1)) { // The section id is valid
if ($this->conf->Shortdescription_arr[$isSection] != "") { // Use section short description
$html_text .= $this->conf->Shortdescription_arr[$isSection];
} else { // section short description not defined!
$html_text .= "$section";
}
} else {
$html_text .= "$section";
}
return $html_text;
}
/**
* This method return the section filename.
* If the requested section is not valid this method returns null.
* @param str section The section name you want the filename
* @return str Section filename
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_filename ($section)
{ // TODO: write log notes for this function
$isSection = array_search($section, $this->conf->Section_arr);
if ((trim ($section) != "") && ($isSection > -1)) { // The section id is valid
if ($this->conf->Section_file_arr[$isSection] != "") { // Use section file name
$filename = $this->conf->Section_file_arr[$isSection];
} else { // section file name not defined!
return null;
}
} else {
return null;
}
$filen = $this->templates_lang_relpath . "/" . $filename;
if (is_file($filen)) { // Return the given language template file
return $filen;
} else {
// Returns the default language template file
$filen = $this->templates_relpath . "/" . $filename;
return $filen;
}
}
/**
* This method return the section uri.
* @param str section The section name you want the uri
* @param int httpcache 0 = HTTP cache, 1 = HTTP NOT cache
* @return str Section URI
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_uri ($section, $httpcache = 0, $http_params = "")
{ /* This method return the section $section uri.
If $httpcache == 0 or if $httpcache is null the section will be cached.
*/
if ((!$httpcache) || (strlen($httpcache) == 0) || ($httpcache == 0)) {
// HTTP cache the section
if ($this->general->smartlink == true) {
$html_text = $this->_private_getsmartlink($section, $http_params);
} else {
$html_text = '?section=' . $section . "&$http_params";
}
} else { // Don't HTTP cache the section
$html_text = '?n_c=1§ion=' . $section;
}
// echo "DEBUG: html_text: $html_text";
return $html_text;
}
/**
* This method open a HTML form for the given section.
* To avoid to create a form for each included section, cmsdAm let you create your
* own form. Using this method, will be created the form for the given section.
* To get the included section name use the '$cms->sections->section_included' variables.
* @param str section The section name you want to open the form
* @return bool Always true.
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function open_form ($section)
{
// This way we can avoid Globals
include ("external.php");
include ("index_openform.php");
return true;
}
/**
* This method close a HTML form for the given section.
* To avoid to create a form for each included section, cmsdAm let you create your
* own form. Using this method, will be closed the form for the given section.
* To get the included section name use the '$cms->sections->section_included' variables.
* @param str section The section name you want to close the form
* @return bool Always true.
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function close_form ($section)
{
include ("index_closeform.php");
return true;
}
/* SECTION COMMENTS */
/**
* This method add a section comment to the DB.
* @param str text The text you want to add as a section comment
* @return bool True on success, False on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_comment_add ($text)
{ /* This method is used to add a section comment to the DB
It returns true on success or false on error
If $text is empty no comment will be added and this method return true
NOTE: This method open a DB connection if is not already open.
Remember to call the DB_close() method outside after this method if you
don't want to keep the DB connection open when finished!!
*/
$User = $this->users->logged_user;
$client_ip = $cms->http->client_ip;
// Some check!!
if (($text == null) || strlen($text) == 0) { return true; }
$this->debug->debug_write(7, "section_comment_add: section=" . $this->section_requested . ", IP=$client_ip, text=$text");
$this->logs->log_note(7, "section_comment_add: section=" . $this->section_requested . ", IP=$client_ip, text=$text");
// DB connection check, open a connection if is not opened!
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
if (strlen($User) == 0) { // User is not logged in
$uid = $this->users->user_id("anonymous");
} else { // User is logged in
$uid = $this->users->user_id($User);
}
// HTML CHARS SUBSTITUTION - TO AVOID XSS!!
$text = htmlspecialchars($text);
$query = "INSERT INTO " . $this->dbms->DB_tbl_prefix . "comment (id, comment_text, cmsdam_users_id, comment_section, comment_date, ip) VALUES (NULL, \"$text\", $uid, \"" . $this->section_requested . "\", now(), \"$client_ip\")";
if ($this->dbms->dbquery($query) == true) { // Row inserted
return true;
} else { // Error inseting to the DB!
$this->debug->debug_write(7, "section_comment_add: section=" . $this->section_requested . "DB error");
$this->logs->log_note(7, "section_comment_add: section=" . $this->section_requested . "DB error");
return false;
}
}
/**
* This method returns an array that contains all the comment for this section.
* On error return false
* On success return an array
* On success without comments returns null
* @param str param the section you want array, the one requested if omitted or == 1
* @return array Comments array for the requested section
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_comment_getarray ($param = 1)
{ /* This method returns an array that contains all the comment for this section.
On error return false
On success return an array
On success without comments returns null
You may want to use our paginator to get the best ;-)
*/
if ($param == 1) { // Parameter $param not passed, peek the section automatically
$param = $this->section_requested;
}
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
$query = "SELECT * from " . $this->dbms->DB_tbl_prefix . "comment where comment_section=\"$param\" ORDER BY comment_date DESC";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(7, "section_comment_getarray: DB error");
$this->logs->log_note(7, "section_comment_getarray: DB error");
return false;
}
if ($this->dbms->dbnum_rows() == 0) { // No records found
return null;
}
for ($rows = 0; $rows < $this->dbms->dbnum_rows(); $rows++)
{ // Getting data from the database
$data = $this->dbms->dbfetch_row();
// Building the array
$rows_arr[$rows] = $data;
// echo "DEBUG: data: " . $data[0];
}
return $rows_arr;
}
/**
* This method returns an array of integer containig the comment ids for this section
* On error return false
* On success return an array
* On success without comments returns null
* @param str param the section you want array, the one requested if omitted or == 1
* @return array Comments array of ID for the requested section
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function section_comment_getid ($param = 1)
{ /* This method returns an array of integer containig the comment ids for this section,
or eventualy that passed.
On error return false
On success return an array
On success without comments returns null
*/
if ($param == 1) { // Parameter $param not passed, peek the section automatically
$param = $this->section_requested;
}
if ($this->dbms->DB_connect() == false) { // We are NOT connected to the DB
return false;
}
$query = "SELECT id from " . $this->dbms->DB_tbl_prefix . "comment where comment_section=\"$param\" ORDER by comment_date ASC";
if ($this->dbms->dbquery($query) == false) { // Rows not selected
$this->debug->debug_write(7, "section_comment_getid: DB error");
$this->logs->log_note(7, "section_comment_getid: DB error");
return false;
}
if ($this->dbms->dbnum_rows() == 0) { // No records found
return null;
}
for ($rows = 0; $rows < $this->dbms->dbnum_rows(); $rows++)
{ // Getting data from the database
$data = $this->dbms->dbfetch_row();
// Building the array
$rows_arr[$rows] = $data;
}
return $rows_arr;
}
/**
* This is to create a new section. Please consider that:
section names must be unique;
a newly created section is not visible from anyone, even anonymous if not granted.
Section name must not contain invalid characters and cannot begin with '_'
* On error return false
* On success return true
* @param str sect_name is the section name you want to create
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function create_new_section($sect_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
if (eregi("^[a-z0-9][a-z0-9_-]+$", $sect_name) == false) {
//echo "Section must not contain invalid characters and cannot begin with '_'";
$this->logs->log_note(4, "ERROR: cannot create section name $sect_name: invalid characters");
$this->debug->debug_write(4, "ERROR: cannot create section name $sect_name: invalid characters");
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if ($data == "1") { // There is a section with the same name
//echo "DEBUG: section name already exists!";
$this->logs->log_note(3, "Section name already exists creating the new section: $sect_name");
$this->debug->debug_write(3, "Section name already exists creating the new section: $sect_name");
return false;
}
$query = "insert into " . $this->dbms->DB_tbl_prefix . "sections values(NULL, \"$sect_name\", \"".$this->users->logged_user."\", NOW())";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to delete a section.
* On error return false
* On success return true
* @param str sect_name is the section name you want to delete
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function delete_section($sect_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if ($data == "0") { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
$this->logs->log_note(3, "Section name not exists deleting section: $sect_name");
$this->debug->debug_write(3, "Section name not exists deleting section: $sect_name");
return false;
}
$query = "delete from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to add a new template with its parameters (ex language) to a already created section
language name must not be already existent.
* On error return false
* On success return true
* @param str sect_name is the section name you want to add
* @param str language is the language name you want to add
* @param str template is the template for the given language
* @param str short_description is the section short description for the given language
* @param str long_description is the section long description for the given language
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function add_parameters_template($sect_name, $language, $template_name, $short_description, $long_description) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
if ($language == "") { // Language is mandatory
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
$this->logs->log_note(3, "add_parameters_template: Section name does not exists: $sect_name");
$this->debug->debug_write(3, "Section name does not exists: $sect_name");
return false;
}
$sectionid = $data;
// Check if language/template is already defined
$query = "select templates.language from " . $this->dbms->DB_tbl_prefix . "section_templates as templates, " . $this->dbms->DB_tbl_prefix . "sections as sections where templates.language = \"$language\" and templates.section_id = sections.id and sections.section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if ($data != "") { // A language / template is already defined
$this->logs->log_note(4, "ERROR: A language/template with this name is already assigned for this section: $sect_name");
$this->debug->debug_write(4, "ERROR: A language/template with this name is already assigned for this section: $sect_name");
return false;
}
$query = "select template from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if ($data == "") { // The given template does not exists
$this->logs->log_note(4, "ERROR: add_parameters_template: template $template_name does not exists setting section: $sect_name");
$this->debug->debug_write(4, "ERROR: add_parameters_template: template $template_name does not exists setting section: $sect_name");
return false;
}
$query = "insert into " . $this->dbms->DB_tbl_prefix . "section_templates (id, section_id, language, template_name, short_description, long_description, c_user, c_date) values (NULL, \"$sectionid\", \"$language\", \"$template_name\", \"$short_description\", \"$long_description\", \"".$this->users->logged_user."\", NOW())";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
function get_parameter_languages($sect_name) { // Get languages for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
$this->logs->log_note(4, "ERROR: get_parameter_languages: section name does not exist: $sect_name");
$this->debug->debug_write(4, "ERROR: get_parameter_languages: section name does not exist: $sect_name");
return false;
}
$query = "select language from " . $this->dbms->DB_tbl_prefix . "section_templates where section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_templates($sect_name, $lang) { // Get templates for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
if ($lang == "") { // Language is mandatory
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
$this->logs->log_note(4, "ERROR: get_parameter_templates: section name does not exist: $sect_name");
$this->debug->debug_write(4, "ERROR: get_parameter_templates: section name does not exist: $sect_name");
return false;
}
$query = "select template_name from " . $this->dbms->DB_tbl_prefix . "section_templates where section_id = $data and language = \"$lang\"";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_sdesc($sect_name, $lang) { // Get short description for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
if ($lang == "") { // Language is mandatory
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
$this->logs->log_note(4, "ERROR: get_parameter_sdesc: section name does not exist: $sect_name");
$this->debug->debug_write(4, "ERROR: get_parameter_sdesc: section name does not exist: $sect_name");
return false;
}
$query = "select short_description from " . $this->dbms->DB_tbl_prefix . "section_templates where section_id = $data and language = \"$lang\"";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_ldesc($sect_name, $lang) { // Get long description for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
if ($lang == "") { // Language is mandatory
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
$this->logs->log_note(4, "ERROR: get_parameter_ldesc: section name does not exist: $sect_name");
$this->debug->debug_write(4, "ERROR: get_parameter_ldesc: section name does not exist: $sect_name");
return false;
}
$query = "select long_description from " . $this->dbms->DB_tbl_prefix . "section_templates where section_id = $data and language = \"$lang\"";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_cuser($sect_name, $lang) { // Get creation user for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
if ($lang == "") { // Language is mandatory
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
return false;
}
$query = "select c_user from " . $this->dbms->DB_tbl_prefix . "section_templates where section_id = $data and language = \"$lang\"";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_cdate($sect_name, $lang) { // Get creation date for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
if ($lang == "") { // Language is mandatory
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
return false;
}
$query = "select c_date from " . $this->dbms->DB_tbl_prefix . "section_templates where section_id = $data and language = \"$lang\"";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_users($sect_name) { // Get users permissions for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
return false;
}
$query = "select user_name from " . $this->dbms->DB_tbl_prefix . "section_users where section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_groups($sect_name) { // Get groups permissions for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
return false;
}
$query = "select group_name from " . $this->dbms->DB_tbl_prefix . "section_groups where section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_searchusers($sect_name) { // Get users search permissions for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
return false;
}
$query = "select user_name from " . $this->dbms->DB_tbl_prefix . "section_search_users where section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
function get_parameter_searchgroups($sect_name) { // Get groups permissions for this section
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
// Check for section stuff
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
return false;
}
$query = "select group_name from " . $this->dbms->DB_tbl_prefix . "section_search_groups where section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
while ($data = $this->dbms->dbfetch_row()) {
$dataval[] = $data[0];
}
}
return $dataval;
}
/**
* This is to grant a new user to a already created section
user name must not be already existent.
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str user_name is the user to grant the section
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function add_parameters_user($sect_name, $user_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
return false;
}
if (($user_name != "*") && ($user_name != "anonymous") && (! $this->users->user_exist($user_name))) { // The given user must exist!
//echo "DEBUG: the given user must exist!";
$this->logs->log_note(4, "ERROR: add_parameters_user: The user must exist");
$this->debug->debug_write(4, "ERROR: add_parameters_user: The user must exist");
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "section_users where section_id = \"$data\" and user_name = \"$user_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data2 = $this->dbms->dbfetch_row();
$data2 = $data2[0];
if ($data2 > 0) {
//echo "DEBUG: The user is already granted!";
$this->logs->log_note(4, "ERROR: add_parameters_user: Section: $sect_name, user: $user_name is alread granted");
$this->debug->debug_write(4, "ERROR: add_parameters_user: Section: $sect_name, user: $user_name is alread granted");
return false;
}
$query = "insert into " . $this->dbms->DB_tbl_prefix . "section_users (id, user_name, section_id, c_user, c_date) values (NULL, \"$user_name\", $data, \"".$this->users->logged_user."\", NOW())";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to grant a new group to a already created section
group name must not be already existent.
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str group_name is the group to grant the section
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function add_parameters_group($sect_name, $group_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
//echo "DEBUG: section name does not exists!";
$this->logs->log_note(4, "ERROR: add_parameters_group: Section: $sect_name does not exist");
$this->debug->debug_write(4, "ERROR: add_parameters_group: Section: $sect_name does not exist");
return false;
}
if (($group_name != "*") && (array_search($group_name, $this->groups->group_names()) === false)) { // The given group must exist!
//echo "DEBUG: the given group must exist!";
$this->logs->log_note(4, "ERROR: add_parameters_group: Section: $sect_name, group: $group_name does not exist");
$this->debug->debug_write(4, "ERROR: add_parameters_group: Section: $sect_name, group: $group_name does not exist");
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "section_groups where section_id = \"$data\" and group_name = \"$group_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data2 = $this->dbms->dbfetch_row();
$data2 = $data2[0];
if ($data2 > 0) {
$this->logs->log_note(4, "ERROR: add_parameters_group: Section: $sect_name, group: $group_name is already granted");
$this->debug->debug_write(4, "ERROR: add_parameters_group: Section: $sect_name, group: $group_name is already granted");
//echo "DEBUG: The group is already granted!";
return false;
}
$query = "insert into " . $this->dbms->DB_tbl_prefix . "section_groups (id, group_name, section_id, c_user, c_date) values (NULL, \"$group_name\", $data, \"".$this->users->logged_user."\", NOW())";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to grant a new user to search a already created section
user name must not be already existent.
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str user_name is the user to grant the search for the section
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function add_parameters_search_user($sect_name, $user_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
echo "DEBUG: section name does not exists!";
return false;
}
if (($user_name != "*") && ($user_name != "anonymous") && (! $this->users->user_exist($user_name))) { // The given user must exist!
echo "DEBUG: the given user must exist!";
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "section_search_users where section_id = \"$data\" and user_name = \"$user_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data2 = $this->dbms->dbfetch_row();
$data2 = $data2[0];
if ($data2 > 0) {
echo "DEBUG: The user is already granted!";
return false;
}
$query = "insert into " . $this->dbms->DB_tbl_prefix . "section_search_users (id, user_name, section_id, c_user, c_date) values (NULL, \"$user_name\", $data, \"".$this->users->logged_user."\", NOW())";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to grant a new group to search a already created section
group name must not be already existent.
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str group_name is the group to grant the search for the section
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function add_parameters_search_group($sect_name, $group_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
echo "DEBUG: section name does not exists!";
return false;
}
if (($group_name != "*") && (array_search($group_name, $this->groups->group_names()) === false)) { // The given group must exist!
echo "DEBUG: the given group must exist!";
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "section_search_groups where section_id = \"$data\" and group_name = \"$group_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data2 = $this->dbms->dbfetch_row();
$data2 = $data2[0];
if ($data2 > 0) {
echo "DEBUG: The group is already granted!";
return false;
}
$query = "insert into " . $this->dbms->DB_tbl_prefix . "section_search_groups (id, group_name, section_id, c_user, c_date) values (NULL, \"$group_name\", $data, \"".$this->users->logged_user."\", NOW())";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to detach a language with its parameters to a already created section.
* Note that the associated template file will be not deleted anyway!!!
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str language is the language name you want to delete
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function del_parameters_language($sect_name, $language) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
echo "DEBUG: section name does not exists!";
return false;
}
$query = "delete from " . $this->dbms->DB_tbl_prefix . "section_templates where section_id = $data and language = \"$language\"";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to revoke a user from a already created section
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str user_name is the user to revoke the section
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function del_parameters_user($sect_name, $user_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
echo "DEBUG: section name does not exists!";
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "section_users where section_id = $data and user_name = \"$user_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data2 = $this->dbms->dbfetch_row();
$data2 = $data2[0];
if ($data2 <= 0) {
echo "DEBUG: The user is not granted!";
return false;
}
$query = "delete from " . $this->dbms->DB_tbl_prefix . "section_users where user_name = \"$user_name\" and section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to revoke a group from a already created section
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str group_name is the group to revoke the section
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function del_parameters_group($sect_name, $group_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
echo "DEBUG: section name does not exists!";
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "section_groups where section_id = \"$data\" and group_name = \"$group_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data2 = $this->dbms->dbfetch_row();
$data2 = $data2[0];
if ($data2 <= 0) {
echo "DEBUG: The group is not granted!";
return false;
}
$query = "delete from " . $this->dbms->DB_tbl_prefix . "section_groups where group_name = \"$group_name\" and section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to revoke a new user from search a already created section
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str user_name is the user to revoke the search for the section
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function del_parameters_search_user($sect_name, $user_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
echo "DEBUG: section name does not exists!";
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "section_search_users where section_id = \"$data\" and user_name = \"$user_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data2 = $this->dbms->dbfetch_row();
$data2 = $data2[0];
if ($data2 <= 0) {
echo "DEBUG: The user is not granted!";
return false;
}
$query = "delete from " . $this->dbms->DB_tbl_prefix . "section_search_users where user_name = \"$user_name\" and section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* This is to revoke a group to search a already created section.
* On error return false
* On success return true
* @param str sect_name is the section name
* @param str group_name is the group to revoke the search for the section
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function del_parameters_search_group($sect_name, $group_name) { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
echo "DEBUG: section name does not exists!";
return false;
}
$query = "select count(id) from " . $this->dbms->DB_tbl_prefix . "section_search_groups where section_id = \"$data\" and group_name = \"$group_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data2 = $this->dbms->dbfetch_row();
$data2 = $data2[0];
if ($data2 <= 0) {
echo "DEBUG: The group is not granted!";
return false;
}
$query = "delete from " . $this->dbms->DB_tbl_prefix . "section_search_groups where group_name = \"$group_name\" and section_id = $data";
//echo "DEBUG: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
/**
* Use this method to check if the given section is granted for publishing (dynamic section).
* Return false on errors and if section is not enabled for publishing
* On success return true
* @param str sect_name is the section name
* @return bool True or False
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function is_a_publishing_section ($sect_name) {
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
// Get the section id to make a relation with cmsdam_publishing_sections
$data = $this->dbms->dbfetch_row();
$data = $data[0];
//echo "DEBUG: id: $data";
if ($data < 0) {
// Query didn't returned a valid ID, may be the section name does not exist?
return false;
}
$section_id = $data;
if ($section_id == "") {
// echo "DEBUG: Section does not exist";
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "publishing_sections where section_id = $section_id";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
if ($data == "") { // The given section is not granted for publishing
return false;
} else { // The given section is granted for publishing
return true;
}
}
/**
* Use this method to grant the given section for publishing (dynamic section).
* Return false on errors and true on success. Also return false if the section is already granted
* @param str sect_name is the section name
* @return bool True or False
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function grant_section_for_publishing ($sect_name) { // Grant a section from publihsing
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
// Get the section id to make a relation with cmsdam_publishing_sections
$data = $this->dbms->dbfetch_row();
$data = $data[0];
//echo "DEBUG: id: $data";
if ($data < 0) {
// Query didn't returned a valid ID, may be the section name does not exist?
return false;
}
$section_id = $data;
if ($section_id == "") {
// echo "DEBUG: Section does not exist";
return false;
}
$query = "select id from " . $this->dbms->DB_tbl_prefix . "publishing_sections where section_id = $section_id";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
if ($data == "") { // The given section is not granted for publishing
$query = "insert into " . $this->dbms->DB_tbl_prefix . "publishing_sections (id, section_id, c_user, c_date) values (NULL, $section_id, \"".$this->users->logged_user."\", NOW())";
if ($this->dbms->dbquery($query) == false) {
return false;
}
// Section granted for publishing
return true;
} else { // The given section is already granted for publishing
return false;
}
return true;
}
/**
* Use this method to revoke the given section for publishing (dynamic section).
* Return false on errors and true on success. Also return false if the section is not already granted
* @param str sect_name is the section name
* @return bool True or False
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function revoke_section_for_publishing($sect_name) { // Revoke a section from publishing
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
$query = "select b.id from " . $this->dbms->DB_tbl_prefix . "publishing_sections as a, " . $this->dbms->DB_tbl_prefix . "sections as b where a.section_id = b.id and b.section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
if ($data == "") { // The given section is not granted for publishing
return false;
}
if ($data == "") {
//echo "DEBUG: Section does not exist";
return false;
}
$query = "delete from " . $this->dbms->DB_tbl_prefix . "publishing_sections where section_id = $data";
if ($this->dbms->dbquery($query) == false) {
return false;
}
// Entry disabled from publihsing
return true;
}
function add_language($language, $shortlang, $charenc="") { // Add a new language to DB
if ($language == "") {
return false;
}
if ($shortlang == "") {
return false;
}
if (eregi("^[a-z0-9][a-z0-9_-]+$", $language) == false) {
//echo "Language must not contain invalid characters and cannot begin with '_'";
$this->logs->log_note(4, "ERROR: cannot create language $language: invalid characters");
$this->debug->debug_write(4, "ERROR: cannot create language $language: invalid characters");
return false;
}
if (eregi("^[a-z0-9][a-z0-9_-]+$", $shortlang) == false) {
//echo "Language must not contain invalid characters and cannot begin with '_'";
$this->logs->log_note(4, "ERROR: cannot create language $language: invalid characters in shortlang");
$this->debug->debug_write(4, "ERROR: cannot create language $language: invalid characters in shortlang");
return false;
}
if ($charenc == "") { // Setting default
$charenc = "UTF-8";
}
// Get language from database
$query = "select language from " . $this->dbms->DB_tbl_prefix . "section_languages where language = \"$language\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
if ($this->dbms->dbnum_rows() > 0) {
// Language already defined
return false;
}
// Get character encoding from database
$query = "select shortlang from " . $this->dbms->DB_tbl_prefix . "section_languages where shortlang = \"$shortlang\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
if ($this->dbms->dbnum_rows() > 0) {
// Charenc already defined
return false;
}
// Get the charenc ID
$query = "select charenc from " . $this->dbms->DB_tbl_prefix . "section_charenc where shortenc = \"$charenc\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
if ($this->dbms->dbnum_rows() == 0) {
// Charenc not defined
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Insert language into DB
$query = "insert into " . $this->dbms->DB_tbl_prefix . "section_languages values (\"\", \"$language\", \"$shortlang\", $data)";
if ($this->dbms->dbquery($query) == false) {
return false;
}
return true;
}
function del_language($language) { // Add a new language to DB
if ($language == "") {
return false;
}
// Get language from database
$query = "select language from " . $this->dbms->DB_tbl_prefix . "section_languages where language = \"$language\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
if ($this->dbms->dbnum_rows() == 0) {
// Language not defined
return false;
}
// Delete language from DB
$query = "delete from " . $this->dbms->DB_tbl_prefix . "section_languages where language = \"$language\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
return true;
}
function get_languages() { // array with all languages
// Get languages from DB
$query = "select language from " . $this->dbms->DB_tbl_prefix . "section_languages";
if ($this->dbms->dbquery($query) == false) {
return false;
}
if ($this->dbms->dbnum_rows() == 0) {
// Language not defined
return false;
}
for ($i = 0; $i < $this->dbms->dbnum_rows(); $i++) {
$data = $this->dbms->dbfetch_row();
$langs[] = $data[0];
}
return $langs;
}
function get_language_shortlang($language) {
// Get short language from DB
$query = "select shortlang from " . $this->dbms->DB_tbl_prefix . "section_languages where language = \"$language\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
if ($this->dbms->dbnum_rows() == 0) {
// Language not defined
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
return $data;
}
function get_language_charenc($language="") {
// Get charenc language from DB
$query = "select encoding.shortenc from " . $this->dbms->DB_tbl_prefix . "section_languages as language, " . $this->dbms->DB_tbl_prefix . "section_charenc as encoding where language.language = \"$language\" and encoding.charenc = language.charenc";
if ($this->dbms->dbquery($query) == false) {
return false;
}
if ($this->dbms->dbnum_rows() == 0) {
// Language not defined
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
return $data;
}
/**
* This is to set (modify) a template with its parameters (ex language) to a already created section
language name must not be changed with onw that already exist.
* On error return false
* On success return true
* @param str sect_name is the section name you want to modify
* @param str language is the language name you want to modify from
* @param str newlang is the language name you want to modify in (ignore if empty)
* @param str template_name is the template file for the given language (ignore if empty)
* @param str short_description is the section short description for the given language (ignore if empty)
* @param str long_description is the section long description for the given language (ignore if empty)
* @return bool True on success, false on errors
* @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net>
*/
function set_parameters_template($sect_name, $language, $newlang="", $template_name="", $short_description="", $long_description="") { // After 0.8-Stable, sections are on DB! ;-)
if ($sect_name == "") { // You must pass that parameter!!
return false;
}
if ($language == "") { // Language is mandatory
return false;
}
if (($newlang == "") && ($template_name == "") && ($short_description == "") && ($long_description == "")) {
// You don't want to change anything!!
return true;
}
// Get section ID
$query = "select id from " . $this->dbms->DB_tbl_prefix . "sections where section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if (($data == "") || ($data < 0)) { // There is not a section with that name
echo "DEBUG: section name does not exists!";
return false;
}
$sectionid = $data;
if ($language != $newlang) { // User want to change template language
// Check if language/template is already defined
$query = "select templates.language from " . $this->dbms->DB_tbl_prefix . "section_templates as templates, " . $this->dbms->DB_tbl_prefix . "sections as sections where templates.language = \"$newlang\" and templates.section_id = sections.id and sections.section_name = \"$sect_name\"";
if ($this->dbms->dbquery($query) == false) {
return false;
}
$data = $this->dbms->dbfetch_row();
$data = $data[0];
// Get the first column, first row
if ($data != "") { // A language / template is already defined
$this->logs->log_note(4, "ERROR: A language/template with this name is already assigned for this section: $sect_name");
$this->debug->debug_write(4, "ERROR: A language/template with this name is already assigned for this section: $sect_name");
return false;
}
}
// We are going to build the UPDATE query. We add pieces to UPDATE to build the query
$query = "";
if (($language != $newlang) && ($newlang != "")) { // Update language
$query = "UPDATE " . $this->dbms->DB_tbl_prefix . "section_templates SET language = \"$newlang\" ";
// $query = $query . "where section_id = $sectionid AND language = \"$language\"";
}
if ($template_name != "") { // Update template
if ($query == "") { // Query begins here
$query = "UPDATE " . $this->dbms->DB_tbl_prefix . "section_templates SET template_name = \"$template_name\" ";
// $query = $query . "where section_id = $sectionid AND language = \"$language\"";
} else { // Query does not begin here! Add this piece
$query = $query . ", template_name = \"$template_name\" ";
// $query = $query . "where section_id = $sectionid AND language = \"$language\"";
}
}
if ($short_description != "") { // Update Short Description
if ($query == "") {
$query = "UPDATE " . $this->dbms->DB_tbl_prefix . "section_templates SET short_description = \"$short_description\" ";
// $query = $query . "where section_id = $sectionid AND language = \"$language\"";
} else {
$query = $query . ", short_description = \"$short_description\" ";
// $query = $query . "where section_id = $sectionid AND language = \"$language\"";
}
}
if ($long_description != "") { // Update Long Description
if ($query == "") {
$query = "UPDATE " . $this->dbms->DB_tbl_prefix . "section_templates SET long_description = \"$long_description\" ";
// $query = $query . "where section_id = $sectionid AND language = \"$language\"";
} else {
$query = $query . ", long_description = \"$long_description\" ";
// $query = $query . "where section_id = $sectionid AND language = \"$language\"";
}
}
$query = $query . "where section_id = $sectionid AND language = \"$language\"";
// echo "DEBUG: query: $query";
if ($this->dbms->dbquery($query) == false) {
return false;
} else {
return true;
}
}
}
?>