http://www.fsf.org/ or write * to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * */ /* TEMPLATE :: TODO: Finish to write this stuff */ /** * Here are defined methods you can use to handle PHP/HTML pieces of code (templates) mapped into section names. You * have to use this class with sections class. 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. Templates are associated to files. Templates must be associated to sections. You can * imagine templates like physical objects (template files) and sections like logical objects(cmsdam sections)

* Class instance: $cms->sections * @author dAm2K (Dino Ciuffetti) <dino@tuxweb.it> */ class cmsdam_templates { /** * You should not use this variable from your section. * Configuration class instance. */ var $conf; /** * You should not use this variable from your section. * Sections class instance. */ var $sections; /** * 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 $http; /** * You should not use this variable from your section. * DBMS class instance. */ var $dbms; /** * You should not use this variable from your section. * General class instance. */ var $general; /** * This is the filename for the requested section. * @type str */ var $filename; /** * 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) <dino@tuxweb.it> */ function cmsdam_templates () { /* $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; 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; } */ } /** * Check if the given template exists and is valid. * @param str template The template name to check * @return bool True if the template is valid, False if not * @author dAm2K (Dino Ciuffetti) <dino@tuxweb.it> */ function template_isvalid($template) { // Check for section stuff $query = "select template from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template\""; if ($this->dbms->dbquery($query) == false) { return false; } else { $data = $this->dbms->dbfetch_row(); if ($data[0] != "") { return true; } else { return false; } } return false; } /** * Returns a template array with all valid template names * @return array template array * @author dAm2K (Dino Ciuffetti) <dino@tuxweb.it> */ function get_template_arr() { // Check for section stuff $query = "select distinct template from " . $this->dbms->DB_tbl_prefix . "templates order by template"; if ($this->dbms->dbquery($query) == false) { return false; } else { while ($data = $this->dbms->dbfetch_row()) { $dataval[] = $data[0]; } } return $dataval; } /** * This method return the template filename. * If the requested template is not valid this method returns null. * @param str template The template name you want the filename * @return str Template filename * @author dAm2K (Dino Ciuffetti) <dino@tuxweb.it> */ function template_filename ($template, $language) { // TODO: write log notes for this function $query = "select template_file from " . $this->dbms->DB_tbl_prefix . "templates where language = \"$language\" AND template = \"$template\" order by template;"; if ($this->dbms->dbquery($query) == false) { // Rows not selected $this->debug->debug_write(7, "template_filename: DB error"); $this->logs->log_note(7, "template_filename: 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]; } $filename = $data[0]; $filen = "templates/" . $language . "/" . $filename; /* if (is_file($filen)) { // Return the given language template file return $filen; } else { // Returns the default language template file $filen = $this->sections->templates_relpath . "/" . $filename; return $filen; }*/ return $filen; } /** * This is to add a new template to cmsdam.
* On error return false
* On success return true
* @param str language is the language for the given template * @param str template_name is the template name you want to create * @param str template_file is the template file * @param str description is the template description * @return bool True on success, false on errors * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function add_template($language, $template_name, $template_file, $description="") { // After 0.9-Devel, templates are here! if ($language == "") { // Language is mandatory $this->logs->log_note(3, "add_template: Language is mandatory creating a new template"); $this->debug->debug_write(3, "add_template: Language is mandatory creating a new template"); return false; } if ($template_name == "") { // Template name is mandatory $this->logs->log_note(3, "add_template: Template name is mandatory creating a new template"); $this->debug->debug_write(3, "add_template: Template name is mandatory creating a new template"); return false; } if ($template_file == "") { // Template file is mandatory $this->logs->log_note(3, "add_template: Template file is mandatory creating a new template"); $this->debug->debug_write(3, "add_template: Template file is mandatory creating a new template"); return false; } // Check if template is already defined $query = "select template from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\" AND language = \"$language\""; 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)) { // template is already existent //echo "DEBUG: section name does not exists!"; $this->logs->log_note(3, "add_template: Template name already exists: $template_name, language: $language"); $this->debug->debug_write(3, "add_template: Template name already exists: $template_name, language: $language"); return false; } $templateid = $data; $query = "insert into " . $this->dbms->DB_tbl_prefix . "templates (id, template, description, language, template_file, c_user, c_date) VALUES (NULL, \"$template_name\", \"$description\", \"$language\", \"$template_file\", \"".$this->users->logged_user."\", NOW())"; if ($this->dbms->dbquery($query) == false) { return false; } else { return true; } } /** * This is to delete a template from cmsdam.
* On error return false
* On success return true
* @param str language is the language for the given template to delete * @param str template_name is the template name you want to delete * @return bool True on success, false on errors * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function delete_template($language, $template_name) { // After 0.9-Devel, templates are here! if ($language == "") { // Language is mandatory $this->logs->log_note(3, "delete_template: Language is mandatory creating a new template"); $this->debug->debug_write(3, "add_template: Language is mandatory creating a new template"); return false; } if ($template_name == "") { // Template name is mandatory $this->logs->log_note(3, "delete_template: Template name is mandatory creating a new template"); $this->debug->debug_write(3, "add_template: Template name is mandatory creating a new template"); return false; } // Check if template is already defined $query = "select template from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\" AND language = \"$language\""; 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)) { // template is not existent $this->logs->log_note(3, "delete_template: Template name does not exists: $template_name, language: $language"); $this->debug->debug_write(3, "delete_template: Template name does not exists: $template_name, language: $language"); return false; } $templateid = $data; $query = "delete from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\" AND language = \"$language\""; if ($this->dbms->dbquery($query) == false) { return false; } else { return true; } } /** * This is to delete a template with all its languages from cmsdam.
* On error return false
* On success return true
* @param str template_name is the template name you want to delete * @return bool True on success, false on errors * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function delete_template_langs($template_name) { // After 0.9-Devel, templates are here! if ($template_name == "") { // Template name is mandatory $this->logs->log_note(3, "delete_template: Template name is mandatory creating a new template"); $this->debug->debug_write(3, "add_template: Template name is mandatory creating a new template"); return false; } // Check if template is already defined $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 == "") || ($data < 0)) { // template is not existent $this->logs->log_note(3, "delete_template: Template name does not exists: $template_name, language: $language"); $this->debug->debug_write(3, "delete_template: Template name does not exists: $template_name, language: $language"); return false; } $templateid = $data; $query = "delete from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\""; if ($this->dbms->dbquery($query) == false) { return false; } else { return true; } } /** * This is to get the array list of each language associated to this template.
* On error return false
* On success return true
* @param str template_name is the template name * @return bool True on success, false on errors * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function get_template_languages($template_name) { // Get languages for this template if ($template_name == "") { // You must pass that parameter!! return false; } // Check for section stuff $query = "select id 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 == "") || ($data < 0)) { // There is not a template with that name $this->logs->log_note(4, "ERROR: get_template_languages: template name does not exist: $template_name"); $this->debug->debug_write(4, "ERROR: get_template_languages: template name does not exist: $template_name"); return false; } $query = "select language from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\""; if ($this->dbms->dbquery($query) == false) { return false; } else { while ($data = $this->dbms->dbfetch_row()) { $dataval[] = $data[0]; } } return $dataval; } /** * This is to get the user who created this template.
* On error return false
* On success return true
* @param str template_name is the template name * @param str language is the template language * @return bool True on success, false on errors * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function get_template_cuser($template_name, $language) { if ($template_name == "") { // You must pass that parameter!! return false; } if ($language == "") { // Language is mandatory $this->logs->log_note(3, "get_templace_cuser: Language is mandatory"); $this->debug->debug_write(3, "get_template_cuser: Language is mandatory"); return false; } // Check for section stuff $query = "select id 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 == "") || ($data < 0)) { // There is not a template with that name $this->logs->log_note(4, "ERROR: get_template_cuser: template name does not exist: $template_name"); $this->debug->debug_write(4, "ERROR: get_template_cuser: template name does not exist: $template_name"); return false; } $query = "select c_user from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\" AND language = \"$language\""; if ($this->dbms->dbquery($query) == false) { return false; } else { while ($data = $this->dbms->dbfetch_row()) { return $data[0]; } } return false; } /** * This is to get the creation date of this template.
* On error return false
* On success return true
* @param str template_name is the template name * @param str language is the template language * @return bool True on success, false on errors * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function get_template_cdate($template_name, $language) { if ($template_name == "") { // You must pass that parameter!! return false; } if ($language == "") { // Language is mandatory $this->logs->log_note(3, "get_templace_cdate: Language is mandatory"); $this->debug->debug_write(3, "get_template_cdate: Language is mandatory"); return false; } // Check for section stuff $query = "select id 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 == "") || ($data < 0)) { // There is not a template with that name $this->logs->log_note(4, "ERROR: get_template_cdate: template name does not exist: $template_name"); $this->debug->debug_write(4, "ERROR: get_template_cdate: template name does not exist: $template_name"); return false; } $query = "select c_date from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\" AND language = \"$language\""; if ($this->dbms->dbquery($query) == false) { return false; } else { while ($data = $this->dbms->dbfetch_row()) { return $data[0]; } } return false; } /** * This is to get the template description.
* On error return false
* On success return true
* @param str template_name is the template name * @param str language is the template language * @return bool True on success, false on errors * @author dAm2K (Dino Ciuffetti) <dam2k@users.sourceforge.net> */ function get_template_description($template_name, $language) { if ($template_name == "") { // You must pass that parameter!! return false; } if ($language == "") { // Language is mandatory $this->logs->log_note(3, "get_templace_description: Language is mandatory"); $this->debug->debug_write(3, "get_template_description: Language is mandatory"); return false; } // Check for section stuff $query = "select id 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 == "") || ($data < 0)) { // There is not a template with that name $this->logs->log_note(4, "ERROR: get_template_description: template name does not exist: $template_name"); $this->debug->debug_write(4, "ERROR: get_template_description: template name does not exist: $template_name"); return false; } $query = "select description from " . $this->dbms->DB_tbl_prefix . "templates where template = \"$template_name\" AND language = \"$language\""; if ($this->dbms->dbquery($query) == false) { return false; } else { while ($data = $this->dbms->dbfetch_row()) { return $data[0]; } } return false; } } ?>