/include/beContent.inc.php
PHP | 9879 lines | 6208 code | 1945 blank | 1726 comment | 1170 complexity | ff8327d9a523bf8bf4e0865e65d28c41 MD5 | raw file
Possible License(s): LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
-
- /**
- * @copyright
-
- This file is part of beContent.
-
- Foobar 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, either version 3 of the License, or
- (at your option) any later version.
-
- Foobar 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 beContent. If not, see <http://www.gnu.org/licenses/>.
-
- http://www.becontent.org
-
- @todo
-
- 0. instead of checking each time whether all the entities have been
- created, this functionality can be included in a configuration wizard
- to be executed each time the designer wishes
-
- 1. it can be important to have besides a SelectFromReference a link to the
- script to enter a new item into the referenced entity - this may require
- a refactoring with a unique script/controller for all the forms
-
-
- Features:
- *******
- * 25-01-2009
- - Skin caching management implemented, different policies have been included with a site-wide
- configuration
-
- * 24-01-2009
- - UPDATE FILE fix
-
- * 07-01-2009
- - TINY MCE upgrade (Version: 3.2.1.1)
- - Spellchecker plugin added
-
- requirements : see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
-
- * 05-01-2009
- - Backoffice graphics has been re-designed.
- - Pager bugs fixes
- - Form javascript include bug solved
-
-
- * 03-01-2009
- - The frame-private template for the private Skin has been simplified, no more javascript code or ad-hoc inclusions are required.
-
- * 02-01-2009
- - A problem has been fixed, some primary_key values cause the name of the Check Boxes in the RELATION MANAGER to be invalid (such as "john.delano") because of illegale
- characters. The fix consists in using an encoding by means of aux::encode_name function which returns the MD5 of the value, its inversion is not required thus the
- function aux::decode_name is unneeded
-
-
- [...] pleanty of release notes are missing here.
-
-
- * 23-10-2007
- - $refferred removed among the instance variabile of the class Entity
-
-
- * 04-07-2007
- - hierarchicalPosition has been added, it is a Position widget which filters elements according
- to a 1-n relation
- - hierarchicalPosition has been enhanced to work also with self references, ie. 1-n auto
- relations, which makes it very useful to be used to build hierarchical menu.
-
- * 01-06-2007
- - some Notice and Warning have been fixed, for instance
-
- Notice: Use of undefined constant table - assumed 'table' in C:\Users\Alfonso\Documents\Documenti\Sviluppo\conferences\ASE2008\include\beContent.inc.php on line 998
- Notice: Use of undefined constant field - assumed 'field' in C:\Users\Alfonso\Documents\Documenti\Sviluppo\conferences\ASE2008\include\beContent.inc.php on line 999
-
- * 03-03-2007
- - a number of small fixes
- - the NO_DELETE did not work on page 2 for the update, it has been fixed.
-
- * 10-02-2007
- - a generic download utility for all entities containing a FILE field, it is used also in the
- editItem.
-
- * 03-02-2007
- - the referential integrity now takes into account also the entities with the WITH_OWNER
- property
- - the position widget has been fixed (in case of empty entity was having an item with a blank
- string)
-
- * 13-12-2006
- - the entities Entity has now two foreign keys to manage Moderator and ExpressPublish Groups
- - it is possible to specify multiple foreign keys referring to the same table to
- - the referential integrity is also validate for multiple foreign keys
-
- * 11-12-2006
- - the built-in reporting has been updated to list only the item which belongs to the user in the
- session, for those entities which are not WITH_OWNER just lists all the items
- - the reload check has been fixed
-
- * 10-12-2006
- - the dataFilering is working with the bootstrapped version of the user/group/service management
- - the authentication is completely working now with
- . authentication
- . service-based authorization
- . item-based data filtering
-
- * 03-08-2006
-
- - the relation class constructor has now an additional parameters for explicitly giving name to
- the corresponding tables
-
- * 02-08-2006
-
- - htmlentities/addslashes/stripslashes on dataentry, this has problems because when editing with the Editor
- the htmlentities function should not be applied,
-
- * 27.07.2006
-
- - WITH_OWNER timestamp is now in the YYYYMMDDHHmm format, a new LONGDATE type has been
- added but only internally used in combination with WITH_OWNER
-
- - aspect oriented code weaving, each stage (addItem: emitForm, Insertion - editItem:
- Selection, formFeed, Update, Deletion) have now
- - manage the "none" message in the file upload by means of the messaging systems
-
- * 24.07.2006
-
- - delete transactions include now also the deletion
- over the n-m relations
-
- * 23.07.2006
-
- - Multiple N-M relation transactions
-
- * Previously
-
- - Entities definition
- - N-M, 1-N relation definition
- - Insert Transaction
- - Edit Transation
- - Deletion Transaction with Integrity Check
-
-
- */
-
- #VARIOUS
-
- define('HTML', "HTML");
- define('IMG', "IMG");
- define('HTML_IMG', "HTML_IMG");
-
- define('AJAX', 'ajax');
-
- #XMLCHARS
-
- define('MODE1','MODE1');
- define('MODE2','MODE2');
- define('MODE3','MODE3');
-
-
- #Rss Mod
-
- define('MOD1','MOD1');
- define('MOD2','MOD2');
- define('MOD3','MOD3');
-
- # OPERATING SYSTEMS
-
- define('WINDOWS', "WINDOWS");
- define('LINUX', "LINUX");
- define('MACOS', "MACOS");
-
- #require_once "Mail.php";
-
- define('ADD',"add");
- define('EDIT',"edit");
- define('DELETE', "delete");
- define('NO_DELETE', true);
- define('ALL',"ALL");
- define('NO_ARG',"NO_ARG");
-
-
- /* Relation orientation */
-
- define('LEFT', "LEFT");
- define('RIGHT', "RIGHT");
-
- #define(MSG_SURE, "sure");
- define('MSG_UPDATED',"updated");
-
- define('AUTO', "AUTO");
-
- define('ITALIANO',"it");
- define('ENGLISH',"en");
-
- define('PRESENT', "PRESENT");
- define('ABSENT', "ABSENT");
-
-
- define('PRELOAD',"preload");
- define('MANDATORY',"yes");
- define('OPTIONAL', 'OPTIONAL');
- define('EQUAL',"equal");
- define('IMPLIES', "implies");
-
- define('LIMIT', "limit");
- define('NORMAL', 'NORMAL');
- define('COUNT', 'COUNT');
- define('ADVANCED', 'ADVANCED');
- define('PARSE', 'PARSE');
-
-
- /* DATE FORMATS */
-
- define('LETTERS', "LETTERS");
- define('SHORT_LETTERS', "SHORT_LETTERS");
- define('STANDARD', "STANDARD");
- define('STANDARD_PLUS', "STANDARD_PLUS");
- define('EXTENDED', "EXTENDED");
- define('EXTENDED_PLUS', "EXTENDED_PLUS");
- define('TIME', 'TIME');
- define('YEAR', 'YEAR');
-
- /* BASIC DATATYPES */
-
- define('VARCHAR','VARCHAR');
- define('HIDDEN', 'HIDDEN');
- define('TEXT','TEXT');
- define('FILE','FILE');
- define('FILE2FOLDER', 'FILE2FOLDER');
- define('IMAGE', 'IMAGE');
- define('INT','INT');
- define('STANDARD_PRIMARY_KEY_TYPE', 'INT UNSIGNED AUTO_INCREMENT');
- define('DATE','DATE');
- define('LONGDATE', 'LONGDATE');
- define('POSITION','POSITION');
- define('PASSWORD','PASSWORD');
- define('COLOR', 'COLOR');
- define('CHECKBOX', 'CHECKBOX');
- define('RELATION_MANAGER', 'RELATION MANAGER');
-
- /* WIDGET TYPES */
-
- define('SELECT_FROM_REFERENCE', 'selectFromReference');
- define('RADIO_FROM_REFERENCE', 'radioFromReference');
-
- /* to be completed */
-
-
- define('WITH_OWNER','WITH_OWNER');
- define('BY_POSITION','BY_POSITION');
- define('MD5', 'MD5');
-
- define('POST','POST');
- define('GET','GET');
-
- /* NOTIFY MESSAGES */
-
- define('NOTIFY_ITEM_ADDED','801');
- define('NOTIFY_ITEM_UPDATED','802');
- define('NOTIFY_ITEM_DELETED','803');
- define('NOTIFY_ITEM_INTEGRITY_VIOLATION','804');
-
- /* FILE UPLOAD MESSAGES */
-
- define('MSG_REPORT_EMPTY', '501');
-
- define('MSG_FILE_NONE', '601');
- define('MSG_FILE_DELETE', '602');
-
- /* ERROR MESSAGES */
-
- define('MSG_ERROR_DATABASE_GENERIC','900');
- define('MSG_ERROR_DATABASE_OPEN','901');
- define('MSG_ERROR_DATABASE_CONNECTION','902');
- define('MSG_ERROR_DATABASE_TABLE','903');
- define('MSG_ERROR_DATABASE_QUERY','904');
- define('MSG_ERROR_DATABASE_DUPLICATE_KEY','905');
- define('MSG_ERROR_DATABASE_RELOAD','906');
-
-
- define('MSG_ERROR_DATABASE_PRESENTATION','907');
- define('MSG_ERROR_UNKNOWN_ENTITY','908');
-
- define('MSG_ERROR_TRIGGERS','909');
- define('MSG_ERROR_RELATION_MANAGER','910');
- define('MSG_ERROR_DATABASE_RELATION_INSERT','911');
- define('MSG_ERROR_SESSION','912');
- define('MSG_ERROR_DATABASE_DELETION','913');
- define('MSG_ERROR_DATABASE_BOOTSTRAP','914');
- define('MSG_ERROR_DATABASE_INIT', '915');
-
-
- /* JAVASCRIPT MESSAGES */
-
- define('WARNING', '000');
-
- define('MSG_JS_INSERT','701');
- define('MSG_JS_SURE','702');
- define('MSG_JS_SELECT','703');
- define('MSG_JS_MODERATION','704');
- define('MSG_JS_RADIO', '705');
- define('MSG_JS_RELATIONMANAGER', '706');
- define('MSG_JS_IMPLIES', '707');
- define('MSG_JS_EXTENSION', '708');
- define('MSG_JS_INSERT_TIME', '709');
-
- /* BUTTON LABELS */
-
- define('BUTTON_ACCEPT','1001');
- define('BUTTON_REFUSE','1002');
- define('BUTTON_ADD', '1003');
- define('BUTTON_EDIT', '1004');
- define('BUTTON_DELETE', '1005');
-
- define('FIELDSET', '1006');
-
- define('MODERATION_ACCEPT','1011');
- define('MODERATION_REFUSE','1012');
- define('MODERATION_EXPIRED','1013');
-
- /* RSS MODALITY */
- define('MODALITY1','1101');
- define('MODALITY2','1102');
- define('MODALITY3','1103');
- define('RSS_MODALITY1_MSG', '1104');
- define('RSS_MODALITY2_MSG', '1105');
-
- /* SYSTEM USER GROUPS */
- define('ADMIN', 1);
-
- /* VARIOUS */
-
- define('OMIT_LOGGED_USER', 'OMIT_LOGGED_USER');
-
- $RESERVEDWORDS = Array('page');
-
-
- /**
- * Class Widget
- *
- */
- Class Widget {
- var
- $name,
- $label,
- $mandatory;
-
- function Widget($name, $label, $mandatory = "no") {
- $this->name = $name;
- $this->label = $label;
- $this->mandatory = $mandatory;
- }
-
- function display() {
- return "Widget {$this->name} - no display admitted!";
- }
-
- }
-
- /**
- * Class Text
- *
- */
- Class Text extends Widget {
- var
- $size,
- $maxlength;
-
- function Text($name,
- $label,
- $size = "20",
- $mandatory = "off",
- $maxlength = "") {
-
- Widget::Widget($name,$label,$mandatory);
- $this->size = $size;
- $this->maxlength = $maxlength;
-
- }
-
- function display() {}
- }
-
-
- /**
- * Message - coded message
- *
- */
- Class Message {
- var $messages = Array( // ITALIAN
- "it" => Array(
- "000" => "Attenzione",
- "001" => "Sei Sicuro ?",
- "501" => "Non ci sono elementi",
- "601" => "vuoto",
- "602" => "rimuovi",
- "701" => "Attenzione: inserire {label} !",
- "702" => "Sei Sicura/o ?",
- "703" => "Attenzione: selezionare {label} !",
- "704" => "Indicare il motivo del rigetto della pubblicazione !",
- "705" => "Attenzione: selezionare {label} !",
- "706" => "Attenzione: selezionare almeno un {label} !",
- "707" => "Attenzione: inserire o selezionare {label} !",
- "708" => "Attenzione: tipo di file errato per {label} !",
- "709" => "Attenzione: indicate anche ora e minuti per {label} !",
- "801" => "L'inserimento � stato effettuato con successo !",
- "802" => "L'aggiornamento � stato effettuato con successo !",
- "803" => "La cancellazione � avvenuta con successo !",
- "804" => "L'elemento selezionato per la cancellazione non pu� essere rimosso perch� in uso.",
- "900" => "Database: Errore Generico ",
- "901" => "Database: Error in opening database ",
- "902" => "Database: Error in opening connection to database ",
- "903" => "Database: Error in creating table ",
- "904" => "Database: Error in querying ",
- "905" => "Attenzione: la chiave risulta gi� presente, modifica per procedere!",
- "906" => "Attenzione: l'inserimento � annullato perch� la transazione � gi� avvenuta!",
- "907" => "Attenzione: errore in interrogazione query, probabilmente non � stata definita una presentazione (setPresentation) per la tabella ",
- "908" => "Database: entit� specificata nella relazione inesistente",
- "909" => "Attenzione: solo form relative a Relazioni possono essere messe in cascata ",
- "910" => "Attenzione: non � possibile adottare un RelationManager per questo tipo di form ",
- "911" => "Attenzione: si � verificato un errore di inserimento nella relazione ",
- "912" => "Attenzione: operazione non ammissibile, sessione non aperta ",
- "913" => "Attenzione: errore di cancellazione ",
- "914" => "Attezione: il sistema non pu� essere inizializzato ",
- "915" => "Attezione: errore di tipi nell'inizializzazione ",
- "1001" => "Pubblica",
- "1002" => "Rifiuta",
- "1003" => "Aggiungi",
- "1004" => "Modifica",
- "1005" => "Rimuovi",
- "1006" => "Tue/Tuoi",
- "1011" => "<b>Grazie!</b><br><br>L'informazione � stata <u>pubblicata</u> e l'autore verr� informato!",
- "1012" => "<b>Grazie!</b><br><br>L'informazione � stata <u>rifiutata</u> e l'autore verr� informato!",
- "1013" => "<b>Attenzione!</b><br><br>La moderazione � stata gi� processata da un altro Editor!",
- "1101" => "Sempre",
- "1102" => "Batch Selettivo",
- "1103" => "Selettivo",
- "1104" => "RSS enabled",
- "1105" => "RSS enabled"
-
- ),
- "en" => Array( // ENGLISH
- "000" => "Warning",
- "001" => "Are you sure ?",
- "501" => "There are no items!",
- "601" => "none",
- "602" => "delete",
- "701" => "Warning: please insert {label} !",
- "702" => "Are you sure ?",
- "703" => "Warning: please select {label} !",
- "704" => "Please specify to the author why this item is rejected !",
- "705" => "Warning: please select {label} !",
- "706" => "Warning: please select at least one {label} !",
- "707" => "Warning: please enter or select {label} !",
- "708" => "Warning: the select file type for {label} is not correct !",
- "709" => "Warning: please enter also the time for {label} !",
- "801" => "The item has been correctly added!",
- "802" => "The item has been correctly updated!",
- "803" => "The item has been removed!",
- "804" => "The deletion cannot take place, because the item you selected is still in use!",
- "900" => "Database: Generic Error ",
- "901" => "Database: Error in opening database ",
- "902" => "Database: Error in opening connection to database ",
- "903" => "Database: Error in creating table ",
- "904" => "Database: Error in querying ",
- "905" => "Warning: duplicate key, enter another value to proceed!",
- "906" => "Warning: transaction cannot take place since already executed!",
- "907" => "Warning: error in querying, likely a presentation has been not defined for table ",
- "908" => "Database: unknown entity in the specified relation",
- "909" => "Warning: only Relation-based form can be in cascade triggered ",
- "910" => "Warning: a RelationManager object cannot be used for this form ",
- "911" => "Warning: an error occourred while inserting tuples into the relation ",
- "912" => "Warning: the operation is not allowed as the session has been not created ",
- "913" => "Warning: error in deletion ",
- "914" => "Warning: the system cannot be bootstrapped ",
- "915" => "Warning: likely a datatype error occurred in the initialization, eg. INT requires 0 valued field if bank is intended ",
- "1001" => "Publish",
- "1002" => "Reject",
- "1002" => "Rifiuta",
- "1003" => "Add",
- "1004" => "Save",
- "1005" => "Delete",
- "1006" => "Your",
- "1011" => "<b>Thank you!</b><br><br>The content has been <u>published</u>, the author is going to be informed!",
- "1012" => "<b>Thank you!</b><br><br>The content has been <u>rejected</u> and the author is going to be informed!",
- "1013" => "<b>Warning!</b><br><br>The content has been already validated by another Editor!",
- "1101" => "Sempre",
- "1102" => "Batch Selettivo",
- "1103" => "Selettivo",
- "1104" => "RSS enabled",
- "1105" => "RSS enabled"
- )
- ),
- $language = "it";
-
- /**
- * Constructor.
- *
- * @param string $language
- * @return Message
- */
- function Message($language) {
- $this->language = $language;
- }
-
- /**
- * Returns message in the selected language.
- *
- * @param costant $code defined in the class.
- * @param array $data placeholder replacement in the message
- * @return string
- */
- function getMessage($code, $data = "") {
- $GLOBALS['count']++;
- if ($GLOBALS['count'] == 2) {
- #echo "code: $code<br>";
- #echo "data: $data<hr>";
- }
-
- if (is_array($data)) {
- $buffer = $this->messages[$this->language][$code];
- if ( (count($data) > 0) && ($data != "") ) {
- foreach($data as $key => $value) {
- if (is_string($value)) {
- $buffer = str_replace('\{'.$key.'\}', $value, $buffer);
- }
- }
- } // if
- return $buffer;
- } else {
- return aux::xmlchars($this->messages[$this->language][$code]);
- }
- }
- } // Class Message
-
- $count = 0;
-
-
- /**
- * Class aux - encodes the xml characters
- * @static
- */
- Class aux {
- /**
- * Encrypt-decrypt the input message.
- *
- * @param string $Str_Message to decrypt
- * @return encrypted decrypted message
- */
- function encrypt_decrypt($Str_Message) {
- $Len_Str_Message = strlen($Str_Message);
- $Str_Encrypted_Message = "";
-
- for ($Position=0; $Position<$Len_Str_Message; $Position++) {
- $Key_To_Use = ( ($Len_Str_Message + $Position) + 1 ); // (+5 or *3 or ^2)
- $Key_To_Use = ( 255 + $Key_To_Use ) % 255;
-
- $Byte_To_Be_Encrypted = SUBSTR($Str_Message, $Position, 1);
- $Ascii_Num_Byte_To_Encrypt = ORD($Byte_To_Be_Encrypted);
- $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use; //xor operation
- $Encrypted_Byte = CHR($Xored_Byte);
- $Str_Encrypted_Message .= $Encrypted_Byte;
- }
- return $Str_Encrypted_Message;
- }
-
- /**
- * Encrypt the string message.
- *
- * @param string $message to encrypt
- * @return string urlencoded message
- */
- function encrypt($message) {
- return urlencode(aux::encrypt_decrypt($message));
- }
-
- /**
- * Decrypt the string message.
- *
- * @param string $message to decrypt
- * @return string urlencoded message
- */
- function decrypt($message) {
- return aux::encrypt_decrypt(urldecode($message));
- }
-
- /**
- * Escapes string from quotes (using mysql_escape_string($str)).
- *
- * @param string $string string to escape
- * @return string
- */
- function escape_string($string) {
- return mysql_escape_string($string);
- }
-
- /**
- * Changes the @ with an image that seems.
- *
- * @param string $email email address
- * @param string $pars['mode'] substitutes <img src='img/beContent/chiocciola-$pars['mode'].gif'
- * @return string
- */
- function email($email, $pars) {
- #$email = ereg_replace("@", "<span class=\"email\">[at]</span>", $email);
- #$email = ereg_replace("\.", "<span class=\"email\">[dot]</span>", $email);
-
- if (!isset($pars['mode'])) {
- $email = ereg_replace("@", "<img style=\"margin-bottom: -2px;\"src=\"img/beContent/chiocciola.gif\" alt=\"@\">", $email);
- } else {
- $email = ereg_replace("@", "<img style=\"margin-bottom: -2px;\"src=\"img/beContent/chiocciola-{$pars['mode']}.gif\" alt=\"@\">", $email);
- }
- return "{$email}";
- }
-
- /**
- * Encodes name in MD5.
- *
- * @param string $name to encode
- * @return string name encoded
- */
- function encode_name($name) {
- return md5($name);
- }
-
- /**
- * Return name as it is.
- *
- * @param string $name name
- * @return name
- */
- function decode_name($name) {
- return $name;
- }
-
- /**
- * This function is useless converts telphone number
- * from 0039 zero or more spaces 0862 zero or more spaces in
- * +39 0862[[:space:]]
- *
- * @param string $phone phone number
- * @return string
- */
- function phone($phone) {
- $phone = ereg_replace("^0039[[:space:]]*0862[[:space:]]*", "+39 0862 ", $phone);
- return $phone;
- }
-
- /**
- * Converts the characters in html compatibles.
- * MODE1:
- * & -> &
- * < -> < > -> >
- * " -> " ' -> '
- * MODE 2: uses htmlentities PHP function
- * MODE 3: Uses th htmlentities translation table
- *
- * @param string $str string to convert
- * @param constant $mode MODE1,MODE2...
- * @return string
- */
- function xmlchars($str, $mode = MODE1) {
- switch($mode) {
- case MODE1:
- $str = str_replace('&', '&', $str);
- $str = str_replace('<', '<', $str);
- $str = str_replace('>', '>', $str);
- $str = str_replace('"', '"', $str);
- $str = str_replace("'", ''', $str);
- break;
- case MODE2:
- $str = htmlentities($str);
- break;
- case MODE3:
- $trans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
- $trans = array_flip($trans);
- $str = strtr($str, $trans);
- $str = preg_replace('/&#(d+);/me', "chr(\1)", $str);
- $str = preg_replace('/&#x([a-f0-9]+);/mei', "chr(0x\1)", $str);
- $trans = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES);
-
- foreach ($trans as $key => $value) {
- $trans[$key] = '&#'.ord($key).';';
- }
- $str = strtr($str, $trans);
-
- break;
- }
- return $str;
- }
-
- /**
- * Recognises parameters inside template files.
- *
- * @param string $parameters to recognise parName=parValue, ...
- * @return array parName->parValue
- */
- function parsePars($parameters) {
- $buffer = $parameters;
- do {
- $result = ereg("^([[:alnum:] \_]+)", $buffer, $token);
- if ($result) {
- $buffer = ereg_replace("^$token[1]", "", $buffer);
- $result2 = ereg("^=\"([[:alnum:]\.\_\% \-]*)\"", $buffer, $token2);
- if ($result2) {
- $buffer = ereg_replace("^=\"$token2[1]\"[[:space:] ]*", "", $buffer);
- $par[$token[1]] = $token2[1];
- }
- } // if
- } while ($result);
-
- return $par;
- }
-
- /**
- * Get a result array from a query.
- *
- * @param string $query SQL query
- * @param unknown_type $field
- * @return array
- */
- function getResultArray($query,$field){
- $data = aux::getResult($query);
- $i = 0;
- while ($data[$i]) {
- $result[] = $data[$i][$field];
- $i++;
- }
- return $result;
- }
-
- /**
- * Get a result from a query.
- *
- * @param string $query Sql query
- * @param constant $mode
- * @return array
- */
- function getResult($query, $mode = "NORMAL") {
- switch ($mode) {
- case ADVANCED:
- case PARSE:
- $finito = false;
- do {
- if (ereg("\[([[:alnum:]]*)\]", $query, $token)) {
- $query = ereg_replace("\[{$token[1]}\]", $_REQUEST[$token[1]], $query);
- } else {
- $finito = true;
- }
- } while (!$finito);
- break;
- default:
- break;
- }
-
- if ($mode == PARSE) {
- return $query;
- } else {
- $oid = mysql_query($query);
- if (!$oid) {
- echo mysql_error();
- echo "<hr>",$query; exit;
- echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC);
- exit;
- }
-
- do {
- $data = mysql_fetch_assoc($oid);
- if ($data) {
- foreach ($data as $k=>$v) {
- if (is_string($data[$k])) {
- $data[$k] = stripslashes($v);
- }
- }
- $content[] = $data;
- }
- } while ($data);
-
- return $content;
- }
- }
-
- /**
- * Enter description here...
- *
- * @param unknown_type $arg
- * @param unknown_type $separator
- * @return unknown
- */
- function first_comma($arg, $separator) {
- global $comma;
-
- // if ((isset($comma[$arg])) && (!$comma[$arg])) {
- if (!isset($comma[$arg])) {
- $comma[$arg] = true;
- return "";
- } else {
- return $separator;
- }
- }
-
- /**
- * Sends mail.
- * (use php comand mail)
- *
- * @param string $to email address
- * @param string $subject subject of the email
- * @param string_type $message message of the email
- * @param string $from email address
- */
- function mail($to, $subject, $message, $from) {
- $signature = new Template("dtml/signature.mail");
- $message .= $signature->get();
-
- mail($to, $subject, $message, "From: {$from}");
- }
-
- /**
- * Returns the date of yesterday in format YYYY/MM/DD
- *
- * @return date YYYY/MM/DD
- */
- function yesterday() {
- $day = time() - (24 * 60 * 60);
- $strtime = strtotime(date('m/d/Y', $day));
- return strftime("%Y%m%d", $strtime);
-
- }
-
- /**
- * Function to format date.
- * format types:
- * RSS LETTERS SHORTLETTERS STANDARD STANDARD_PLUS BLOG EXTENDED EXTENDED_PLUS TIME YEAR
- *
- * @param YYYYDDMM $date
- * @param constant $format format type
- * @return string formatted date
- */
- function formatDate($date, $format = "") {
- switch ($format) {
- case RSS:
- ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
- $result = date("D, j M Y 06:00:00 +0100",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
- break;
-
- case LETTERS:
- ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
- $result = date("F jS Y",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
- break;
-
- case SHORT_LETTERS:
- ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
- $result = date("M j, Y",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
- break;
-
- case STANDARD:
- if ($date != "") {
- if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
- $result = "{$token[3]}/{$token[2]}/{$token[1]}";
- } elseif (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
- $result = "{$token[3]}/{$token[2]}/{$token[1]}";
- }
- } else {
- $result = "";
- }
- break;
-
- case STANDARD_PLUS:
- if ($date != "") {
- ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
-
- if (date("Ymd") == "{$token[1]}{$token[2]}{$token[3]}") {
- $result = aux::lingual("Oggi", "Today", "Oy");
- } else {
- $result = "{$token[3]}/{$token[2]}/{$token[1]}";
- }
- if ($token[4] != "") {
- $result .= " {$token[4]}:{$token[5]}";
- }
- } else {
- $result = "";
- }
- break;
-
- case BLOG: // calendar colouredsquare
- if ($date != "") {
- ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
- $date = date("jS M",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
- $result = "<div title=\"Oggi\" style=\"float: left; line-height: 13px; font-size: 9px;padding-top: 4px; margin: 2px 20px 0px 10px; width: 29px; height: 32px; text-align:center; background: url(img/date.jpg) no-repeat;\">{$date}</div>";
- } else {
- $result = "";
- }
- break;
-
- case EXTENDED:
- setlocale(LC_ALL, aux::getLocale($_SESSION['language']));
- if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
- $day = "{$token[2]}/{$token[3]}/{$token[1]} {$token[4]}:{$token[5]}";
- $strtime = strtotime($day);
- $result = strftime("%A %d %B, %H:%M", $strtime);
- } else if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
- $day = "{$token[2]}/{$token[3]}/{$token[1]} 00:01";
- $strtime = strtotime($day);
- $result = strftime("%A %d %B", $strtime);
- }
- break;
-
- case EXTENDED_PLUS: // Thursday 01 January (locale)
- setlocale(LC_ALL, aux::getLocale($_SESSION['language']));
-
- if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
- if ("{$token[2]}{$token[3]}{$token[1]}" == date("mdY")) {
- $result = "Oggi {$token[4]}:{$token[5]}";
- } else {
- $day = "{$token[2]}/{$token[3]}/{$token[1]} {$token[4]}:{$token[5]}";
- $strtime = strtotime($day);
- $result = strftime("%A %d %B, %H:%M", $strtime);
- }
- } else if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
-
- if ("{$token[2]}{$token[3]}{$token[1]}" == date("mdY")) {
- $result = "Oggi";
- } else {
- $day = "{$token[2]}/{$token[3]}/{$token[1]} 00:01";
- $strtime = strtotime($day);
- $result = strftime("%A %d %B", $strtime);
- }
- }
- break;
-
- case TIME: // hh:mm
- $h = substr($date,8,2);
- $m = substr($date,10,2);
- return "{$h}:{$m}";
- break;
-
- case YEAR: // yyyy
- $y = substr($date,0,4);
- return $y;
- break;
-
- default: // mm.dd.yyyy
- ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
- $result = "{$token[3]}.{$token[2]}.{$token[1]}";
- break;
-
- }
- return $result;
- }
-
- /**
- * Return subtext of a text cutted at a given length.
- *
- * @param string $text text
- * @param integer $length length to cut
- * @return the new text cutted
- */
- function subtext($text, $length = 100) {
- if (strlen(strip_tags(html_entity_decode($text))) < $length) {
- $result = strip_tags(html_entity_decode($text));
- } else {
- $newtext = wordwrap(strip_tags(html_entity_decode($text)), $length, "<interrupt>");
- $pos = strpos($newtext, "<interrupt>");
- $result = substr($newtext, 0, $pos);
- }
-
- return $result;
- }
-
- /**
- * Strips slashes from a value.
- *
- * @param string $value to strip
- * @return value stripped
- */
- function quote_smart($value) {
- if (get_magic_quotes_gpc()) { // Stripslashes
- $value = stripslashes($value);
- }
- if (!is_numeric($value)) { // Quote if not integer
- $value = "'" . mysql_real_escape_string($value) . "'";
- }
- return $value;
- }
-
- /**
- * Makes an indentation of 4 * for level.
- *
- * @param integer $level level of indentation
- * @return indentation string
- */
- function mkIndent($level) {
- #echo "** {$level}<br>";
- $result = "";
- for($i=0; $i<$level; $i++) {
- $result .= " ";
- }
- return $result;
- }
-
- /**
- * Finds a children of the parent recursively.
- *
- * @param unknown_type $parent
- * @param unknown_type $level
- */
- function FindChildren ($parent, $level) {
- global
- $flag,
- $data,
- $tree_text,
- $tree_value,
- $tree_level,
- $undef_flag;
-
- for ($i=0; $i<count($data); $i++) {
- if (($data[$i]['reference'] == $parent) and (!isset($flag[$i]))) {
- $tree_value[] = $data[$i]['value'];
- $tree_text [] = aux::mkIndent($level) . $data[$i]['text'];
- $tree_level[] = $level;
- $flag[$i] = true;
- aux::FindChildren($data[$i]['value'],$level+1);
- }
- }
- }
-
- /**
- * Merge two or more arrays without duplicates.
- *
- * @param array $arrays arrays
- * @return array merged
- */
- function array_merge($arrays) {
- $result = array();
-
- foreach($arrays as $array) {
- $result = array_merge(
- array_diff($result,$array),
- array_diff($array,$result),
- array_intersect($result,$array)
- );
- }
- return $result;
- }
-
- /**
- * Add an element in a array if not already exists.
- *
- * @param array $array container
- * @param element $element element to insert into
- * @return array with th new element
- */
- function add_distinct($array, $element) {
- if (!is_array($array)) {
- $array = array();
- }
- if (!in_array($element, $array)) {
- $array[] = $element;
- }
- return $array;
- }
-
- /**
- * This function provides ajax encoding.
- *
- * @param object $object object to encode
- * @return object encoded
- */
- function AjaxEncode($object) {
- $str = serialize($object);
-
- #$str = str_replace(array('\\', "'"), array("\\\\", "\\'"), $str);
- $str = preg_replace('#([\x00-\x08])#e', '"\x" . sprintf("%02x", ord("\1"))', $str);
- $str = preg_replace('#([\x0A-\x1F])#e', '"\x" . sprintf("%02x", ord("\1"))', $str);
- #$str = ereg_replace("\\x0d","",$str);
- #$str = ereg_replace("\\x02","",$str);
- #$str = ereg_replace("\\x01","",$str);
- #$str = ereg_replace("\\x12","",$str);
- #$str = ereg_replace("\\x0e","",$str);
- $str = ereg_replace("\\x0[0-9a-f]", "", $str);
- $str = ereg_replace("\\x1[0-9a-f]", "", $str);
-
- #Header("Content-type: text/plain");
- #echo stripslashes($str);exit;
- return $str;
- }
-
- /**
- * Returns item passed to function according with the session language.
- *
- * @param $item_it
- * @param $item_en
- * @param $item_es
- * @return item_sessionlanguage
- */
- function lingual($item_it, $item_en, $item_es = "") {
- $item = "item_{$_SESSION['language']}";
- return $$item;
- }
-
- /**
- * Returns locale string according with os in use.
- *
- * @param string $language
- * @return locale string
- */
- function getLocale($language) {
- $locale = array(
- WINDOWS => array("it" => "ita_ita", "en" => "eng_eng","es" => "esp_esp"),
- LINUX => array("it" => "it_IT", "en" => "en_UK", "es" => "es_ES")
- );
- return $locale[$GLOBALS['config']['os']][$language];
- }
-
- function refineQuery($query, $condition) {
- $queryToken['body'] = $query;
- if (ereg("(.*)(".sql_regcase("order by").".*)$", $queryToken['body'], $token)) {
- $queryToken['order_by'] = $token[2];
- $queryToken['body'] = $token[1];
- }
- if (ereg("(.*)(".sql_regcase("where").".*)$", $queryToken['body'], $token)) {
- $queryToken['where'] = $token[2];
- $queryToken['body'] = $token[1];
- }
-
- $query = $queryToken['body'];
-
- if ($queryToken['where'] == "") {
- if ($condition != "") {
- $query .= " WHERE {$condition} ";
- }
- } else {
- $query .= $queryToken['where']." AND {$condition} ";
- }
-
- $query .= $queryToken['order_by'];
-
- return $query;
- }
-
- function evaluate($str, $array) {
- do {
- $result = ereg("^.*\[(.*)\]", $str, $token);
- if ($result) {
- $buffer = $str;
- $str = ereg_replace("\[{$token[1]}\]", $array[$token[1]], $buffer);
- }
- } while ($result);
-
- return $str;
- }
-
- function seo_url($str) {
- $str = str_replace("?", "", $str);
- $str = str_replace(":", "", $str);
- $str = str_replace("/", "", $str);
- $str = str_replace("\\", "", $str);
- $str = str_replace("!", "", $str);
- $str = str_replace(".", "", $str);
- return str_replace(" ", "-", $str);
- }
- } // Class aux
-
-
-
- /**
- * Class - beContenPager
- *
- */
- Class beContentPager {
- var $itemTemplate;
- var $template;
-
- /**
- * Query.
- *
- * @var string
- */
- var $query;
-
- /**
- * WHERE clause content.
- *
- * @var string
- */
- var $filter;
-
- /**
- * ORDER BY clause content.
- *
- * @var string
- */
- var $order;
-
- /**
- * Number of the page items.
- *
- * @var unknown_type
- */
- var $length;
-
-
- /**
- * Constructor.
- *
- * @param integer $length page items
- * @return beContentPager
- */
- function beContentPager($length = 15) {
- $this->itemTemplate = $template = "";
- $this->query = "";
- $this->length = $length;
- }
-
- /**
- * Sets the query to perform.
- *
- * @param unknown_type $query
- */
- function setQuery($query) {
- $this->query = $query;
- }
-
- /**
- * Sets filter to pass to the query in WHERE clause.
- *
- * @param string $filter
- * @example id=1 OR id=0
- */
- function setFilter($filter) {
- $this->filter = $filter;
- }
-
- /**
- * Sets order to pass to the query in ORDER clause.
- * Complete the ORDER cause
- *
- * @param string $order
- * @example order by id ASC
- */
- function setOrder($order) {
- $this->order = $order;
- }
-
- /**
- * Returns query with WHERE and ORDER clauses concatenated.
- *
- * @return string query
- */
- function getQuery() {
- $query = $this->query;
-
- if ($this->filter != "") {
- $query .= " WHERE {$this->filter}";
- }
- if ($this->order != "") {
- $query .= " ORDER BY {$this->order}";
- }
- return $query;
- }
-
- /**
- * Sets template to use.
- *
- * @param string $template
- */
- function setTemplate($template) {
- $this->itemTemplate = $template;
- }
-
-
- function displayItem($item) {
- $this->template->setContent("script", basename($_SERVER['SCRIPT_FILENAME']));
- foreach($item as $k => $v) {
- $this->template->setContent($k,$this->display($k,$v));
- }
- }
-
- function get($data) {
- if (is_array($data)) {
- if ($this->itemTemplate == "") {
- if (isset($data[0]['lastmodified'])) {
- $this->setTemplate("dtml/ajax-report-with-owner.html");
- } else {
- $this->setTemplate("dtml/ajax-report.html");
- }
- }
- $this->template = new Template($this->itemTemplate);
-
- foreach($data as $item) {
- $this->displayItem($item);
- }
- return $this->template->get();
- }
- }
-
- /**
- * Formats content to display.
- *
- * @param string $k key
- * @param string $v to format
- * @return string
- */
- function display($k,$v) {
- switch($k) {
- case "lastmodified":
- if ($v == "") {
- return "";
- } else {
- return aux::formatDate($v , SHORT_LETTERS);
- }
- break;
-
- case "owner":
- return "by {$v}";
- break;
-
- case "active":
- if ($v == "*") {
- return "checked";
- } else {
- return "";
- }
- break;
-
- default:
- return aux::xmlchars($v, MODE3);
- break;
- }
- return $v;
- }
- }
-
- Class beContent {
- var
- $files,
- $selfrefs,
- $entities,
- $currentform,
- $comments;
-
- function beContent() { }
-
- function getSearchForm() {
- $entities = func_get_args();
-
- if (!isset($_REQUEST['page'])) {
- $_REQUEST['page'] = 0;
- }
-
- switch ($_REQUEST['page']) {
- case 0: /* FORM EMISSION - This should be done on a presentation layer! */
-
- $content = "<div id=\"search\"> <form name=\"search\">\n";
- $content .= "<input type=\"hidden\" name=\"page\" value=\"1\">\n";
- $content .= "<input type=\"hidden\" name=\"action\" value=\"search\">\n";
-
- $content .= "<table>\n";
- $content .= "<tr>\n";
- $content .= "<td>Free Text </td>\n";
- #$content .= "<td><input type=\"text\" name=\"text\" size=\"30\" onkeyup=\"searchRequest();\"></td>\n";
- $content .= "<td><input type=\"text\" name=\"text\" size=\"30\" ></td>\n";
- $content .= "</tr>\n";
-
- foreach($entities as $k => $entity) {
- if (is_array($entity->searchFields['CHECK'])) {
-
- foreach($entity->searchFields['CHECK'] as $index => $field) {
-
- $result[$entity->name][$field] = aux::getResult("SELECT DISTINCT {$field} FROM {$entity->name} WHERE {$field} <> '' ORDER BY {$field}");
-
- $label[$field] = $entity->searchFields['CHECKLABEL'][$index];
- }
- }
- }
-
- $finalArray = array();
- $field = "";
- if (is_array($result)) {
- foreach($result as $entity => $v1) {
- foreach($v1 as $field => $v2) {
- foreach($v2 as $v3) {
-
- foreach($v3 as $k => $v) {
-
- if ($k != $field) {
- $field = $k;
- }
- $finalArray[$field] = aux::add_distinct($finalArray[$field],$v);
- }
- }
- }
- }
- }
-
- $field = "";
- foreach($finalArray as $k => $item) {
- $content .= "<tr>\n";
- if ($k != $field) {
- $content .= "<td valign=\"top\">{$label[$k]}</td>\n";
- $field = $k;
- } else {
- $content .= "<td></td>\n";
- }
- $content .= "<td>\n";
- $sorted = $item;
- asort($sorted);
-
- $content .= "\n\n<!-- BEGIN -->\n<table width=\"100%\">\n";
- $checkcount = 0;
- foreach($sorted as $k => $v) {
- if (($checkcount % 2) == 0) {
- $content .= "<tr>\n";
- $content .= "<td width=\"50%\"><input type=\"checkbox\" name=\"{$field}_{$v}\" value=\"{$v}\"> {$v}</td>\n";
- } else {
- $content .= "<td width=\"50%\"><input type=\"checkbox\" name=\"{$field}_{$v}\" value=\"{$v}\"> {$v}</td>\n";
- $content .= "</tr>\n";
- }
- $checkcount++;
- }
-
- if (($checkcount % 2) == 0) {
- $content .= "<td></td>\n";
- $content .= "</tr>\n";
- }
-
- $content .= "</table>\n\n<!-- END -->\n\n";
- $content .= "</td>\n";
- $content .= "</tr>\n";
- }
-
- foreach($entities as $k => $entity) {
-
- if (is_array($entity->searchRelations)) {
- foreach($entity->searchRelations as $index => $relation) {
-
-
- $relations[$relation->name] = $relation;
-
- if ($relation->entity_1->name == $entity->name) {
- $data = $relation->entity_2->getReference();
-
- } else {
- $data = $relation->entity_1->getReference();
-
- }
- $name = $relation->name;
-
- $content .= "<tr><td valign=\"top\">{$entity->searchFields['RELATIONLABEL'][$index]}</td><td>\n";
- $content .= "<table width=\"100%\">\n";
- $checkcount = 0;
- foreach($data as $v) {
-
- if (($checkcount % 2) == 0) {
- $content .= "<tr>\n";
-
- $content .= "<td width=\"50%\"><input type=\"checkbox\" name=\"{$name}_{$v['value']}\" value=\"{$v['value']}\"> {$v['text']}</td>\n";
-
- } else {
- $content .= "<td width=\"50%\"><input type=\"checkbox\" name=\"{$name}_{$v['value']}\" value=\"{$v['value']}\"> {$v['text']}</td>\n";
- $content .= "</tr>";
-
- }
-
- $checkcount++;
- }
- if (($checkcount % 2) == 0) {
- $content .= "<td></td>\n";
- $content .= "</tr>";
- }
-
- $content .= "</table>\n";
- $content .= "</td></tr>\n";
-
-
-
- }
- }
- }
-
-
- $content .= "<tr><td></td>\n";
- $content .= "<td><input type=\"submit\" value=\"Show Result\"></td>\n";
- $content .= "</tr>\n</table>\n</form></div>\n\n";
-
- return $content;
-
- break;
- case 1:
-
- // ******************
-
- foreach($entities as $entity) {
-
-
-
- unset($sub_cond);
-
- $fields = "{$entity->name}.{$entity->fields[0]['name']} AS {$entity->name}_{$entity->fields[0]['name']}";
- if (is_array($entity->searchFields['TEXT'])) {
- foreach($entity->searchFields['TEXT'] as $field) {
- $fields .= ", {$entity->name}.{$field} AS {$entity->name}_{$field}";
- }
- }
- if (is_array($entity->searchFields['CHECK'])) {
- foreach($entity->searchFields['CHECK'] as $field) {
- $fields .= ", {$entity->name}.{$field} AS {$entity->name}_{$field}";
- }
- }
-
- if (is_array($entity->searchFields['TEXT'])) {
- if ($entity->owner) {
- $fields .= ", username, creation";
- }
- }
-
-
- $query = "SELECT $fields FROM {$entity->name} ";
-
- $left = "";
- if (count($entity->searchRelations) > 0) {
- foreach($entity->searchRelations as $relation) {
- $left .= "LEFT JOIN {$relation->name} ON {$relation->name}.id_{$entity->name} = {$entity->name}.{$entity->fields[0]['name']} ";
- }
- }
-
-
-
- if ($_REQUEST['text'] != "") {
- $condition = "";
- if (count($entity->searchFields['TEXT']) > 0) {
- foreach($entity->searchFields['TEXT'] as $field) {
- $condition .= aux::first_comma("{$entity->name} cond_1", " OR ")."{$entity->name}.{$field} LIKE '%{$_REQUEST['text']}%'";
- }
-
- }
- if ($condition != "") {
- $sub_cond[] = $condition;
- }
- }
- $condition = "";
- if (count($entity->searchFields['CHECK']) > 0) {
- foreach($entity->searchFields['CHECK'] as $field) {
-
- foreach($_REQUEST as $element => $value) {
- if (ereg($field, $element)) {
- $condition .= aux::first_comma("{$entity->name} cond_2", " OR ")."{$entity->name}.{$field} = '{$value}'";
- }
- }
- }
-
- }
-
- if ($condition != "") {
- $sub_cond[] = $condition;
- }
-
- if (count($entity->searchRelations) > 0) {
-
- foreach($entity->searchRelations as $relation) {
- $condition = "";
- foreach($_REQUEST as $element => $value) {
- if (ereg($relation->name, $element)) {
- $condition .= aux::first_comma($relation->name, " OR ")."{$relation->name}.id_{$entity->name} = '{$value}'";
- }
- }
- if ($condition != "") {
- $sub_cond[] = $condition;
- $query .= $left;
- }
- }
- }
- if (count($sub_cond) > 0) {
- $query .= " WHERE ";
- foreach($sub_cond as $condition) {
- $query .= aux::first_comma("{$entity->name} WHERE", " AND ")."({$condition})";
- }
- }
-
-
- return $query;
-
- }
-
- break;
- }
- }
-
- function search() {
-
- $entities = func_get_args();
-
- $text = $_REQUEST['text'];
- $_REQUEST['action'] = "search";
- $_REQUEST['page'] = 1;
-
- $empty = true;
- $skin = new Skinlet("search");
-
- foreach($entities as $entity) {
-
- if (is_array($entity->searchFields)) {
-
- $data = aux::getResult($GLOBALS['becontent']->getsearchform($entity));
-
- if (count($data) > 0) {
-
- $empty = false;
- foreach($data as $item) {
-
- $head = "";
-
- if (is_array($entity->searchHead)) {
- foreach($entity->searchHead as $field) {
- if (!$entity->existsField($field)) {
-
- $head .= " ".$item[$entity->name."_".$field."_".$_SESSION['language']];
- } else {
- $head .= " ".$item[$entity->name."_".$field];
- }
-
-
- }
-
- $skin->setContent("handler", $entity->searchHandler);
- $skin->setContent("table", $entity->name);
- $skin->setContent("key", $entity->fields[0]['name']);
- $skin->setContent("value", $item["{$entity->name}_{$entity->fields[0]['name']}"]);
- $skin->setContent("title", $head);
- }
-
- $body = "";
-
- if (is_array($entity->searchBody)) {
- foreach($entity->searchBody as $field) {
-
- if (!$entity->existsField($field)) {
- $body .= " ".$item[$entity->name."_".$field."_".$_SESSION['language']];
- } else {
- $body .= " ".$item[$entity->name."_".$field];
- }
-
- $body .= "<br />";
-
- }
- $skin->setContent("body", $body);
- }
-
- if ($entity->owner) {
- $skin->setContent("date", "</p><p class=\"search-date\">".aux::lingual("Pubblicato","Published on", "")." ".aux::formatDate($item['creation'], EXTENDED));
- } else {
- $skin->setContent("date", "");
- }
- }
-
- }
- }
- }
-
- if ($empty) {
- $skin = new Skinlet("search_empty");
- $skin->setContent("text", $_REQUEST['text']);
- }
-
- return $skin->get();
-
- }
-
- function clearCache($mode = HTML_IMG) {
-
- $dh = opendir($GLOBALS['config']['cache_folder']);
-
- while (false !== ($file = readdir($dh))) {
- if (($file != ".") and ($file != "..")) {
-
- switch($mode) {
- case HTML:
- if (ereg("\.html$", $file)) {
- unlink("{$GLOBALS['config']['cache_folder']}/{$file}");
- }
- break;
- case IMG:
- if (ereg("\.jpg$", $file)) {
- unlink("{$GLOBALS['config']['cache_folder']}/{$file}");
- }
- break;
- case HTML_IMG:
- if ((ereg("\.html$", $file)) or (ereg("\.jpg$", $file))) {
- unlink("{$GLOBALS['config']['cache_folder']}/{$file}");
- }
- break;
-
-
- }
-
-
- }
- }
-
- closedir($dh);
-
-
-
- }
-
-
- }
-
- $becontent = new beContent();
-
-
-
- /**
- * Class DB - manages db connections.
- *
- */
- Class DB {
- /**
- * Server Hostname or IP.
- *
- * @var string
- */
- var $host;
-
- /**
- * DB name.
- *
- * @var string
- */
- var $name;
-
- /**
- * DB user.
- *
- * @var string
- */
- var $user;
-
- /**
- * DB password.
- *
- * @var unknown_type
- */
- var $pass;
-
- /**
- * Tables name.
- *
- * @var array
- */
- var $tables = array();
- var $fields = array();
- var $files;
- var $entities;
-
-
-
- function DB($host,$name,$user,$pass) {
- $this->host = $host;
- $this->name = $name;
- $this->user = $user;
- $this->pass = $pass;
-
- $connection = mysql_pconnect($this->host,$this->user,$this->pass, MYSQL_CLIENT_COMPRESS);
-
- if ($connection) {
- $database = $connection;
- if (mysql_select_db($this->name)) {
- $dbms_database_open = true;
- } else {
- echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_OPEN)." {$this->name}";
- exit;
- }
- } else {
- echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_CONNECTION)." {$this->name}";
- exit;
- }
-
- $result = mysql_list_tables($this->name);
-
- while ($row = mysql_fetch_row($result)) {
- $this->tables[] = strtolower($row[0]);
-
- /*
- $oid = mysql_query("SHOW COLUMNS
- FROM {$row[0]}");
- if (!$oid){
- echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
- exit;
- }
-
- do {
- $data = mysql_fetch_assoc($oid);
- if ($data) {
-
- $this->fields[$row[0]][$data['Field']] = true;
- }
- } while ($data);
- */
- }
-
- }
-
- /**
- * Returns an Entity from a given name.
- *
- * @param string $name
- * @return Entity
- */
- function getEntityByName($name) {
- $result = false;
- $i = 0;
- while ((!$result) and ($i<count($GLOBALS['becontent']->entities))) {
- if ($GLOBALS['becontent']->entities[$i]->name == $name) {
- $result = $GLOBALS['becontent']->entities[$i];
- }
- $i++;
- }
- return $result;
-
- }
-
- /**
- * Checks if table exists from a given name.
- *
- * @param string $name
- * @return bool
- */
- function existsTable($name) {
- $result = false;
- for($i=0; $i<count($this->tables); $i++) {
- if ($this->tables[$i] == $name) {
- $result = true;
- }
- }
- return $result;
- }
-
- /**
- * Checks if a table contains a field.
- *
- * @param string $tableName
- * @param string $fieldName
- * @return integer
- */
- function existsField($tableName, $fieldName) {
- return $this->fields[$tableName][$fieldName];
- }
-
- /**
- * Init the skeleton application with main services.
- *
- * @return void
- *
- */
- function init() {
- $oid = mysql_query("SELECT * FROM {$GLOBALS['usersEntity']->name}");
-
- if (mysql_num_rows($oid) == 0) {
- $GLOBALS['usersEntity']->insertItem(array(
- "username" => $GLOBALS['config']['defaultuser']['username'],
- "password" => md5($GLOBALS['config']['defaultuser']['password']),
- "email" => $GLOBALS['config']['defaultuser']['email'],
- "name" => $GLOBALS['config']['defaultuser']['name'],
- "surname" => $GLOBALS['config']['defaultuser']['surname']
- )
- );
-
- $GLOBALS['groupsEntity']->insertItem("1", "Administrator", "Administration Group.");
- $GLOBALS['usersGroupsRelation']->insertItem($GLOBALS['co…
Large files files are truncated, but you can click here to view the full file