PageRenderTime 58ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/include/beContent.inc.php

http://becontent.googlecode.com/
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

  1. <?php
  2. /**
  3. * @copyright
  4. This file is part of beContent.
  5. Foobar is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. Foobar is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with beContent. If not, see <http://www.gnu.org/licenses/>.
  15. http://www.becontent.org
  16. @todo
  17. 0. instead of checking each time whether all the entities have been
  18. created, this functionality can be included in a configuration wizard
  19. to be executed each time the designer wishes
  20. 1. it can be important to have besides a SelectFromReference a link to the
  21. script to enter a new item into the referenced entity - this may require
  22. a refactoring with a unique script/controller for all the forms
  23. Features:
  24. *******
  25. * 25-01-2009
  26. - Skin caching management implemented, different policies have been included with a site-wide
  27. configuration
  28. * 24-01-2009
  29. - UPDATE FILE fix
  30. * 07-01-2009
  31. - TINY MCE upgrade (Version: 3.2.1.1)
  32. - Spellchecker plugin added
  33. requirements : see http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/spellchecker
  34. * 05-01-2009
  35. - Backoffice graphics has been re-designed.
  36. - Pager bugs fixes
  37. - Form javascript include bug solved
  38. * 03-01-2009
  39. - The frame-private template for the private Skin has been simplified, no more javascript code or ad-hoc inclusions are required.
  40. * 02-01-2009
  41. - 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
  42. 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
  43. function aux::decode_name is unneeded
  44. [...] pleanty of release notes are missing here.
  45. * 23-10-2007
  46. - $refferred removed among the instance variabile of the class Entity
  47. * 04-07-2007
  48. - hierarchicalPosition has been added, it is a Position widget which filters elements according
  49. to a 1-n relation
  50. - hierarchicalPosition has been enhanced to work also with self references, ie. 1-n auto
  51. relations, which makes it very useful to be used to build hierarchical menu.
  52. * 01-06-2007
  53. - some Notice and Warning have been fixed, for instance
  54. Notice: Use of undefined constant table - assumed 'table' in C:\Users\Alfonso\Documents\Documenti\Sviluppo\conferences\ASE2008\include\beContent.inc.php on line 998
  55. Notice: Use of undefined constant field - assumed 'field' in C:\Users\Alfonso\Documents\Documenti\Sviluppo\conferences\ASE2008\include\beContent.inc.php on line 999
  56. * 03-03-2007
  57. - a number of small fixes
  58. - the NO_DELETE did not work on page 2 for the update, it has been fixed.
  59. * 10-02-2007
  60. - a generic download utility for all entities containing a FILE field, it is used also in the
  61. editItem.
  62. * 03-02-2007
  63. - the referential integrity now takes into account also the entities with the WITH_OWNER
  64. property
  65. - the position widget has been fixed (in case of empty entity was having an item with a blank
  66. string)
  67. * 13-12-2006
  68. - the entities Entity has now two foreign keys to manage Moderator and ExpressPublish Groups
  69. - it is possible to specify multiple foreign keys referring to the same table to
  70. - the referential integrity is also validate for multiple foreign keys
  71. * 11-12-2006
  72. - the built-in reporting has been updated to list only the item which belongs to the user in the
  73. session, for those entities which are not WITH_OWNER just lists all the items
  74. - the reload check has been fixed
  75. * 10-12-2006
  76. - the dataFilering is working with the bootstrapped version of the user/group/service management
  77. - the authentication is completely working now with
  78. . authentication
  79. . service-based authorization
  80. . item-based data filtering
  81. * 03-08-2006
  82. - the relation class constructor has now an additional parameters for explicitly giving name to
  83. the corresponding tables
  84. * 02-08-2006
  85. - htmlentities/addslashes/stripslashes on dataentry, this has problems because when editing with the Editor
  86. the htmlentities function should not be applied,
  87. * 27.07.2006
  88. - WITH_OWNER timestamp is now in the YYYYMMDDHHmm format, a new LONGDATE type has been
  89. added but only internally used in combination with WITH_OWNER
  90. - aspect oriented code weaving, each stage (addItem: emitForm, Insertion - editItem:
  91. Selection, formFeed, Update, Deletion) have now
  92. - manage the "none" message in the file upload by means of the messaging systems
  93. * 24.07.2006
  94. - delete transactions include now also the deletion
  95. over the n-m relations
  96. * 23.07.2006
  97. - Multiple N-M relation transactions
  98. * Previously
  99. - Entities definition
  100. - N-M, 1-N relation definition
  101. - Insert Transaction
  102. - Edit Transation
  103. - Deletion Transaction with Integrity Check
  104. */
  105. #VARIOUS
  106. define('HTML', "HTML");
  107. define('IMG', "IMG");
  108. define('HTML_IMG', "HTML_IMG");
  109. define('AJAX', 'ajax');
  110. #XMLCHARS
  111. define('MODE1','MODE1');
  112. define('MODE2','MODE2');
  113. define('MODE3','MODE3');
  114. #Rss Mod
  115. define('MOD1','MOD1');
  116. define('MOD2','MOD2');
  117. define('MOD3','MOD3');
  118. # OPERATING SYSTEMS
  119. define('WINDOWS', "WINDOWS");
  120. define('LINUX', "LINUX");
  121. define('MACOS', "MACOS");
  122. #require_once "Mail.php";
  123. define('ADD',"add");
  124. define('EDIT',"edit");
  125. define('DELETE', "delete");
  126. define('NO_DELETE', true);
  127. define('ALL',"ALL");
  128. define('NO_ARG',"NO_ARG");
  129. /* Relation orientation */
  130. define('LEFT', "LEFT");
  131. define('RIGHT', "RIGHT");
  132. #define(MSG_SURE, "sure");
  133. define('MSG_UPDATED',"updated");
  134. define('AUTO', "AUTO");
  135. define('ITALIANO',"it");
  136. define('ENGLISH',"en");
  137. define('PRESENT', "PRESENT");
  138. define('ABSENT', "ABSENT");
  139. define('PRELOAD',"preload");
  140. define('MANDATORY',"yes");
  141. define('OPTIONAL', 'OPTIONAL');
  142. define('EQUAL',"equal");
  143. define('IMPLIES', "implies");
  144. define('LIMIT', "limit");
  145. define('NORMAL', 'NORMAL');
  146. define('COUNT', 'COUNT');
  147. define('ADVANCED', 'ADVANCED');
  148. define('PARSE', 'PARSE');
  149. /* DATE FORMATS */
  150. define('LETTERS', "LETTERS");
  151. define('SHORT_LETTERS', "SHORT_LETTERS");
  152. define('STANDARD', "STANDARD");
  153. define('STANDARD_PLUS', "STANDARD_PLUS");
  154. define('EXTENDED', "EXTENDED");
  155. define('EXTENDED_PLUS', "EXTENDED_PLUS");
  156. define('TIME', 'TIME');
  157. define('YEAR', 'YEAR');
  158. /* BASIC DATATYPES */
  159. define('VARCHAR','VARCHAR');
  160. define('HIDDEN', 'HIDDEN');
  161. define('TEXT','TEXT');
  162. define('FILE','FILE');
  163. define('FILE2FOLDER', 'FILE2FOLDER');
  164. define('IMAGE', 'IMAGE');
  165. define('INT','INT');
  166. define('STANDARD_PRIMARY_KEY_TYPE', 'INT UNSIGNED AUTO_INCREMENT');
  167. define('DATE','DATE');
  168. define('LONGDATE', 'LONGDATE');
  169. define('POSITION','POSITION');
  170. define('PASSWORD','PASSWORD');
  171. define('COLOR', 'COLOR');
  172. define('CHECKBOX', 'CHECKBOX');
  173. define('RELATION_MANAGER', 'RELATION MANAGER');
  174. /* WIDGET TYPES */
  175. define('SELECT_FROM_REFERENCE', 'selectFromReference');
  176. define('RADIO_FROM_REFERENCE', 'radioFromReference');
  177. /* to be completed */
  178. define('WITH_OWNER','WITH_OWNER');
  179. define('BY_POSITION','BY_POSITION');
  180. define('MD5', 'MD5');
  181. define('POST','POST');
  182. define('GET','GET');
  183. /* NOTIFY MESSAGES */
  184. define('NOTIFY_ITEM_ADDED','801');
  185. define('NOTIFY_ITEM_UPDATED','802');
  186. define('NOTIFY_ITEM_DELETED','803');
  187. define('NOTIFY_ITEM_INTEGRITY_VIOLATION','804');
  188. /* FILE UPLOAD MESSAGES */
  189. define('MSG_REPORT_EMPTY', '501');
  190. define('MSG_FILE_NONE', '601');
  191. define('MSG_FILE_DELETE', '602');
  192. /* ERROR MESSAGES */
  193. define('MSG_ERROR_DATABASE_GENERIC','900');
  194. define('MSG_ERROR_DATABASE_OPEN','901');
  195. define('MSG_ERROR_DATABASE_CONNECTION','902');
  196. define('MSG_ERROR_DATABASE_TABLE','903');
  197. define('MSG_ERROR_DATABASE_QUERY','904');
  198. define('MSG_ERROR_DATABASE_DUPLICATE_KEY','905');
  199. define('MSG_ERROR_DATABASE_RELOAD','906');
  200. define('MSG_ERROR_DATABASE_PRESENTATION','907');
  201. define('MSG_ERROR_UNKNOWN_ENTITY','908');
  202. define('MSG_ERROR_TRIGGERS','909');
  203. define('MSG_ERROR_RELATION_MANAGER','910');
  204. define('MSG_ERROR_DATABASE_RELATION_INSERT','911');
  205. define('MSG_ERROR_SESSION','912');
  206. define('MSG_ERROR_DATABASE_DELETION','913');
  207. define('MSG_ERROR_DATABASE_BOOTSTRAP','914');
  208. define('MSG_ERROR_DATABASE_INIT', '915');
  209. /* JAVASCRIPT MESSAGES */
  210. define('WARNING', '000');
  211. define('MSG_JS_INSERT','701');
  212. define('MSG_JS_SURE','702');
  213. define('MSG_JS_SELECT','703');
  214. define('MSG_JS_MODERATION','704');
  215. define('MSG_JS_RADIO', '705');
  216. define('MSG_JS_RELATIONMANAGER', '706');
  217. define('MSG_JS_IMPLIES', '707');
  218. define('MSG_JS_EXTENSION', '708');
  219. define('MSG_JS_INSERT_TIME', '709');
  220. /* BUTTON LABELS */
  221. define('BUTTON_ACCEPT','1001');
  222. define('BUTTON_REFUSE','1002');
  223. define('BUTTON_ADD', '1003');
  224. define('BUTTON_EDIT', '1004');
  225. define('BUTTON_DELETE', '1005');
  226. define('FIELDSET', '1006');
  227. define('MODERATION_ACCEPT','1011');
  228. define('MODERATION_REFUSE','1012');
  229. define('MODERATION_EXPIRED','1013');
  230. /* RSS MODALITY */
  231. define('MODALITY1','1101');
  232. define('MODALITY2','1102');
  233. define('MODALITY3','1103');
  234. define('RSS_MODALITY1_MSG', '1104');
  235. define('RSS_MODALITY2_MSG', '1105');
  236. /* SYSTEM USER GROUPS */
  237. define('ADMIN', 1);
  238. /* VARIOUS */
  239. define('OMIT_LOGGED_USER', 'OMIT_LOGGED_USER');
  240. $RESERVEDWORDS = Array('page');
  241. /**
  242. * Class Widget
  243. *
  244. */
  245. Class Widget {
  246. var
  247. $name,
  248. $label,
  249. $mandatory;
  250. function Widget($name, $label, $mandatory = "no") {
  251. $this->name = $name;
  252. $this->label = $label;
  253. $this->mandatory = $mandatory;
  254. }
  255. function display() {
  256. return "Widget {$this->name} - no display admitted!";
  257. }
  258. }
  259. /**
  260. * Class Text
  261. *
  262. */
  263. Class Text extends Widget {
  264. var
  265. $size,
  266. $maxlength;
  267. function Text($name,
  268. $label,
  269. $size = "20",
  270. $mandatory = "off",
  271. $maxlength = "") {
  272. Widget::Widget($name,$label,$mandatory);
  273. $this->size = $size;
  274. $this->maxlength = $maxlength;
  275. }
  276. function display() {}
  277. }
  278. /**
  279. * Message - coded message
  280. *
  281. */
  282. Class Message {
  283. var $messages = Array( // ITALIAN
  284. "it" => Array(
  285. "000" => "Attenzione",
  286. "001" => "Sei Sicuro ?",
  287. "501" => "Non ci sono elementi",
  288. "601" => "vuoto",
  289. "602" => "rimuovi",
  290. "701" => "Attenzione: inserire {label} !",
  291. "702" => "Sei Sicura/o ?",
  292. "703" => "Attenzione: selezionare {label} !",
  293. "704" => "Indicare il motivo del rigetto della pubblicazione !",
  294. "705" => "Attenzione: selezionare {label} !",
  295. "706" => "Attenzione: selezionare almeno un {label} !",
  296. "707" => "Attenzione: inserire o selezionare {label} !",
  297. "708" => "Attenzione: tipo di file errato per {label} !",
  298. "709" => "Attenzione: indicate anche ora e minuti per {label} !",
  299. "801" => "L'inserimento � stato effettuato con successo !",
  300. "802" => "L'aggiornamento � stato effettuato con successo !",
  301. "803" => "La cancellazione � avvenuta con successo !",
  302. "804" => "L'elemento selezionato per la cancellazione non pu� essere rimosso perch� in uso.",
  303. "900" => "Database: Errore Generico ",
  304. "901" => "Database: Error in opening database ",
  305. "902" => "Database: Error in opening connection to database ",
  306. "903" => "Database: Error in creating table ",
  307. "904" => "Database: Error in querying ",
  308. "905" => "Attenzione: la chiave risulta gi� presente, modifica per procedere!",
  309. "906" => "Attenzione: l'inserimento � annullato perch� la transazione � gi� avvenuta!",
  310. "907" => "Attenzione: errore in interrogazione query, probabilmente non � stata definita una presentazione (setPresentation) per la tabella ",
  311. "908" => "Database: entit� specificata nella relazione inesistente",
  312. "909" => "Attenzione: solo form relative a Relazioni possono essere messe in cascata ",
  313. "910" => "Attenzione: non � possibile adottare un RelationManager per questo tipo di form ",
  314. "911" => "Attenzione: si � verificato un errore di inserimento nella relazione ",
  315. "912" => "Attenzione: operazione non ammissibile, sessione non aperta ",
  316. "913" => "Attenzione: errore di cancellazione ",
  317. "914" => "Attezione: il sistema non pu� essere inizializzato ",
  318. "915" => "Attezione: errore di tipi nell'inizializzazione ",
  319. "1001" => "Pubblica",
  320. "1002" => "Rifiuta",
  321. "1003" => "Aggiungi",
  322. "1004" => "Modifica",
  323. "1005" => "Rimuovi",
  324. "1006" => "Tue/Tuoi",
  325. "1011" => "<b>Grazie!</b><br><br>L'informazione � stata <u>pubblicata</u> e l'autore verr� informato!",
  326. "1012" => "<b>Grazie!</b><br><br>L'informazione � stata <u>rifiutata</u> e l'autore verr� informato!",
  327. "1013" => "<b>Attenzione!</b><br><br>La moderazione � stata gi� processata da un altro Editor!",
  328. "1101" => "Sempre",
  329. "1102" => "Batch Selettivo",
  330. "1103" => "Selettivo",
  331. "1104" => "RSS enabled",
  332. "1105" => "RSS enabled"
  333. ),
  334. "en" => Array( // ENGLISH
  335. "000" => "Warning",
  336. "001" => "Are you sure ?",
  337. "501" => "There are no items!",
  338. "601" => "none",
  339. "602" => "delete",
  340. "701" => "Warning: please insert {label} !",
  341. "702" => "Are you sure ?",
  342. "703" => "Warning: please select {label} !",
  343. "704" => "Please specify to the author why this item is rejected !",
  344. "705" => "Warning: please select {label} !",
  345. "706" => "Warning: please select at least one {label} !",
  346. "707" => "Warning: please enter or select {label} !",
  347. "708" => "Warning: the select file type for {label} is not correct !",
  348. "709" => "Warning: please enter also the time for {label} !",
  349. "801" => "The item has been correctly added!",
  350. "802" => "The item has been correctly updated!",
  351. "803" => "The item has been removed!",
  352. "804" => "The deletion cannot take place, because the item you selected is still in use!",
  353. "900" => "Database: Generic Error ",
  354. "901" => "Database: Error in opening database ",
  355. "902" => "Database: Error in opening connection to database ",
  356. "903" => "Database: Error in creating table ",
  357. "904" => "Database: Error in querying ",
  358. "905" => "Warning: duplicate key, enter another value to proceed!",
  359. "906" => "Warning: transaction cannot take place since already executed!",
  360. "907" => "Warning: error in querying, likely a presentation has been not defined for table ",
  361. "908" => "Database: unknown entity in the specified relation",
  362. "909" => "Warning: only Relation-based form can be in cascade triggered ",
  363. "910" => "Warning: a RelationManager object cannot be used for this form ",
  364. "911" => "Warning: an error occourred while inserting tuples into the relation ",
  365. "912" => "Warning: the operation is not allowed as the session has been not created ",
  366. "913" => "Warning: error in deletion ",
  367. "914" => "Warning: the system cannot be bootstrapped ",
  368. "915" => "Warning: likely a datatype error occurred in the initialization, eg. INT requires 0 valued field if bank is intended ",
  369. "1001" => "Publish",
  370. "1002" => "Reject",
  371. "1002" => "Rifiuta",
  372. "1003" => "Add",
  373. "1004" => "Save",
  374. "1005" => "Delete",
  375. "1006" => "Your",
  376. "1011" => "<b>Thank you!</b><br><br>The content has been <u>published</u>, the author is going to be informed!",
  377. "1012" => "<b>Thank you!</b><br><br>The content has been <u>rejected</u> and the author is going to be informed!",
  378. "1013" => "<b>Warning!</b><br><br>The content has been already validated by another Editor!",
  379. "1101" => "Sempre",
  380. "1102" => "Batch Selettivo",
  381. "1103" => "Selettivo",
  382. "1104" => "RSS enabled",
  383. "1105" => "RSS enabled"
  384. )
  385. ),
  386. $language = "it";
  387. /**
  388. * Constructor.
  389. *
  390. * @param string $language
  391. * @return Message
  392. */
  393. function Message($language) {
  394. $this->language = $language;
  395. }
  396. /**
  397. * Returns message in the selected language.
  398. *
  399. * @param costant $code defined in the class.
  400. * @param array $data placeholder replacement in the message
  401. * @return string
  402. */
  403. function getMessage($code, $data = "") {
  404. $GLOBALS['count']++;
  405. if ($GLOBALS['count'] == 2) {
  406. #echo "code: $code<br>";
  407. #echo "data: $data<hr>";
  408. }
  409. if (is_array($data)) {
  410. $buffer = $this->messages[$this->language][$code];
  411. if ( (count($data) > 0) && ($data != "") ) {
  412. foreach($data as $key => $value) {
  413. if (is_string($value)) {
  414. $buffer = str_replace('\{'.$key.'\}', $value, $buffer);
  415. }
  416. }
  417. } // if
  418. return $buffer;
  419. } else {
  420. return aux::xmlchars($this->messages[$this->language][$code]);
  421. }
  422. }
  423. } // Class Message
  424. $count = 0;
  425. /**
  426. * Class aux - encodes the xml characters
  427. * @static
  428. */
  429. Class aux {
  430. /**
  431. * Encrypt-decrypt the input message.
  432. *
  433. * @param string $Str_Message to decrypt
  434. * @return encrypted decrypted message
  435. */
  436. function encrypt_decrypt($Str_Message) {
  437. $Len_Str_Message = strlen($Str_Message);
  438. $Str_Encrypted_Message = "";
  439. for ($Position=0; $Position<$Len_Str_Message; $Position++) {
  440. $Key_To_Use = ( ($Len_Str_Message + $Position) + 1 ); // (+5 or *3 or ^2)
  441. $Key_To_Use = ( 255 + $Key_To_Use ) % 255;
  442. $Byte_To_Be_Encrypted = SUBSTR($Str_Message, $Position, 1);
  443. $Ascii_Num_Byte_To_Encrypt = ORD($Byte_To_Be_Encrypted);
  444. $Xored_Byte = $Ascii_Num_Byte_To_Encrypt ^ $Key_To_Use; //xor operation
  445. $Encrypted_Byte = CHR($Xored_Byte);
  446. $Str_Encrypted_Message .= $Encrypted_Byte;
  447. }
  448. return $Str_Encrypted_Message;
  449. }
  450. /**
  451. * Encrypt the string message.
  452. *
  453. * @param string $message to encrypt
  454. * @return string urlencoded message
  455. */
  456. function encrypt($message) {
  457. return urlencode(aux::encrypt_decrypt($message));
  458. }
  459. /**
  460. * Decrypt the string message.
  461. *
  462. * @param string $message to decrypt
  463. * @return string urlencoded message
  464. */
  465. function decrypt($message) {
  466. return aux::encrypt_decrypt(urldecode($message));
  467. }
  468. /**
  469. * Escapes string from quotes (using mysql_escape_string($str)).
  470. *
  471. * @param string $string string to escape
  472. * @return string
  473. */
  474. function escape_string($string) {
  475. return mysql_escape_string($string);
  476. }
  477. /**
  478. * Changes the @ with an image that seems.
  479. *
  480. * @param string $email email address
  481. * @param string $pars['mode'] substitutes <img src='img/beContent/chiocciola-$pars['mode'].gif'
  482. * @return string
  483. */
  484. function email($email, $pars) {
  485. #$email = ereg_replace("@", "<span class=\"email\">[at]</span>", $email);
  486. #$email = ereg_replace("\.", "<span class=\"email\">[dot]</span>", $email);
  487. if (!isset($pars['mode'])) {
  488. $email = ereg_replace("@", "<img style=\"margin-bottom: -2px;\"src=\"img/beContent/chiocciola.gif\" alt=\"@\">", $email);
  489. } else {
  490. $email = ereg_replace("@", "<img style=\"margin-bottom: -2px;\"src=\"img/beContent/chiocciola-{$pars['mode']}.gif\" alt=\"@\">", $email);
  491. }
  492. return "{$email}";
  493. }
  494. /**
  495. * Encodes name in MD5.
  496. *
  497. * @param string $name to encode
  498. * @return string name encoded
  499. */
  500. function encode_name($name) {
  501. return md5($name);
  502. }
  503. /**
  504. * Return name as it is.
  505. *
  506. * @param string $name name
  507. * @return name
  508. */
  509. function decode_name($name) {
  510. return $name;
  511. }
  512. /**
  513. * This function is useless converts telphone number
  514. * from 0039 zero or more spaces 0862 zero or more spaces in
  515. * +39 0862[[:space:]]
  516. *
  517. * @param string $phone phone number
  518. * @return string
  519. */
  520. function phone($phone) {
  521. $phone = ereg_replace("^0039[[:space:]]*0862[[:space:]]*", "+39 0862 ", $phone);
  522. return $phone;
  523. }
  524. /**
  525. * Converts the characters in html compatibles.
  526. * MODE1:
  527. * & -> &amp;
  528. * < -> &lt; > -> &gt;
  529. * " -> &quot; ' -> &#39;
  530. * MODE 2: uses htmlentities PHP function
  531. * MODE 3: Uses th htmlentities translation table
  532. *
  533. * @param string $str string to convert
  534. * @param constant $mode MODE1,MODE2...
  535. * @return string
  536. */
  537. function xmlchars($str, $mode = MODE1) {
  538. switch($mode) {
  539. case MODE1:
  540. $str = str_replace('&', '&amp;', $str);
  541. $str = str_replace('<', '&lt;', $str);
  542. $str = str_replace('>', '&gt;', $str);
  543. $str = str_replace('"', '&quot;', $str);
  544. $str = str_replace("'", '&#39;', $str);
  545. break;
  546. case MODE2:
  547. $str = htmlentities($str);
  548. break;
  549. case MODE3:
  550. $trans = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
  551. $trans = array_flip($trans);
  552. $str = strtr($str, $trans);
  553. $str = preg_replace('/&#(d+);/me', "chr(\1)", $str);
  554. $str = preg_replace('/&#x([a-f0-9]+);/mei', "chr(0x\1)", $str);
  555. $trans = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES);
  556. foreach ($trans as $key => $value) {
  557. $trans[$key] = '&#'.ord($key).';';
  558. }
  559. $str = strtr($str, $trans);
  560. break;
  561. }
  562. return $str;
  563. }
  564. /**
  565. * Recognises parameters inside template files.
  566. *
  567. * @param string $parameters to recognise parName=parValue, ...
  568. * @return array parName->parValue
  569. */
  570. function parsePars($parameters) {
  571. $buffer = $parameters;
  572. do {
  573. $result = ereg("^([[:alnum:] \_]+)", $buffer, $token);
  574. if ($result) {
  575. $buffer = ereg_replace("^$token[1]", "", $buffer);
  576. $result2 = ereg("^=\"([[:alnum:]\.\_\% \-]*)\"", $buffer, $token2);
  577. if ($result2) {
  578. $buffer = ereg_replace("^=\"$token2[1]\"[[:space:] ]*", "", $buffer);
  579. $par[$token[1]] = $token2[1];
  580. }
  581. } // if
  582. } while ($result);
  583. return $par;
  584. }
  585. /**
  586. * Get a result array from a query.
  587. *
  588. * @param string $query SQL query
  589. * @param unknown_type $field
  590. * @return array
  591. */
  592. function getResultArray($query,$field){
  593. $data = aux::getResult($query);
  594. $i = 0;
  595. while ($data[$i]) {
  596. $result[] = $data[$i][$field];
  597. $i++;
  598. }
  599. return $result;
  600. }
  601. /**
  602. * Get a result from a query.
  603. *
  604. * @param string $query Sql query
  605. * @param constant $mode
  606. * @return array
  607. */
  608. function getResult($query, $mode = "NORMAL") {
  609. switch ($mode) {
  610. case ADVANCED:
  611. case PARSE:
  612. $finito = false;
  613. do {
  614. if (ereg("\[([[:alnum:]]*)\]", $query, $token)) {
  615. $query = ereg_replace("\[{$token[1]}\]", $_REQUEST[$token[1]], $query);
  616. } else {
  617. $finito = true;
  618. }
  619. } while (!$finito);
  620. break;
  621. default:
  622. break;
  623. }
  624. if ($mode == PARSE) {
  625. return $query;
  626. } else {
  627. $oid = mysql_query($query);
  628. if (!$oid) {
  629. echo mysql_error();
  630. echo "<hr>",$query; exit;
  631. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC);
  632. exit;
  633. }
  634. do {
  635. $data = mysql_fetch_assoc($oid);
  636. if ($data) {
  637. foreach ($data as $k=>$v) {
  638. if (is_string($data[$k])) {
  639. $data[$k] = stripslashes($v);
  640. }
  641. }
  642. $content[] = $data;
  643. }
  644. } while ($data);
  645. return $content;
  646. }
  647. }
  648. /**
  649. * Enter description here...
  650. *
  651. * @param unknown_type $arg
  652. * @param unknown_type $separator
  653. * @return unknown
  654. */
  655. function first_comma($arg, $separator) {
  656. global $comma;
  657. // if ((isset($comma[$arg])) && (!$comma[$arg])) {
  658. if (!isset($comma[$arg])) {
  659. $comma[$arg] = true;
  660. return "";
  661. } else {
  662. return $separator;
  663. }
  664. }
  665. /**
  666. * Sends mail.
  667. * (use php comand mail)
  668. *
  669. * @param string $to email address
  670. * @param string $subject subject of the email
  671. * @param string_type $message message of the email
  672. * @param string $from email address
  673. */
  674. function mail($to, $subject, $message, $from) {
  675. $signature = new Template("dtml/signature.mail");
  676. $message .= $signature->get();
  677. mail($to, $subject, $message, "From: {$from}");
  678. }
  679. /**
  680. * Returns the date of yesterday in format YYYY/MM/DD
  681. *
  682. * @return date YYYY/MM/DD
  683. */
  684. function yesterday() {
  685. $day = time() - (24 * 60 * 60);
  686. $strtime = strtotime(date('m/d/Y', $day));
  687. return strftime("%Y%m%d", $strtime);
  688. }
  689. /**
  690. * Function to format date.
  691. * format types:
  692. * RSS LETTERS SHORTLETTERS STANDARD STANDARD_PLUS BLOG EXTENDED EXTENDED_PLUS TIME YEAR
  693. *
  694. * @param YYYYDDMM $date
  695. * @param constant $format format type
  696. * @return string formatted date
  697. */
  698. function formatDate($date, $format = "") {
  699. switch ($format) {
  700. case RSS:
  701. ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
  702. $result = date("D, j M Y 06:00:00 +0100",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
  703. break;
  704. case LETTERS:
  705. ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
  706. $result = date("F jS Y",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
  707. break;
  708. case SHORT_LETTERS:
  709. ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
  710. $result = date("M j, Y",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
  711. break;
  712. case STANDARD:
  713. if ($date != "") {
  714. 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)) {
  715. $result = "{$token[3]}/{$token[2]}/{$token[1]}";
  716. } elseif (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
  717. $result = "{$token[3]}/{$token[2]}/{$token[1]}";
  718. }
  719. } else {
  720. $result = "";
  721. }
  722. break;
  723. case STANDARD_PLUS:
  724. if ($date != "") {
  725. 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);
  726. if (date("Ymd") == "{$token[1]}{$token[2]}{$token[3]}") {
  727. $result = aux::lingual("Oggi", "Today", "Oy");
  728. } else {
  729. $result = "{$token[3]}/{$token[2]}/{$token[1]}";
  730. }
  731. if ($token[4] != "") {
  732. $result .= " {$token[4]}:{$token[5]}";
  733. }
  734. } else {
  735. $result = "";
  736. }
  737. break;
  738. case BLOG: // calendar colouredsquare
  739. if ($date != "") {
  740. ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
  741. $date = date("jS M",mktime(0, 0, 0, $token[2], $token[3], $token[1]));
  742. $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>";
  743. } else {
  744. $result = "";
  745. }
  746. break;
  747. case EXTENDED:
  748. setlocale(LC_ALL, aux::getLocale($_SESSION['language']));
  749. 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)) {
  750. $day = "{$token[2]}/{$token[3]}/{$token[1]} {$token[4]}:{$token[5]}";
  751. $strtime = strtotime($day);
  752. $result = strftime("%A %d %B, %H:%M", $strtime);
  753. } else if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
  754. $day = "{$token[2]}/{$token[3]}/{$token[1]} 00:01";
  755. $strtime = strtotime($day);
  756. $result = strftime("%A %d %B", $strtime);
  757. }
  758. break;
  759. case EXTENDED_PLUS: // Thursday 01 January (locale)
  760. setlocale(LC_ALL, aux::getLocale($_SESSION['language']));
  761. 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)) {
  762. if ("{$token[2]}{$token[3]}{$token[1]}" == date("mdY")) {
  763. $result = "Oggi {$token[4]}:{$token[5]}";
  764. } else {
  765. $day = "{$token[2]}/{$token[3]}/{$token[1]} {$token[4]}:{$token[5]}";
  766. $strtime = strtotime($day);
  767. $result = strftime("%A %d %B, %H:%M", $strtime);
  768. }
  769. } else if (ereg("^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])$", $date, $token)) {
  770. if ("{$token[2]}{$token[3]}{$token[1]}" == date("mdY")) {
  771. $result = "Oggi";
  772. } else {
  773. $day = "{$token[2]}/{$token[3]}/{$token[1]} 00:01";
  774. $strtime = strtotime($day);
  775. $result = strftime("%A %d %B", $strtime);
  776. }
  777. }
  778. break;
  779. case TIME: // hh:mm
  780. $h = substr($date,8,2);
  781. $m = substr($date,10,2);
  782. return "{$h}:{$m}";
  783. break;
  784. case YEAR: // yyyy
  785. $y = substr($date,0,4);
  786. return $y;
  787. break;
  788. default: // mm.dd.yyyy
  789. ereg("([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])", $date, $token);
  790. $result = "{$token[3]}.{$token[2]}.{$token[1]}";
  791. break;
  792. }
  793. return $result;
  794. }
  795. /**
  796. * Return subtext of a text cutted at a given length.
  797. *
  798. * @param string $text text
  799. * @param integer $length length to cut
  800. * @return the new text cutted
  801. */
  802. function subtext($text, $length = 100) {
  803. if (strlen(strip_tags(html_entity_decode($text))) < $length) {
  804. $result = strip_tags(html_entity_decode($text));
  805. } else {
  806. $newtext = wordwrap(strip_tags(html_entity_decode($text)), $length, "<interrupt>");
  807. $pos = strpos($newtext, "<interrupt>");
  808. $result = substr($newtext, 0, $pos);
  809. }
  810. return $result;
  811. }
  812. /**
  813. * Strips slashes from a value.
  814. *
  815. * @param string $value to strip
  816. * @return value stripped
  817. */
  818. function quote_smart($value) {
  819. if (get_magic_quotes_gpc()) { // Stripslashes
  820. $value = stripslashes($value);
  821. }
  822. if (!is_numeric($value)) { // Quote if not integer
  823. $value = "'" . mysql_real_escape_string($value) . "'";
  824. }
  825. return $value;
  826. }
  827. /**
  828. * Makes an indentation of 4 * &nbsp; for level.
  829. *
  830. * @param integer $level level of indentation
  831. * @return indentation string
  832. */
  833. function mkIndent($level) {
  834. #echo "** {$level}<br>";
  835. $result = "";
  836. for($i=0; $i<$level; $i++) {
  837. $result .= "&nbsp;&nbsp;&nbsp;&nbsp;";
  838. }
  839. return $result;
  840. }
  841. /**
  842. * Finds a children of the parent recursively.
  843. *
  844. * @param unknown_type $parent
  845. * @param unknown_type $level
  846. */
  847. function FindChildren ($parent, $level) {
  848. global
  849. $flag,
  850. $data,
  851. $tree_text,
  852. $tree_value,
  853. $tree_level,
  854. $undef_flag;
  855. for ($i=0; $i<count($data); $i++) {
  856. if (($data[$i]['reference'] == $parent) and (!isset($flag[$i]))) {
  857. $tree_value[] = $data[$i]['value'];
  858. $tree_text [] = aux::mkIndent($level) . $data[$i]['text'];
  859. $tree_level[] = $level;
  860. $flag[$i] = true;
  861. aux::FindChildren($data[$i]['value'],$level+1);
  862. }
  863. }
  864. }
  865. /**
  866. * Merge two or more arrays without duplicates.
  867. *
  868. * @param array $arrays arrays
  869. * @return array merged
  870. */
  871. function array_merge($arrays) {
  872. $result = array();
  873. foreach($arrays as $array) {
  874. $result = array_merge(
  875. array_diff($result,$array),
  876. array_diff($array,$result),
  877. array_intersect($result,$array)
  878. );
  879. }
  880. return $result;
  881. }
  882. /**
  883. * Add an element in a array if not already exists.
  884. *
  885. * @param array $array container
  886. * @param element $element element to insert into
  887. * @return array with th new element
  888. */
  889. function add_distinct($array, $element) {
  890. if (!is_array($array)) {
  891. $array = array();
  892. }
  893. if (!in_array($element, $array)) {
  894. $array[] = $element;
  895. }
  896. return $array;
  897. }
  898. /**
  899. * This function provides ajax encoding.
  900. *
  901. * @param object $object object to encode
  902. * @return object encoded
  903. */
  904. function AjaxEncode($object) {
  905. $str = serialize($object);
  906. #$str = str_replace(array('\\', "'"), array("\\\\", "\\'"), $str);
  907. $str = preg_replace('#([\x00-\x08])#e', '"\x" . sprintf("%02x", ord("\1"))', $str);
  908. $str = preg_replace('#([\x0A-\x1F])#e', '"\x" . sprintf("%02x", ord("\1"))', $str);
  909. #$str = ereg_replace("\\x0d","",$str);
  910. #$str = ereg_replace("\\x02","",$str);
  911. #$str = ereg_replace("\\x01","",$str);
  912. #$str = ereg_replace("\\x12","",$str);
  913. #$str = ereg_replace("\\x0e","",$str);
  914. $str = ereg_replace("\\x0[0-9a-f]", "", $str);
  915. $str = ereg_replace("\\x1[0-9a-f]", "", $str);
  916. #Header("Content-type: text/plain");
  917. #echo stripslashes($str);exit;
  918. return $str;
  919. }
  920. /**
  921. * Returns item passed to function according with the session language.
  922. *
  923. * @param $item_it
  924. * @param $item_en
  925. * @param $item_es
  926. * @return item_sessionlanguage
  927. */
  928. function lingual($item_it, $item_en, $item_es = "") {
  929. $item = "item_{$_SESSION['language']}";
  930. return $$item;
  931. }
  932. /**
  933. * Returns locale string according with os in use.
  934. *
  935. * @param string $language
  936. * @return locale string
  937. */
  938. function getLocale($language) {
  939. $locale = array(
  940. WINDOWS => array("it" => "ita_ita", "en" => "eng_eng","es" => "esp_esp"),
  941. LINUX => array("it" => "it_IT", "en" => "en_UK", "es" => "es_ES")
  942. );
  943. return $locale[$GLOBALS['config']['os']][$language];
  944. }
  945. function refineQuery($query, $condition) {
  946. $queryToken['body'] = $query;
  947. if (ereg("(.*)(".sql_regcase("order by").".*)$", $queryToken['body'], $token)) {
  948. $queryToken['order_by'] = $token[2];
  949. $queryToken['body'] = $token[1];
  950. }
  951. if (ereg("(.*)(".sql_regcase("where").".*)$", $queryToken['body'], $token)) {
  952. $queryToken['where'] = $token[2];
  953. $queryToken['body'] = $token[1];
  954. }
  955. $query = $queryToken['body'];
  956. if ($queryToken['where'] == "") {
  957. if ($condition != "") {
  958. $query .= " WHERE {$condition} ";
  959. }
  960. } else {
  961. $query .= $queryToken['where']." AND {$condition} ";
  962. }
  963. $query .= $queryToken['order_by'];
  964. return $query;
  965. }
  966. function evaluate($str, $array) {
  967. do {
  968. $result = ereg("^.*\[(.*)\]", $str, $token);
  969. if ($result) {
  970. $buffer = $str;
  971. $str = ereg_replace("\[{$token[1]}\]", $array[$token[1]], $buffer);
  972. }
  973. } while ($result);
  974. return $str;
  975. }
  976. function seo_url($str) {
  977. $str = str_replace("?", "", $str);
  978. $str = str_replace(":", "", $str);
  979. $str = str_replace("/", "", $str);
  980. $str = str_replace("\\", "", $str);
  981. $str = str_replace("!", "", $str);
  982. $str = str_replace(".", "", $str);
  983. return str_replace(" ", "-", $str);
  984. }
  985. } // Class aux
  986. /**
  987. * Class - beContenPager
  988. *
  989. */
  990. Class beContentPager {
  991. var $itemTemplate;
  992. var $template;
  993. /**
  994. * Query.
  995. *
  996. * @var string
  997. */
  998. var $query;
  999. /**
  1000. * WHERE clause content.
  1001. *
  1002. * @var string
  1003. */
  1004. var $filter;
  1005. /**
  1006. * ORDER BY clause content.
  1007. *
  1008. * @var string
  1009. */
  1010. var $order;
  1011. /**
  1012. * Number of the page items.
  1013. *
  1014. * @var unknown_type
  1015. */
  1016. var $length;
  1017. /**
  1018. * Constructor.
  1019. *
  1020. * @param integer $length page items
  1021. * @return beContentPager
  1022. */
  1023. function beContentPager($length = 15) {
  1024. $this->itemTemplate = $template = "";
  1025. $this->query = "";
  1026. $this->length = $length;
  1027. }
  1028. /**
  1029. * Sets the query to perform.
  1030. *
  1031. * @param unknown_type $query
  1032. */
  1033. function setQuery($query) {
  1034. $this->query = $query;
  1035. }
  1036. /**
  1037. * Sets filter to pass to the query in WHERE clause.
  1038. *
  1039. * @param string $filter
  1040. * @example id=1 OR id=0
  1041. */
  1042. function setFilter($filter) {
  1043. $this->filter = $filter;
  1044. }
  1045. /**
  1046. * Sets order to pass to the query in ORDER clause.
  1047. * Complete the ORDER cause
  1048. *
  1049. * @param string $order
  1050. * @example order by id ASC
  1051. */
  1052. function setOrder($order) {
  1053. $this->order = $order;
  1054. }
  1055. /**
  1056. * Returns query with WHERE and ORDER clauses concatenated.
  1057. *
  1058. * @return string query
  1059. */
  1060. function getQuery() {
  1061. $query = $this->query;
  1062. if ($this->filter != "") {
  1063. $query .= " WHERE {$this->filter}";
  1064. }
  1065. if ($this->order != "") {
  1066. $query .= " ORDER BY {$this->order}";
  1067. }
  1068. return $query;
  1069. }
  1070. /**
  1071. * Sets template to use.
  1072. *
  1073. * @param string $template
  1074. */
  1075. function setTemplate($template) {
  1076. $this->itemTemplate = $template;
  1077. }
  1078. function displayItem($item) {
  1079. $this->template->setContent("script", basename($_SERVER['SCRIPT_FILENAME']));
  1080. foreach($item as $k => $v) {
  1081. $this->template->setContent($k,$this->display($k,$v));
  1082. }
  1083. }
  1084. function get($data) {
  1085. if (is_array($data)) {
  1086. if ($this->itemTemplate == "") {
  1087. if (isset($data[0]['lastmodified'])) {
  1088. $this->setTemplate("dtml/ajax-report-with-owner.html");
  1089. } else {
  1090. $this->setTemplate("dtml/ajax-report.html");
  1091. }
  1092. }
  1093. $this->template = new Template($this->itemTemplate);
  1094. foreach($data as $item) {
  1095. $this->displayItem($item);
  1096. }
  1097. return $this->template->get();
  1098. }
  1099. }
  1100. /**
  1101. * Formats content to display.
  1102. *
  1103. * @param string $k key
  1104. * @param string $v to format
  1105. * @return string
  1106. */
  1107. function display($k,$v) {
  1108. switch($k) {
  1109. case "lastmodified":
  1110. if ($v == "") {
  1111. return "";
  1112. } else {
  1113. return aux::formatDate($v , SHORT_LETTERS);
  1114. }
  1115. break;
  1116. case "owner":
  1117. return "by {$v}";
  1118. break;
  1119. case "active":
  1120. if ($v == "*") {
  1121. return "checked";
  1122. } else {
  1123. return "";
  1124. }
  1125. break;
  1126. default:
  1127. return aux::xmlchars($v, MODE3);
  1128. break;
  1129. }
  1130. return $v;
  1131. }
  1132. }
  1133. Class beContent {
  1134. var
  1135. $files,
  1136. $selfrefs,
  1137. $entities,
  1138. $currentform,
  1139. $comments;
  1140. function beContent() { }
  1141. function getSearchForm() {
  1142. $entities = func_get_args();
  1143. if (!isset($_REQUEST['page'])) {
  1144. $_REQUEST['page'] = 0;
  1145. }
  1146. switch ($_REQUEST['page']) {
  1147. case 0: /* FORM EMISSION - This should be done on a presentation layer! */
  1148. $content = "<div id=\"search\"> <form name=\"search\">\n";
  1149. $content .= "<input type=\"hidden\" name=\"page\" value=\"1\">\n";
  1150. $content .= "<input type=\"hidden\" name=\"action\" value=\"search\">\n";
  1151. $content .= "<table>\n";
  1152. $content .= "<tr>\n";
  1153. $content .= "<td>Free Text &nbsp;</td>\n";
  1154. #$content .= "<td><input type=\"text\" name=\"text\" size=\"30\" onkeyup=\"searchRequest();\"></td>\n";
  1155. $content .= "<td><input type=\"text\" name=\"text\" size=\"30\" ></td>\n";
  1156. $content .= "</tr>\n";
  1157. foreach($entities as $k => $entity) {
  1158. if (is_array($entity->searchFields['CHECK'])) {
  1159. foreach($entity->searchFields['CHECK'] as $index => $field) {
  1160. $result[$entity->name][$field] = aux::getResult("SELECT DISTINCT {$field} FROM {$entity->name} WHERE {$field} <> '' ORDER BY {$field}");
  1161. $label[$field] = $entity->searchFields['CHECKLABEL'][$index];
  1162. }
  1163. }
  1164. }
  1165. $finalArray = array();
  1166. $field = "";
  1167. if (is_array($result)) {
  1168. foreach($result as $entity => $v1) {
  1169. foreach($v1 as $field => $v2) {
  1170. foreach($v2 as $v3) {
  1171. foreach($v3 as $k => $v) {
  1172. if ($k != $field) {
  1173. $field = $k;
  1174. }
  1175. $finalArray[$field] = aux::add_distinct($finalArray[$field],$v);
  1176. }
  1177. }
  1178. }
  1179. }
  1180. }
  1181. $field = "";
  1182. foreach($finalArray as $k => $item) {
  1183. $content .= "<tr>\n";
  1184. if ($k != $field) {
  1185. $content .= "<td valign=\"top\">{$label[$k]}</td>\n";
  1186. $field = $k;
  1187. } else {
  1188. $content .= "<td></td>\n";
  1189. }
  1190. $content .= "<td>\n";
  1191. $sorted = $item;
  1192. asort($sorted);
  1193. $content .= "\n\n<!-- BEGIN -->\n<table width=\"100%\">\n";
  1194. $checkcount = 0;
  1195. foreach($sorted as $k => $v) {
  1196. if (($checkcount % 2) == 0) {
  1197. $content .= "<tr>\n";
  1198. $content .= "<td width=\"50%\"><input type=\"checkbox\" name=\"{$field}_{$v}\" value=\"{$v}\"> {$v}</td>\n";
  1199. } else {
  1200. $content .= "<td width=\"50%\"><input type=\"checkbox\" name=\"{$field}_{$v}\" value=\"{$v}\"> {$v}</td>\n";
  1201. $content .= "</tr>\n";
  1202. }
  1203. $checkcount++;
  1204. }
  1205. if (($checkcount % 2) == 0) {
  1206. $content .= "<td></td>\n";
  1207. $content .= "</tr>\n";
  1208. }
  1209. $content .= "</table>\n\n<!-- END -->\n\n";
  1210. $content .= "</td>\n";
  1211. $content .= "</tr>\n";
  1212. }
  1213. foreach($entities as $k => $entity) {
  1214. if (is_array($entity->searchRelations)) {
  1215. foreach($entity->searchRelations as $index => $relation) {
  1216. $relations[$relation->name] = $relation;
  1217. if ($relation->entity_1->name == $entity->name) {
  1218. $data = $relation->entity_2->getReference();
  1219. } else {
  1220. $data = $relation->entity_1->getReference();
  1221. }
  1222. $name = $relation->name;
  1223. $content .= "<tr><td valign=\"top\">{$entity->searchFields['RELATIONLABEL'][$index]}</td><td>\n";
  1224. $content .= "<table width=\"100%\">\n";
  1225. $checkcount = 0;
  1226. foreach($data as $v) {
  1227. if (($checkcount % 2) == 0) {
  1228. $content .= "<tr>\n";
  1229. $content .= "<td width=\"50%\"><input type=\"checkbox\" name=\"{$name}_{$v['value']}\" value=\"{$v['value']}\"> {$v['text']}</td>\n";
  1230. } else {
  1231. $content .= "<td width=\"50%\"><input type=\"checkbox\" name=\"{$name}_{$v['value']}\" value=\"{$v['value']}\"> {$v['text']}</td>\n";
  1232. $content .= "</tr>";
  1233. }
  1234. $checkcount++;
  1235. }
  1236. if (($checkcount % 2) == 0) {
  1237. $content .= "<td></td>\n";
  1238. $content .= "</tr>";
  1239. }
  1240. $content .= "</table>\n";
  1241. $content .= "</td></tr>\n";
  1242. }
  1243. }
  1244. }
  1245. $content .= "<tr><td></td>\n";
  1246. $content .= "<td><input type=\"submit\" value=\"Show Result\"></td>\n";
  1247. $content .= "</tr>\n</table>\n</form></div>\n\n";
  1248. return $content;
  1249. break;
  1250. case 1:
  1251. // ******************
  1252. foreach($entities as $entity) {
  1253. unset($sub_cond);
  1254. $fields = "{$entity->name}.{$entity->fields[0]['name']} AS {$entity->name}_{$entity->fields[0]['name']}";
  1255. if (is_array($entity->searchFields['TEXT'])) {
  1256. foreach($entity->searchFields['TEXT'] as $field) {
  1257. $fields .= ", {$entity->name}.{$field} AS {$entity->name}_{$field}";
  1258. }
  1259. }
  1260. if (is_array($entity->searchFields['CHECK'])) {
  1261. foreach($entity->searchFields['CHECK'] as $field) {
  1262. $fields .= ", {$entity->name}.{$field} AS {$entity->name}_{$field}";
  1263. }
  1264. }
  1265. if (is_array($entity->searchFields['TEXT'])) {
  1266. if ($entity->owner) {
  1267. $fields .= ", username, creation";
  1268. }
  1269. }
  1270. $query = "SELECT $fields FROM {$entity->name} ";
  1271. $left = "";
  1272. if (count($entity->searchRelations) > 0) {
  1273. foreach($entity->searchRelations as $relation) {
  1274. $left .= "LEFT JOIN {$relation->name} ON {$relation->name}.id_{$entity->name} = {$entity->name}.{$entity->fields[0]['name']} ";
  1275. }
  1276. }
  1277. if ($_REQUEST['text'] != "") {
  1278. $condition = "";
  1279. if (count($entity->searchFields['TEXT']) > 0) {
  1280. foreach($entity->searchFields['TEXT'] as $field) {
  1281. $condition .= aux::first_comma("{$entity->name} cond_1", " OR ")."{$entity->name}.{$field} LIKE '%{$_REQUEST['text']}%'";
  1282. }
  1283. }
  1284. if ($condition != "") {
  1285. $sub_cond[] = $condition;
  1286. }
  1287. }
  1288. $condition = "";
  1289. if (count($entity->searchFields['CHECK']) > 0) {
  1290. foreach($entity->searchFields['CHECK'] as $field) {
  1291. foreach($_REQUEST as $element => $value) {
  1292. if (ereg($field, $element)) {
  1293. $condition .= aux::first_comma("{$entity->name} cond_2", " OR ")."{$entity->name}.{$field} = '{$value}'";
  1294. }
  1295. }
  1296. }
  1297. }
  1298. if ($condition != "") {
  1299. $sub_cond[] = $condition;
  1300. }
  1301. if (count($entity->searchRelations) > 0) {
  1302. foreach($entity->searchRelations as $relation) {
  1303. $condition = "";
  1304. foreach($_REQUEST as $element => $value) {
  1305. if (ereg($relation->name, $element)) {
  1306. $condition .= aux::first_comma($relation->name, " OR ")."{$relation->name}.id_{$entity->name} = '{$value}'";
  1307. }
  1308. }
  1309. if ($condition != "") {
  1310. $sub_cond[] = $condition;
  1311. $query .= $left;
  1312. }
  1313. }
  1314. }
  1315. if (count($sub_cond) > 0) {
  1316. $query .= " WHERE ";
  1317. foreach($sub_cond as $condition) {
  1318. $query .= aux::first_comma("{$entity->name} WHERE", " AND ")."({$condition})";
  1319. }
  1320. }
  1321. return $query;
  1322. }
  1323. break;
  1324. }
  1325. }
  1326. function search() {
  1327. $entities = func_get_args();
  1328. $text = $_REQUEST['text'];
  1329. $_REQUEST['action'] = "search";
  1330. $_REQUEST['page'] = 1;
  1331. $empty = true;
  1332. $skin = new Skinlet("search");
  1333. foreach($entities as $entity) {
  1334. if (is_array($entity->searchFields)) {
  1335. $data = aux::getResult($GLOBALS['becontent']->getsearchform($entity));
  1336. if (count($data) > 0) {
  1337. $empty = false;
  1338. foreach($data as $item) {
  1339. $head = "";
  1340. if (is_array($entity->searchHead)) {
  1341. foreach($entity->searchHead as $field) {
  1342. if (!$entity->existsField($field)) {
  1343. $head .= " ".$item[$entity->name."_".$field."_".$_SESSION['language']];
  1344. } else {
  1345. $head .= " ".$item[$entity->name."_".$field];
  1346. }
  1347. }
  1348. $skin->setContent("handler", $entity->searchHandler);
  1349. $skin->setContent("table", $entity->name);
  1350. $skin->setContent("key", $entity->fields[0]['name']);
  1351. $skin->setContent("value", $item["{$entity->name}_{$entity->fields[0]['name']}"]);
  1352. $skin->setContent("title", $head);
  1353. }
  1354. $body = "";
  1355. if (is_array($entity->searchBody)) {
  1356. foreach($entity->searchBody as $field) {
  1357. if (!$entity->existsField($field)) {
  1358. $body .= " ".$item[$entity->name."_".$field."_".$_SESSION['language']];
  1359. } else {
  1360. $body .= " ".$item[$entity->name."_".$field];
  1361. }
  1362. $body .= "<br />";
  1363. }
  1364. $skin->setContent("body", $body);
  1365. }
  1366. if ($entity->owner) {
  1367. $skin->setContent("date", "</p><p class=\"search-date\">".aux::lingual("Pubblicato","Published on", "")." ".aux::formatDate($item['creation'], EXTENDED));
  1368. } else {
  1369. $skin->setContent("date", "");
  1370. }
  1371. }
  1372. }
  1373. }
  1374. }
  1375. if ($empty) {
  1376. $skin = new Skinlet("search_empty");
  1377. $skin->setContent("text", $_REQUEST['text']);
  1378. }
  1379. return $skin->get();
  1380. }
  1381. function clearCache($mode = HTML_IMG) {
  1382. $dh = opendir($GLOBALS['config']['cache_folder']);
  1383. while (false !== ($file = readdir($dh))) {
  1384. if (($file != ".") and ($file != "..")) {
  1385. switch($mode) {
  1386. case HTML:
  1387. if (ereg("\.html$", $file)) {
  1388. unlink("{$GLOBALS['config']['cache_folder']}/{$file}");
  1389. }
  1390. break;
  1391. case IMG:
  1392. if (ereg("\.jpg$", $file)) {
  1393. unlink("{$GLOBALS['config']['cache_folder']}/{$file}");
  1394. }
  1395. break;
  1396. case HTML_IMG:
  1397. if ((ereg("\.html$", $file)) or (ereg("\.jpg$", $file))) {
  1398. unlink("{$GLOBALS['config']['cache_folder']}/{$file}");
  1399. }
  1400. break;
  1401. }
  1402. }
  1403. }
  1404. closedir($dh);
  1405. }
  1406. }
  1407. $becontent = new beContent();
  1408. /**
  1409. * Class DB - manages db connections.
  1410. *
  1411. */
  1412. Class DB {
  1413. /**
  1414. * Server Hostname or IP.
  1415. *
  1416. * @var string
  1417. */
  1418. var $host;
  1419. /**
  1420. * DB name.
  1421. *
  1422. * @var string
  1423. */
  1424. var $name;
  1425. /**
  1426. * DB user.
  1427. *
  1428. * @var string
  1429. */
  1430. var $user;
  1431. /**
  1432. * DB password.
  1433. *
  1434. * @var unknown_type
  1435. */
  1436. var $pass;
  1437. /**
  1438. * Tables name.
  1439. *
  1440. * @var array
  1441. */
  1442. var $tables = array();
  1443. var $fields = array();
  1444. var $files;
  1445. var $entities;
  1446. function DB($host,$name,$user,$pass) {
  1447. $this->host = $host;
  1448. $this->name = $name;
  1449. $this->user = $user;
  1450. $this->pass = $pass;
  1451. $connection = mysql_pconnect($this->host,$this->user,$this->pass, MYSQL_CLIENT_COMPRESS);
  1452. if ($connection) {
  1453. $database = $connection;
  1454. if (mysql_select_db($this->name)) {
  1455. $dbms_database_open = true;
  1456. } else {
  1457. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_OPEN)." {$this->name}";
  1458. exit;
  1459. }
  1460. } else {
  1461. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_CONNECTION)." {$this->name}";
  1462. exit;
  1463. }
  1464. $result = mysql_list_tables($this->name);
  1465. while ($row = mysql_fetch_row($result)) {
  1466. $this->tables[] = strtolower($row[0]);
  1467. /*
  1468. $oid = mysql_query("SHOW COLUMNS
  1469. FROM {$row[0]}");
  1470. if (!$oid){
  1471. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  1472. exit;
  1473. }
  1474. do {
  1475. $data = mysql_fetch_assoc($oid);
  1476. if ($data) {
  1477. $this->fields[$row[0]][$data['Field']] = true;
  1478. }
  1479. } while ($data);
  1480. */
  1481. }
  1482. }
  1483. /**
  1484. * Returns an Entity from a given name.
  1485. *
  1486. * @param string $name
  1487. * @return Entity
  1488. */
  1489. function getEntityByName($name) {
  1490. $result = false;
  1491. $i = 0;
  1492. while ((!$result) and ($i<count($GLOBALS['becontent']->entities))) {
  1493. if ($GLOBALS['becontent']->entities[$i]->name == $name) {
  1494. $result = $GLOBALS['becontent']->entities[$i];
  1495. }
  1496. $i++;
  1497. }
  1498. return $result;
  1499. }
  1500. /**
  1501. * Checks if table exists from a given name.
  1502. *
  1503. * @param string $name
  1504. * @return bool
  1505. */
  1506. function existsTable($name) {
  1507. $result = false;
  1508. for($i=0; $i<count($this->tables); $i++) {
  1509. if ($this->tables[$i] == $name) {
  1510. $result = true;
  1511. }
  1512. }
  1513. return $result;
  1514. }
  1515. /**
  1516. * Checks if a table contains a field.
  1517. *
  1518. * @param string $tableName
  1519. * @param string $fieldName
  1520. * @return integer
  1521. */
  1522. function existsField($tableName, $fieldName) {
  1523. return $this->fields[$tableName][$fieldName];
  1524. }
  1525. /**
  1526. * Init the skeleton application with main services.
  1527. *
  1528. * @return void
  1529. *
  1530. */
  1531. function init() {
  1532. $oid = mysql_query("SELECT * FROM {$GLOBALS['usersEntity']->name}");
  1533. if (mysql_num_rows($oid) == 0) {
  1534. $GLOBALS['usersEntity']->insertItem(array(
  1535. "username" => $GLOBALS['config']['defaultuser']['username'],
  1536. "password" => md5($GLOBALS['config']['defaultuser']['password']),
  1537. "email" => $GLOBALS['config']['defaultuser']['email'],
  1538. "name" => $GLOBALS['config']['defaultuser']['name'],
  1539. "surname" => $GLOBALS['config']['defaultuser']['surname']
  1540. )
  1541. );
  1542. $GLOBALS['groupsEntity']->insertItem("1", "Administrator", "Administration Group.");
  1543. $GLOBALS['usersGroupsRelation']->insertItem($GLOBALS['co…

Large files files are truncated, but you can click here to view the full file