/include/beContent.inc.php

http://becontent.googlecode.com/ · PHP · 9879 lines · 6208 code · 1945 blank · 1726 comment · 1170 complexity · ff8327d9a523bf8bf4e0865e65d28c41 MD5 · raw 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['config']['defaultuser']['username'],"1");
  1544. $GLOBALS['servicecategoryEntity']->insertItem(array(
  1545. "id" => "1",
  1546. "name" => "System",
  1547. "position" => "1")
  1548. );
  1549. $GLOBALS['servicecategoryEntity']->insertItem(array(
  1550. "id" => "2",
  1551. "name" => "Content",
  1552. "position" => "2")
  1553. );
  1554. $GLOBALS['servicecategoryEntity']->insertItem(array(
  1555. "id" => "3",
  1556. "name" => "RSS",
  1557. "position" => "3")
  1558. );
  1559. /* Services */
  1560. $GLOBALS['servicesEntity']->insertItem(array(
  1561. "id" => "1",
  1562. "name" => "Login",
  1563. "script" => "login.php",
  1564. "entry" => "Login",
  1565. "servicecategory" => "0",
  1566. "visible" => "*",
  1567. "des" => "Login service",
  1568. "id_entities" => "",
  1569. "position" => "1")
  1570. );
  1571. $GLOBALS['servicesEntity']->insertItem(array(
  1572. "id" => "2",
  1573. "name" => "Logout",
  1574. "script" => "logout.php",
  1575. "entry" => "Logout",
  1576. "servicecategory" => "0",
  1577. "visible" => "*",
  1578. "des" => "Logout service",
  1579. "id_entities" => "",
  1580. "position" => "2")
  1581. );
  1582. $GLOBALS['servicesEntity']->insertItem(array(
  1583. "id" => "3",
  1584. "name" => "User Management",
  1585. "script" => "user-manager.php",
  1586. "entry" => "Users",
  1587. "servicecategory" => "1",
  1588. "visible" => "*",
  1589. "des" => "",
  1590. "id_entities" => "",
  1591. "position" => "1")
  1592. );
  1593. $GLOBALS['servicesEntity']->insertItem(array(
  1594. "id" => "4",
  1595. "name" => "Group Management",
  1596. "script" => "group-manager.php",
  1597. "entry" => "Groups",
  1598. "servicecategory" => "1",
  1599. "visible" => "*",
  1600. "des" => "",
  1601. "id_entities" => "",
  1602. "position" => "2")
  1603. );
  1604. $GLOBALS['servicesEntity']->insertItem(array(
  1605. "id" => "5",
  1606. "name" => "Service Management",
  1607. "script" => "service-manager.php",
  1608. "entry" => "Services",
  1609. "servicecategory" => "1",
  1610. "visible" => "*",
  1611. "des" => "",
  1612. "id_entities" => "",
  1613. "position" => "3")
  1614. );
  1615. $GLOBALS['servicesEntity']->insertItem(array(
  1616. "id" => "6",
  1617. "name" => "Service Category Management",
  1618. "script" => "servicecategory-manager.php",
  1619. "entry" => "Service Categories",
  1620. "servicecategory" => "1",
  1621. "visible" => "*",
  1622. "des" => "",
  1623. "id_entities" => "",
  1624. "position" => "4")
  1625. );
  1626. $GLOBALS['servicesEntity']->insertItem(array(
  1627. "id" => "7",
  1628. "name" => "Logs",
  1629. "script" => "logs.php",
  1630. "entry" => "Logs",
  1631. "servicecategory" => "1",
  1632. "visible" => "*",
  1633. "des" => "",
  1634. "id_entities" => "",
  1635. "position" => "5")
  1636. );
  1637. $GLOBALS['servicesEntity']->insertItem(array(
  1638. "id" => "8",
  1639. "name" => "Page Management",
  1640. "script" => "page-manager.php",
  1641. "entry" => "Pages",
  1642. "servicecategory" => "2",
  1643. "visible" => "*",
  1644. "des" => "",
  1645. "id_entities" => "",
  1646. "position" => "1")
  1647. );
  1648. $GLOBALS['servicesEntity']->insertItem(array(
  1649. "id" => "9",
  1650. "name" => "Menu Management",
  1651. "script" => "menu-manager.php",
  1652. "entry" => "Menu",
  1653. "servicecategory" => "2",
  1654. "visible" => "*",
  1655. "des" => "",
  1656. "id_entities" => "",
  1657. "position" => "2")
  1658. );
  1659. $GLOBALS['servicesEntity']->insertItem(array(
  1660. "id" => "10",
  1661. "name" => "Template Management",
  1662. "script" => "template-manager.php",
  1663. "entry" => "Template",
  1664. "servicecategory" => "2",
  1665. "visible" => "*",
  1666. "des" => "",
  1667. "id_entities" => "",
  1668. "position" => "3")
  1669. );
  1670. $GLOBALS['servicesEntity']->insertItem(array(
  1671. "id" => "11",
  1672. "name" => "News",
  1673. "script" => "news-manager.php",
  1674. "entry" => "News",
  1675. "servicecategory" => "2",
  1676. "visible" => "*",
  1677. "des" => "",
  1678. "id_entities" => "",
  1679. "position" => "4")
  1680. );
  1681. $GLOBALS['servicesEntity']->insertItem(array(
  1682. "id" => "12",
  1683. "name" => "Comments",
  1684. "script" => "comment-manager.php",
  1685. "entry" => "Comments",
  1686. "servicecategory" => "2",
  1687. "visible" => "*",
  1688. "des" => "",
  1689. "id_entities" => "",
  1690. "position" => "5")
  1691. );
  1692. $GLOBALS['servicesEntity']->insertItem(array(
  1693. "id" => "13",
  1694. "name" => "Channel Manager",
  1695. "script" => "channel-manager.php",
  1696. "entry" => "Channels",
  1697. "servicecategory" => "3",
  1698. "visible" => "*",
  1699. "des" => "",
  1700. "id_entities" => "",
  1701. "position" => "1")
  1702. );
  1703. $GLOBALS['servicesEntity']->insertItem(array(
  1704. "id" => "14",
  1705. "name" => "RSS Management",
  1706. "script" => "rss-panel.php",
  1707. "entry" => "Panel",
  1708. "servicecategory" => "3",
  1709. "visible" => "*",
  1710. "des" => "",
  1711. "id_entities" => "",
  1712. "position" => "2")
  1713. );
  1714. $GLOBALS['lanEntity']->insertItem("en-US", "English");
  1715. $GLOBALS['lanEntity']->insertItem("it-IT", "Italian");
  1716. $GLOBALS['lanEntity']->insertItem("es-ES", "German");
  1717. $GLOBALS['channelAssotiation']->insertItem("1", "news", "1");
  1718. #$GLOBALS['rssMod']->insertItem("news", "MOD3");
  1719. $GLOBALS['servicesGroupsRelation']->insertItem("1","1");
  1720. $GLOBALS['servicesGroupsRelation']->insertItem("2","1");
  1721. $GLOBALS['servicesGroupsRelation']->insertItem("3","1");
  1722. $GLOBALS['servicesGroupsRelation']->insertItem("4","1");
  1723. $GLOBALS['servicesGroupsRelation']->insertItem("5","1");
  1724. $GLOBALS['servicesGroupsRelation']->insertItem("6","1");
  1725. $GLOBALS['servicesGroupsRelation']->insertItem("7","1");
  1726. $GLOBALS['servicesGroupsRelation']->insertItem("8","1");
  1727. $GLOBALS['servicesGroupsRelation']->insertItem("9","1");
  1728. $GLOBALS['servicesGroupsRelation']->insertItem("10","1");
  1729. $GLOBALS['servicesGroupsRelation']->insertItem("11","1");
  1730. $GLOBALS['servicesGroupsRelation']->insertItem("12","1");
  1731. $GLOBALS['servicesGroupsRelation']->insertItem("13","1");
  1732. $GLOBALS['servicesGroupsRelation']->insertItem("14","1");
  1733. } // if(mysql_num_rows($oid))
  1734. } // init()
  1735. } // class DB
  1736. /* Class Fields {
  1737. var
  1738. $fields,
  1739. $fieldsByName;
  1740. function Fields() {
  1741. }
  1742. function append($field) {
  1743. $this->fields[] = $field;
  1744. $this->fieldsByName[$field->getName()] = $field;
  1745. }
  1746. function exists($name) {
  1747. return array_key_exists($name, $this->fieldsByName);
  1748. }
  1749. function getField($name) {
  1750. if ($this->exists($name)) {
  1751. return $this->fieldsByName[$name];
  1752. } else {
  1753. return false;
  1754. }
  1755. }
  1756. }
  1757. Class Field {
  1758. var
  1759. $name,
  1760. $type;
  1761. function Field($name, $type) {
  1762. $this->name = $name;
  1763. $this->type = $type;
  1764. }
  1765. } */
  1766. /**
  1767. * Class Entity - model
  1768. *
  1769. */
  1770. Class Entity {
  1771. var $fieldRepository;
  1772. /**
  1773. * Database connection.
  1774. *
  1775. * @var DB
  1776. */
  1777. var $database;
  1778. /**
  1779. * Name.
  1780. *
  1781. * @var string
  1782. */
  1783. var $name;
  1784. /**
  1785. * Fields.
  1786. *
  1787. * @var array
  1788. */
  1789. var $fields;
  1790. /**
  1791. * Maintains last Index of array $field
  1792. *
  1793. * @var integer
  1794. */
  1795. var $lastFieldIndex;
  1796. /**
  1797. * Presentation Fields to show in reports link.
  1798. *
  1799. * @var array
  1800. */
  1801. var $presentation;
  1802. /**
  1803. * Entity has standard key.
  1804. * Until is not specified with addPrimaryKey.
  1805. * default: true
  1806. *
  1807. * @var bool
  1808. */
  1809. var $standardKey;
  1810. /**
  1811. * Entity has not a primary key.
  1812. *
  1813. * @var bool
  1814. */
  1815. var $noKey;
  1816. /**
  1817. * Entity has owner.
  1818. *
  1819. * @var bool
  1820. */
  1821. var $owner;
  1822. /**
  1823. * Magic quotes On or Off.
  1824. * Actual configuration.
  1825. *
  1826. * @var bool
  1827. */
  1828. var $addslashes;
  1829. /**
  1830. * Reload.
  1831. *
  1832. * @var bool
  1833. */
  1834. var $reload;
  1835. /**
  1836. * Keep references from others Entity.
  1837. *
  1838. *
  1839. * @var array
  1840. */
  1841. var $referredBy;
  1842. /**
  1843. * Keep relations with others Entity.
  1844. *
  1845. * @var array
  1846. */
  1847. var $relations;
  1848. /**
  1849. * Position items.
  1850. *
  1851. * @var array
  1852. */
  1853. var $positions;
  1854. /**
  1855. * Used to filter relations.
  1856. *
  1857. * @var array
  1858. */
  1859. var $filterRelation;
  1860. /**
  1861. * Keep field to ordinate to.
  1862. *
  1863. * @var string
  1864. */
  1865. var $referenceOrder;
  1866. /**
  1867. * Vale true se l'entita abilitata alla gestione degli rss.
  1868. *
  1869. * @var bool
  1870. */
  1871. var $rss;
  1872. /**
  1873. * Relation Entity-RssChannel.
  1874. *
  1875. * @var array
  1876. */
  1877. var $channel;
  1878. /**
  1879. * Mantiene corrispondenze field entita -> campo Item.
  1880. *
  1881. * @var array
  1882. */
  1883. var $rssPresentation;
  1884. /**
  1885. * Filters item according to given criteria.
  1886. *
  1887. * @var unknown_type
  1888. */
  1889. var $rssFilter;
  1890. /**
  1891. * List of fields to be searched.
  1892. *
  1893. * @var array
  1894. */
  1895. var $searchFields;
  1896. /**
  1897. * List of n-m relations to be searched.
  1898. *
  1899. * @var unknown_type
  1900. */
  1901. var $searchRelations;
  1902. /**
  1903. *
  1904. *
  1905. * @var unknown_type
  1906. */
  1907. var $searchHead;
  1908. /**
  1909. * Presentation fields.
  1910. *
  1911. * @var unknown_type
  1912. */
  1913. var $searchBody;
  1914. /**
  1915. * The handler to be used to present data from search results.
  1916. *
  1917. * @var unknown_type
  1918. */
  1919. var $searchHandler;
  1920. /**
  1921. * Comments.
  1922. *
  1923. * @var array
  1924. */
  1925. var $comments;
  1926. /**
  1927. * NOT USED.
  1928. *
  1929. * @var unknown_type
  1930. */
  1931. var $moderated = true;
  1932. /**
  1933. * Constructor Entity.
  1934. *
  1935. * @param DB $database database object connection
  1936. * @param String $name name of entity (table)
  1937. * @param Constant $owner WITH_OWNER add owner to the entry
  1938. * @return Entity
  1939. */
  1940. function Entity($database,$name,$owner = "") {
  1941. global $entitiesEntity;
  1942. $this->owner = ($owner == WITH_OWNER);
  1943. $this->addslashes = (!get_magic_quotes_gpc());
  1944. #$this->addslashes = false;
  1945. $this->database = $database;
  1946. $this->name = $name;
  1947. $this->standardKey = true;
  1948. $this->noKey = false;
  1949. $this->reload = false;
  1950. $this->referenceOrder = false;
  1951. $this->fields[0] = array(
  1952. "name" => "id",
  1953. "type" => "INT UNSIGNED AUTO_INCREMENT",
  1954. "primary key" => true,
  1955. "foreign key" => false
  1956. );
  1957. if ($this->owner) {
  1958. /* $this->fields[] = array("name" => "username",
  1959. "type" => "VARCHAR",
  1960. "foreign key" => true,
  1961. "primary key" => false,
  1962. "owner" => true,
  1963. "length" => 15
  1964. );*/
  1965. $this->addReference($GLOBALS['usersEntity'], "username");
  1966. $this->setFieldParameter("owner", true);
  1967. $this->addField("creation", LONGDATE);
  1968. $this->addField("lastModified", LONGDATE);
  1969. /*
  1970. The following is used in order to extend the referential integrity check
  1971. to WITH_OWNER entities.
  1972. */
  1973. $GLOBALS['usersEntity']->referred[$this->name][] = $this;
  1974. $GLOBALS['usersEntity']->referredBy[$this->name]['entity'][] = $this;
  1975. $GLOBALS['usersEntity']->referredBy[$this->name]['foreign key'][] = 'username';
  1976. }
  1977. #$GLOBALS['database']->entities[] = &$this;
  1978. #Viene utilizzato per la gestione degli Rss
  1979. $GLOBALS['becontent']->entities[$this->name] = &$this;
  1980. $this->moderated = true;
  1981. }
  1982. /**
  1983. * Checks if fields exists in the entity.
  1984. *
  1985. * @param String $field name
  1986. * @return integer 1 if exists else 0
  1987. */
  1988. function existsField($field) {
  1989. $i = 0;
  1990. $trovato = 0;
  1991. while ((!$trovato) and ($i<count($this->fields))) {
  1992. if ($this->fields[$i]['name'] == $field) {
  1993. $trovato = 1;
  1994. }
  1995. $i++;
  1996. }
  1997. return $trovato;
  1998. #return $GLOBALS['database']->existsField($this->name, $field);
  1999. }
  2000. /**
  2001. * Set comments.
  2002. *
  2003. * @param Array $arg
  2004. */
  2005. function setComments($arg) {
  2006. $this->comments = $arg;
  2007. }
  2008. /**
  2009. * NOT YET IMPLEMENTED .
  2010. */
  2011. function addItem_postInsertion() { }
  2012. /**
  2013. * Returns a field by name.
  2014. *
  2015. * @param string $name
  2016. * @return Array field
  2017. */
  2018. function getField($name) {
  2019. $field = false;
  2020. foreach($this->fields as $k => $f) {
  2021. if ($f['name'] == $name) {
  2022. $field = $this->fields[$k];
  2023. }
  2024. }
  2025. return $field;
  2026. }
  2027. /**
  2028. * Set extension to a field.
  2029. *
  2030. * @param string $name
  2031. * @param string $exts
  2032. */
  2033. function setExtension($name, $exts) {
  2034. $index = false;
  2035. foreach($this->fields as $k => $v) {
  2036. if ($v['name'] == $name) {
  2037. $this->fields[$k]['exts'] = $exts;
  2038. }
  2039. }
  2040. }
  2041. /**
  2042. * Return the keyname if exists
  2043. *
  2044. * @return unknown
  2045. */
  2046. function getKeyName() {
  2047. if ($this->noKey) {
  2048. return false;
  2049. } else {
  2050. return $this->fields[0]['name'];
  2051. }
  2052. }
  2053. /**
  2054. * Returns the field type of the primary key.
  2055. * if Entity has no key return false
  2056. *
  2057. * @return string or bool
  2058. */
  2059. function getKeyType() {
  2060. if ($this->noKey) {
  2061. return false;
  2062. } else {
  2063. return $this->fields[0]['type'];
  2064. }
  2065. }
  2066. /**
  2067. * Adds the primary key
  2068. *
  2069. * @param unknown_type $name
  2070. * @param unknown_type $type
  2071. * @param unknown_type $length
  2072. */
  2073. function getKeyLength() {
  2074. if ($this->noKey) {
  2075. return false;
  2076. } else {
  2077. return $this->fields[0]['length'];
  2078. }
  2079. }
  2080. /**
  2081. * Return if has standardkey
  2082. *
  2083. * @return bool
  2084. */
  2085. function standardKey() {
  2086. return $this->standardKey;
  2087. }
  2088. /**
  2089. * Adds the primary key
  2090. * note: this action add also the field
  2091. * It is not necessary to addField
  2092. *
  2093. * @param string $name name of the field
  2094. * @param string $type of the field
  2095. * @param integer $length
  2096. */
  2097. function addPrimaryKey($name, $type, $length = "") {
  2098. /* the following override the primary key definition given
  2099. in the class constructor, which create a defaultKey as
  2100. INT UNSIGNED */
  2101. $this->fields[0] = array(
  2102. "name" => $name,
  2103. "type" => $type,
  2104. "foreign key" => false,
  2105. "primary key" => true,
  2106. "length" => $length
  2107. //"mandatory" => $mandatory
  2108. );
  2109. $this->standardKey = false;
  2110. }
  2111. /**
  2112. * Sets Entity to noKey
  2113. *
  2114. * @return void
  2115. */
  2116. function noKey() {
  2117. $this->noKey = true;
  2118. unset($this->fields);
  2119. }
  2120. /**
  2121. * Adds a field to the Entity.
  2122. * By definition, the first POSITION field is
  2123. * dominant over the other orderings.
  2124. *
  2125. * @example $type: POSITION PASSWORD FILE IMAGE FILE2FOLDER ENUM or passed type
  2126. *
  2127. * @param String $name field name
  2128. * @param Costant $type
  2129. * @param integer $length of the field in characters in ENUM is the default value
  2130. * @param Option $mandatory MANDATORY=yes default=no
  2131. */
  2132. function addField($name, $type, $length = "", $mandatory = "no") {
  2133. switch($type) {
  2134. case "POSITION":
  2135. if (!$this->referenceOrder) {
  2136. $this->setReferenceOrder($name);
  2137. }
  2138. $this->fields[] = array(
  2139. "name" => $name,
  2140. "type" => $type,
  2141. "foreign key" => false,
  2142. "primary key" => false,
  2143. "length" => $length,
  2144. "mandatory" => $mandatory
  2145. );
  2146. break;
  2147. case "PASSWORD":
  2148. $this->fields[] = array(
  2149. "name" => $name,
  2150. "type" => $type,
  2151. "foreign key" => false,
  2152. "primary key" => false,
  2153. "password method" => $length,
  2154. "mandatory" => $mandatory
  2155. );
  2156. break;
  2157. case FILE:
  2158. case "IMAGE":
  2159. case FILE2FOLDER:
  2160. $GLOBALS['becontent']->files[md5($this->name.$name)]['table'] = $this->name;
  2161. $GLOBALS['becontent']->files[md5($this->name.$name)]['field'] = $name;
  2162. $this->fields[] = array(
  2163. "name" => $name,
  2164. "type" => $type,
  2165. "foreign key" => false,
  2166. "primary key" => false,
  2167. "length" => $length,
  2168. "mandatory" => $mandatory
  2169. );
  2170. break;
  2171. default:
  2172. $this->fields[] = array(
  2173. "name" => $name,
  2174. "type" => $type,
  2175. "foreign key" => false,
  2176. "primary key" => false,
  2177. "length" => $length,
  2178. "mandatory" => $mandatory
  2179. );
  2180. break;
  2181. }
  2182. } // addField
  2183. /**
  2184. * Set the field which is responsible for reference order.
  2185. *
  2186. * @param string $field tipicalli position
  2187. */
  2188. function setReferenceOrder($field) {
  2189. $this->referenceOrder = $field;
  2190. }
  2191. /**
  2192. * Get the field name which is responsible for reference order.
  2193. *
  2194. * @return string field name
  2195. */
  2196. function getReferenceOrder() {
  2197. return $this->referenceOrder;
  2198. }
  2199. /**
  2200. * NOT YET IMPLEMENTED.
  2201. *
  2202. * @param unknown_type $name
  2203. */
  2204. function checkName($name) {
  2205. /*
  2206. if (in_array($name,$RESERVEDWORDS)) {
  2207. echo "Error: '{$name}' is a reserved name and cannot be used in entity '{$this->name}'!";
  2208. exit;
  2209. }
  2210. */
  2211. }
  2212. /**
  2213. * Adds a reference to other entity.
  2214. * Different names should allow the definition of multiple foreigner keys
  2215. * targeting the same Entity.
  2216. *
  2217. * @param Entity $entity to reference
  2218. * @param field $name field of the Entity to reference PRIMARY KEY default: id_entityname
  2219. */
  2220. function addReference(&$entity, $name = "") {
  2221. $this->checkName($name);
  2222. if ($name == "") {
  2223. $name = "id_{$entity->name}";
  2224. }
  2225. $type = $entity->fields[0]['type'];
  2226. $length = (isset($entity->fields[0]['length']) ? $entity->fields[0]['length'] : '');
  2227. if ($this->name == $entity->name) {
  2228. $selfRelation = true;
  2229. } else {
  2230. $selfRelation = false;
  2231. }
  2232. $this->fields[] = array(
  2233. "name" => $name,
  2234. "type" => $type,
  2235. "length" => $length,
  2236. "foreign key" => true,
  2237. "primary key" => false,
  2238. "reference" => $entity,
  2239. "reference_name" => $entity->name,
  2240. "self_reference" => $selfRelation
  2241. );
  2242. $entity->referred[$this->name][] = $this;
  2243. $entity->referredBy[$this->name]['entity' ][] = $this;
  2244. $entity->referredBy[$this->name]['foreign key'][] = $name;
  2245. if ($this->name == $entity->name) {
  2246. $GLOBALS['becontent']->selfrefs[md5($this->name.$name)]['table'] = $this->name;
  2247. $GLOBALS['becontent']->selfrefs[md5($this->name.$name)]['field'] = $name;
  2248. }
  2249. $this->lastFieldIndex = count($this->fields)-1;
  2250. }
  2251. function setFieldParameter($name, $value) {
  2252. $this->fields[$this->lastFieldIndex][$name] = $value;
  2253. }
  2254. /**
  2255. * Set Presentation field to show in reports link.
  2256. * @example "name", "title"
  2257. * passed to function
  2258. *
  2259. * @return void
  2260. */
  2261. function setPresentation() {
  2262. $this->presentation = func_get_args();
  2263. }
  2264. /**
  2265. * Set text fields to search into.
  2266. * Used by the search engine.
  2267. * (function tipically expects parameters)
  2268. *
  2269. */
  2270. function setTextSearchFields() {
  2271. $this->searchFields['TEXT'] = func_get_args();
  2272. }
  2273. /**
  2274. * Set the CHECK and CHECKLABEL to search into.
  2275. * Used then by search engine.
  2276. * (function tipically expects parameters)
  2277. *
  2278. * @param string $name of the check field
  2279. * @param string $label
  2280. */
  2281. function setCheckSearchField($name, $label) {
  2282. $this->searchFields['CHECK'][] = $name;
  2283. $this->searchFields['CHECKLABEL'][] = $label;
  2284. }
  2285. /**
  2286. * Set th CHECK to search into.
  2287. * Used by search engine.
  2288. * (function tipically expects parameters)
  2289. *
  2290. */
  2291. function setCheckSearchFields() {
  2292. $this->searchFields['CHECK'] = func_get_args();
  2293. }
  2294. /**
  2295. * Set relations to search into.
  2296. * Used by search engine.
  2297. * (function tipically expects parameters)
  2298. *
  2299. */
  2300. function setSearchRelations() {
  2301. $this->searchRelations = func_get_args();
  2302. }
  2303. /**
  2304. * Set relation to search into.
  2305. * Used by search engine.
  2306. * (function tipically expects parameters)
  2307. *
  2308. * @param string $relation name
  2309. * @param string $label label
  2310. */
  2311. function setSearchRelation($relation, $label) {
  2312. $this->searchRelations[] = $relation;
  2313. $this->searchFields['RELATIONLABEL'][] = $label;
  2314. }
  2315. /**
  2316. * Set Presentation Head to present.
  2317. * Used by search engine.
  2318. * (function tipically expects parameters)
  2319. *
  2320. */
  2321. function setSearchPresentationHead() {
  2322. $this->searchHead = func_get_args();
  2323. }
  2324. /**
  2325. * Set Presentation Body.
  2326. * Used by search engine.
  2327. * (function tipically expects parameters)
  2328. *
  2329. */
  2330. function setSearchPresentationBody() {
  2331. $this->searchBody = func_get_args();
  2332. }
  2333. /**
  2334. * Set search handler php page to present data.
  2335. *
  2336. * @example setHandler('searchResult.php')
  2337. * @param string $script filename
  2338. */
  2339. function setHandler($script) {
  2340. $this->searchHandler = $script;
  2341. }
  2342. /**
  2343. * Return results from entity with his relations if exists
  2344. *
  2345. */
  2346. function getResult() {
  2347. $query = "SELECT * FROM {$this->name} ";
  2348. if (is_array($this->relations)) {
  2349. foreach($this->relations as $relation) {
  2350. $query .= "LEFT JOIN {$relation->name} ";
  2351. foreach($relation->fields as $key => $field) {
  2352. if ($_REQUEST[$field['name']] != '') {
  2353. $query .= "ON {$this->name}.{$this->fields[0]['name']} = {$relation->name}.{$field['name']}";
  2354. }
  2355. } // foreach field
  2356. } // foreach relation
  2357. } // if
  2358. $query;
  2359. }
  2360. /**
  2361. * Create entity in the database if not yet exists
  2362. * Attach entity to the others in $GLOBALS['becontent']->entities[]
  2363. *
  2364. */
  2365. function connect() {
  2366. #global $entitiesEntity;
  2367. if (true) { // isset($_['init])
  2368. if (!$this->database->existsTable($this->name)) {
  2369. $query = "CREATE TABLE {$this->name} (";
  2370. foreach ($this->fields as $k => $v) {
  2371. if (($this->standardKey) and ($k == 0) and ($v['primary key'])) {
  2372. #$query .= aux::first_comma("create".$this->name,", ")."{$v['name']} {$v['type']}";
  2373. }
  2374. #echo "{$v['name']}, *{$v['type']}*, {$v['length']}<br>";
  2375. switch ($v['type']) {
  2376. case VARCHAR:
  2377. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} {$v['type']}({$v['length']}) NOT NULL";
  2378. break;
  2379. case TEXT:
  2380. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} {$v['type']} NOT NULL";
  2381. break;
  2382. case FILE:
  2383. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} LONGBLOB NOT NULL";
  2384. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_filename VARCHAR(255) NOT NULL";
  2385. #$query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_original_filename VARCHAR(255) NOT NULL";
  2386. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_size INT UNSIGNED NOT NULL";
  2387. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_type VARCHAR(40) NOT NULL";
  2388. break;
  2389. case FILE2FOLDER:
  2390. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_reference VARCHAR(255) NOT NULL";
  2391. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_filename VARCHAR(255) NOT NULL";
  2392. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_size INT UNSIGNED NOT NULL";
  2393. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_type VARCHAR(40) NOT NULL";
  2394. break;
  2395. case IMAGE:
  2396. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} LONGBLOB NOT NULL";
  2397. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_thumb LONGBLOB NOT NULL";
  2398. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_filename VARCHAR(255) NOT NULL";
  2399. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_size INT UNSIGNED NOT NULL";
  2400. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']}_type VARCHAR(40) NOT NULL";
  2401. break;
  2402. case INT:
  2403. case STANDARD_PRIMARY_KEY_TYPE:
  2404. case POSITION:
  2405. if ($v['primary key']) {
  2406. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} INT UNSIGNED AUTO_INCREMENT";
  2407. } else {
  2408. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} INT UNSIGNED NOT NULL";
  2409. }
  2410. break;
  2411. case DATE:
  2412. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} VARCHAR(8) NOT NULL";
  2413. break;
  2414. /**
  2415. * the following is only for internal use at the moment, used in combination with
  2416. * the WITH_OWNER option.
  2417. *
  2418. */
  2419. case LONGDATE:
  2420. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} VARCHAR(12) NOT NULL";
  2421. break;
  2422. case PASSWORD:
  2423. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} VARCHAR(32) NOT NULL";
  2424. break;
  2425. case COLOR:
  2426. $query .= aux::first_comma("create".$this->name,", ")."{$v['name']} VARCHAR(7) NOT NULL";
  2427. break;
  2428. }
  2429. }
  2430. if ($this->noKey) {
  2431. $query .= ")";
  2432. } else {
  2433. $query .= ", primary key({$this->fields[0]['name']}))";
  2434. }
  2435. #echo "<hr>",$query, "<hr>";
  2436. $oid = mysql_query($query);
  2437. if (!$oid) {
  2438. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_QUERY)." {$this->name} at line ",__LINE__;
  2439. echo "<hr>", $query;
  2440. exit;
  2441. }
  2442. } else {
  2443. /*
  2444. $query = "ALTER TABLE {$this->name} ";
  2445. $alter = false;
  2446. foreach($this->fields as $k => $field) {
  2447. if (!$this->database->existsField($this->name,$field['name'])) {
  2448. echo "QIO ";
  2449. $alter = true;
  2450. $query .= "ADD ";
  2451. switch ($field['type']) {
  2452. case VARCHAR:
  2453. $query .= aux::first_comma("alter".$this->name,", ")."{$field[name]} {$field[type]}({$field[length]}) NOT NULL";
  2454. break;
  2455. case TEXT:
  2456. $query .= aux::first_comma("alter".$this->name,", ")."{$field[name]} {$field[type]} NOT NULL";
  2457. break;
  2458. case INT:
  2459. $query .= aux::first_comma("alter".$this->name,", ")."{$field[name]} INT UNSIGNED NOT NULL";
  2460. break;
  2461. case DATE:
  2462. $query .= aux::first_comma("alter".$this->name,", ")."{$field[name]} VARCHAR(8) NOT NULL";
  2463. break;
  2464. }
  2465. }
  2466. }
  2467. echo $query;
  2468. exit;
  2469. */
  2470. }
  2471. $GLOBALS['becontent']->entities[] = $this;
  2472. $this->register();
  2473. }
  2474. }
  2475. /**
  2476. * Register the entity in the entities DB table.
  2477. *
  2478. * @return void
  2479. */
  2480. function register() {
  2481. global $entitiesEntity;
  2482. if (isset($GLOBALS['entitiesEntity'])) {
  2483. $oid = mysql_query("INSERT INTO {$entitiesEntity->name}
  2484. VALUES('{$this->name}','{$this->name}', '{$this->owner}', '', 0, 0, 0)");
  2485. if (!$oid) {
  2486. /*
  2487. At the moment, this is executed each time but the first time, because of
  2488. the duplicate key notification. This can be avoided with a session based
  2489. technique.
  2490. */
  2491. }
  2492. }
  2493. }
  2494. /**
  2495. * Performs the update action of the entity in the DB.
  2496. *
  2497. * @return bool
  2498. */
  2499. function editItem() {
  2500. $query = "UPDATE {$this->name} SET ";
  2501. $_REQUEST['lastModified'] = date('YmdHi');
  2502. for($i=1; $i<count($this->fields); $i++) {
  2503. if ((array_key_exists($this->fields[$i]['name'], $_REQUEST)) or
  2504. ($this->fields[$i]['type'] == FILE) or
  2505. ($this->fields[$i]['type'] == FILE2FOLDER)) {
  2506. if ($this->addslashes) {
  2507. if (isset($_REQUEST[$this->fields[$i]['name']])) {
  2508. $this->fields[$i]['value'] = addslashes($_REQUEST[$this->fields[$i]['name']]);
  2509. }
  2510. } else {
  2511. if (isset($_REQUEST[$this->fields[$i]['name']])) {
  2512. $this->fields[$i]['value'] = $_REQUEST[$this->fields[$i]['name']];
  2513. }
  2514. }
  2515. switch ($this->fields[$i]['type']) {
  2516. case "DATE":
  2517. $date = explode("/",$this->fields[$i]['value']);
  2518. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  2519. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2520. break;
  2521. case LONGDATE:
  2522. $date = explode("/",$this->fields[$i]['value']);
  2523. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  2524. $time = explode(":", $_REQUEST[$this->fields[$i]['name']."_time"]);
  2525. $this->fields[$i]['value'] .= $time[0].$time[1];
  2526. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2527. break;
  2528. case FILE:
  2529. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  2530. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}=''";
  2531. $query .= ", {$this->fields[$i]['name']}_filename=''";
  2532. $query .= ", {$this->fields[$i]['name']}_size=''";
  2533. $query .= ", {$this->fields[$i]['name']}_type=''";
  2534. } else {
  2535. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  2536. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  2537. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  2538. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  2539. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  2540. $buffer = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  2541. if ($this->addslashes) {
  2542. $filename = addslashes($filename);
  2543. } else {
  2544. #$buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  2545. }
  2546. if (get_magic_quotes_gpc()) {
  2547. /*
  2548. Here instead of trim one should use stripslashes but doesn't work.
  2549. */
  2550. $buffer = mysql_real_escape_string(trim($buffer));
  2551. } else {
  2552. /*
  2553. It could be that here something different is required.
  2554. */
  2555. $buffer = mysql_real_escape_string(trim($buffer));
  2556. }
  2557. fclose($fp);
  2558. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}='{$buffer}'";
  2559. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  2560. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  2561. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  2562. }
  2563. }
  2564. break;
  2565. case FILE2FOLDER:
  2566. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  2567. if (file_exists("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}")) {
  2568. unlink("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}");
  2569. }
  2570. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}_reference = ''";
  2571. $query .= ", {$this->fields[$i]['name']}_filename = ''";
  2572. $query .= ", {$this->fields[$i]['name']}_size = ''";
  2573. $query .= ", {$this->fields[$i]['name']}_type = ''";
  2574. } else {
  2575. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  2576. if ($_REQUEST[$this->fields[$i]['name']."_reference"] != "") {
  2577. if (file_exists("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}")) {
  2578. unlink("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}");
  2579. }
  2580. }
  2581. $filename_local = md5(uniqid(time()));
  2582. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  2583. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  2584. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  2585. if (ereg("\.([[:alnum:]]*)$", $filename, $token)) {
  2586. if (isset($this->fields[$i]['exts'][$token[1]])) {
  2587. if ($this->fields[$i]['exts'][$token[1]] == AUTO) {
  2588. $extension = ".{$token[1]}";
  2589. } else {
  2590. $extension = ".{$this->fields[$i]['exts'][$token[1]]}";
  2591. }
  2592. } else {
  2593. $extension = "";
  2594. }
  2595. }
  2596. $filename_local = $filename_local.$extension;
  2597. move_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'], $GLOBALS['config']['upload_folder']."/$filename_local");
  2598. if ($this->addslashes) {
  2599. $filename = addslashes($filename);
  2600. }
  2601. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}_reference='{$filename_local}'";
  2602. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  2603. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  2604. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  2605. }
  2606. }
  2607. break;
  2608. case "IMAGE":
  2609. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  2610. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}=''";
  2611. $query .= ", {$this->fields[$i]['name']}_thumb=''";
  2612. $query .= ", {$this->fields[$i]['name']}_filename=''";
  2613. $query .= ", {$this->fields[$i]['name']}_size=''";
  2614. $query .= ", {$this->fields[$i]['name']}_type=''";
  2615. } else {
  2616. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  2617. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  2618. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  2619. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  2620. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  2621. $buffer = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  2622. if ($this->addslashes) {
  2623. $filename = addslashes($filename);
  2624. } else {
  2625. #$buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  2626. }
  2627. if (get_magic_quotes_gpc()) {
  2628. /*
  2629. Here instead of trim one should use stripslashes but doesn't work.
  2630. */
  2631. $buffer = mysql_real_escape_string(trim($buffer));
  2632. } else {
  2633. /*
  2634. It could be that here something different is required.
  2635. */
  2636. $buffer = mysql_real_escape_string(trim($buffer));
  2637. }
  2638. fclose($fp);
  2639. /* ** */
  2640. #list($width, $height) = getimagesize($_FILES[$this->fields[$i]['name']]['tmp_name']);
  2641. $newwidth = 100; // $width * $percent;
  2642. $newheight = 100; //$height * $percent;
  2643. $thumb = imagecreatetruecolor($newwidth, $newheight);
  2644. $source = imagecreatefromjpeg($_FILES[$this->fields[$i]['name']]['tmp_name']);
  2645. // Resize
  2646. imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  2647. imagejpeg($thumb,$_FILES[$this->fields[$i]['name']]['tmp_name']);
  2648. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  2649. $buffer_thumb = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  2650. /* ** */
  2651. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}='{$buffer}'";
  2652. $query .= ", {$this->fields[$i]['name']}_thumb='{$buffer_thumb}}'";
  2653. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  2654. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  2655. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  2656. }
  2657. }
  2658. break;
  2659. case POSITION:
  2660. $query .= aux::first_comma("addItem".$this->name,", ").
  2661. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2662. $this->positions[$this->fields[$i]['name']]['index'] = $i;
  2663. $this->positions[$this->fields[$i]['name']]['all'] = $_REQUEST["{$this->fields[$i]['name']}_all"];
  2664. $this->positions[$this->fields[$i]['name']]['value'] = $this->fields[$i]['value'];
  2665. #echo "edit ", $_REQUEST["{$this->fields[$i]['name']}_all"];
  2666. break;
  2667. case PASSWORD:
  2668. if ((isset($this->fields[$i]['value'])) and ($this->fields[$i]['value'] != "")) {
  2669. $query .= aux::first_comma("addItem".$this->name,", ")."{$this->fields[$i]['name']}=MD5('{$this->fields[$i]['value']}')";
  2670. }
  2671. break;
  2672. default:
  2673. /* HTMLENTITIES */
  2674. if (!isset($this->fields[$i]['value'])) {
  2675. $this->fields[$i]['value'] = "";
  2676. }
  2677. $query .= aux::first_comma("addItem".$this->name,", ").
  2678. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2679. break;
  2680. }
  2681. }
  2682. }
  2683. $query .= " WHERE {$this->fields[0]['name']}='{$_REQUEST[$this->fields[0]['name']]}'";
  2684. $oid = mysql_query($query);
  2685. if (!$oid) {
  2686. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_QUERY)." (".basename(__FILE__).":".__LINE__.")";
  2687. echo mysql_error();
  2688. echo "<hr>";
  2689. echo $query;
  2690. exit;
  2691. }
  2692. if (count($this->positions) > 0) {
  2693. $insert_id = $_REQUEST[$this->fields[0]['name']];
  2694. foreach($this->positions as $position_key => $position_value) {
  2695. $positions = explode(":", $position_value['all']);
  2696. array_pop($positions);
  2697. foreach($positions as $single_key => $single_value) {
  2698. if ($single_value == 0) {
  2699. $id = $insert_id;
  2700. } else {
  2701. $id = $single_value;
  2702. }
  2703. $position = $single_key+1;
  2704. $query = "UPDATE {$this->name} SET {$position_key} = {$position} WHERE {$this->fields[0]['name']} = '{$id}'";
  2705. #echo "{$query}<br>";
  2706. $oid = mysql_query($query);
  2707. if (!$oid) {
  2708. return false;
  2709. }
  2710. }
  2711. }
  2712. } // if(count..)
  2713. $GLOBALS['logEntity']->insertItem(NULL,
  2714. 'EDIT',
  2715. $this->name,
  2716. $_REQUEST[$this->fields[0]['name']],
  2717. basename($_SERVER['SCRIPT_FILENAME']),
  2718. $_SESSION['user']['username'],
  2719. date("YmdHi"),
  2720. $_SERVER['HTTP_HOST']
  2721. );
  2722. $GLOBALS['becontent']->clearCache(HTML_IMG);
  2723. if (!$oid) {
  2724. return false;
  2725. } else {
  2726. return true;
  2727. }
  2728. } // editItem
  2729. /**
  2730. * Version 2 of editItem()
  2731. *
  2732. * @return bool
  2733. */
  2734. function editItem2() {
  2735. $query = "UPDATE {$this->name} SET ";
  2736. for($i=1; $i<count($this->fields); $i++) {
  2737. $_REQUEST[$this->fields[$i]['name']] = htmlentities($_REQUEST[$this->fields[$i]['name']]);
  2738. if ($this->addslashes) {
  2739. if (isset($_REQUEST[$this->fields[$i]['name']])) {
  2740. $this->fields[$i]['value'] = addslashes($_REQUEST[$this->fields[$i]['name']]);
  2741. }
  2742. } else {
  2743. if (isset($_REQUEST[$this->fields[$i]['name']])) {
  2744. $this->fields[$i]['value'] = $_REQUEST[$this->fields[$i]['name']];
  2745. }
  2746. }
  2747. if (array_key_exists($this->fields[$i]['name'],$_REQUEST)) {
  2748. switch ($this->fields[$i]['type']) {
  2749. case "DATE":
  2750. $date = explode("/",$this->fields[$i]['value']);
  2751. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  2752. $query .= aux::first_comma("addItem".$this->name,", ").
  2753. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2754. break;
  2755. case LONGDATE:
  2756. $date = explode("/",$this->fields[$i]['value']);
  2757. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  2758. $time = explode(":", $_REQUEST[$this->fields[$i]['name']."_time"]);
  2759. $this->fields[$i]['value'] .= $time[0].$time[1];
  2760. $query .= aux::first_comma("addItem".$this->name,", ").
  2761. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2762. break;
  2763. case FILE:
  2764. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  2765. $query .= ", {$this->fields[$i]['name']}=''";
  2766. $query .= ", {$this->fields[$i]['name']}_filename=''";
  2767. $query .= ", {$this->fields[$i]['name']}_size=''";
  2768. $query .= ", {$this->fields[$i]['name']}_type=''";
  2769. } else {
  2770. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  2771. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  2772. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  2773. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  2774. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  2775. $buffer = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  2776. if ($this->addslashes) {
  2777. $filename = addslashes($filename);
  2778. } else {
  2779. #$buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  2780. }
  2781. if (get_magic_quotes_gpc()) {
  2782. /*
  2783. Here instead of trim one should use stripslashes but doesn't work.
  2784. */
  2785. $buffer = mysql_real_escape_string(trim($buffer));
  2786. } else {
  2787. /*
  2788. It could be that here something different is required.
  2789. */
  2790. $buffer = mysql_real_escape_string(trim($buffer));
  2791. }
  2792. fclose($fp);
  2793. $query .= ", {$this->fields[$i]['name']}='{$buffer}'";
  2794. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  2795. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  2796. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  2797. }
  2798. } // else
  2799. break;
  2800. case FILE2FOLDER:
  2801. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  2802. if (file_exists("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}")) {
  2803. unlink("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}");
  2804. }
  2805. $query .= ", {$this->fields[$i]['name']}_reference = ''";
  2806. $query .= ", {$this->fields[$i]['name']}_filename = ''";
  2807. $query .= ", {$this->fields[$i]['name']}_size = ''";
  2808. $query .= ", {$this->fields[$i]['name']}_type = ''";
  2809. } else {
  2810. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  2811. if ($_REQUEST[$this->fields[$i]['name']."_reference"] != "") {
  2812. if (file_exists("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}")) {
  2813. unlink("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}");
  2814. }
  2815. }
  2816. $filename_local = md5(uniqid(time()));
  2817. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  2818. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  2819. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  2820. if (ereg("\.([[:alnum:]]*)$", $filename, $token)) {
  2821. if (isset($this->fields[$i]['exts'][$token[1]])) {
  2822. if ($this->fields[$i]['exts'][$token[1]] == AUTO) {
  2823. $extension = ".{$token[1]}";
  2824. } else {
  2825. $extension = ".{$this->fields[$i]['exts'][$token[1]]}";
  2826. }
  2827. } else {
  2828. $extension = "";
  2829. }
  2830. }
  2831. $filename_local = $filename_local.$extension;
  2832. move_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'], $GLOBALS['config']['upload_folder']."/$filename_local");
  2833. if ($this->addslashes) {
  2834. $filename = addslashes($filename);
  2835. }
  2836. $query .= ", {$this->fields[$i]['name']}_reference='{$filename_local}'";
  2837. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  2838. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  2839. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  2840. }
  2841. } // else
  2842. break;
  2843. case "IMAGE":
  2844. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  2845. $query .= ", {$this->fields[$i]['name']}=''";
  2846. $query .= ", {$this->fields[$i]['name']}_thumb=''";
  2847. $query .= ", {$this->fields[$i]['name']}_filename=''";
  2848. $query .= ", {$this->fields[$i]['name']}_size=''";
  2849. $query .= ", {$this->fields[$i]['name']}_type=''";
  2850. } else {
  2851. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  2852. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  2853. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  2854. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  2855. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  2856. $buffer = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  2857. if ($this->addslashes) {
  2858. $filename = addslashes($filename);
  2859. } else {
  2860. #$buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  2861. }
  2862. if (get_magic_quotes_gpc()) {
  2863. /*
  2864. Here instead of trim one should use stripslashes but doesn't work.
  2865. */
  2866. $buffer = mysql_real_escape_string(trim($buffer));
  2867. } else {
  2868. /*
  2869. It could be that here something different is required.
  2870. */
  2871. $buffer = mysql_real_escape_string(trim($buffer));
  2872. }
  2873. fclose($fp);
  2874. /* ** */
  2875. #list($width, $height) = getimagesize($_FILES[$this->fields[$i]['name']]['tmp_name']);
  2876. $newwidth = 100; // $width * $percent;
  2877. $newheight = 100; //$height * $percent;
  2878. $thumb = imagecreatetruecolor($newwidth, $newheight);
  2879. $source = imagecreatefromjpeg($_FILES[$this->fields[$i]['name']]['tmp_name']);
  2880. // Resize
  2881. imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  2882. imagejpeg($thumb,$_FILES[$this->fields[$i]['name']]['tmp_name']);
  2883. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  2884. $buffer_thumb = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  2885. $query .= ", {$this->fields[$i]['name']}='{$buffer}'";
  2886. $query .= ". {$this->fields[$i]['name']}_thumb='{$buffer_thumb}}'";
  2887. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  2888. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  2889. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  2890. }
  2891. }
  2892. break;
  2893. case POSITION:
  2894. $query .= aux::first_comma("addItem".$this->name,", ").
  2895. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2896. $this->positions[$this->fields[$i]['name']]['index'] = $i;
  2897. $this->positions[$this->fields[$i]['name']]['all'] = $_REQUEST["{$this->fields[$i]['name']}_all"];
  2898. $this->positions[$this->fields[$i]['name']]['value'] = $this->fields[$i]['value'];
  2899. #echo "edit ", $_REQUEST["{$this->fields[$i]['name']}_all"];
  2900. break;
  2901. case PASSWORD:
  2902. # if ($this->fields[$i]['value'] != "") {
  2903. if (isset($this->fields[$i]['value'])) {
  2904. $query .= aux::first_comma("addItem".$this->name,", ").
  2905. "{$this->fields[$i]['name']}=MD5('{$this->fields[$i]['value']}')";
  2906. }
  2907. break;
  2908. default:
  2909. /* HTMLENTITIES */
  2910. #$this->fields[$i]['value'] = htmlentities($this->fields[$i]['value']);
  2911. if (!isset($this->fields[$i]['value'])) {
  2912. $this->fields[$i]['value'] = "";
  2913. }
  2914. $query .= aux::first_comma("addItem".$this->name,", ").
  2915. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2916. break;
  2917. } // switch
  2918. } // if
  2919. } // for
  2920. $query .= " WHERE {$this->fields[0]['name']}='{$_REQUEST[$this->fields[0]['name']]}'";
  2921. $oid = mysql_query($query);
  2922. if (!$oid) {
  2923. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_QUERY)." (".basename(__FILE__).":".__LINE__.")";
  2924. echo mysql_error();
  2925. echo "<hr>";
  2926. echo $query;
  2927. exit;
  2928. }
  2929. if (count($this->positions) > 0) {
  2930. $insert_id = $_REQUEST[$this->fields[0]['name']];
  2931. foreach($this->positions as $position_key => $position_value) {
  2932. /* Warning: this must be tested, in other words the editItem() function has been
  2933. modified in order to have forms with only part of the fields of the entity, and as
  2934. such also position widgets can be included or excluded - the following should be executed
  2935. only if the position widget is in the form.
  2936. */
  2937. if (array_key_exists($position_key, $_REQUEST)) {
  2938. $positions = explode(":", $position_value['all']);
  2939. array_pop($positions);
  2940. foreach($positions as $single_key => $single_value) {
  2941. if ($single_value == 0) {
  2942. $id = $insert_id;
  2943. } else {
  2944. $id = $single_value;
  2945. }
  2946. $position = $single_key+1;
  2947. $query = "UPDATE {$this->name} SET {$position_key} = {$position} WHERE {$this->fields[0]['name']} = '{$id}'";
  2948. #echo "{$query}<br>";
  2949. $oid = mysql_query($query);
  2950. if (!$oid) {
  2951. return false;
  2952. }
  2953. }
  2954. }
  2955. } // foreach
  2956. } // if
  2957. if (!$oid) {
  2958. return false;
  2959. } else {
  2960. return true;
  2961. }
  2962. } // editItem2
  2963. /**
  2964. * Version 3 editItem()
  2965. *
  2966. * @return bool
  2967. */
  2968. function editItem3() {
  2969. $query = "UPDATE {$this->name} SET ";
  2970. for($i=1; $i<count($this->fields); $i++) {
  2971. $_REQUEST[$this->fields[$i]['name']] = htmlentities($_REQUEST[$this->fields[$i]['name']]);
  2972. if ($this->addslashes) {
  2973. if (isset($_REQUEST[$this->fields[$i]['name']])) {
  2974. $this->fields[$i]['value'] = addslashes($_REQUEST[$this->fields[$i]['name']]);
  2975. }
  2976. } else {
  2977. if (isset($_REQUEST[$this->fields[$i]['name']])) {
  2978. $this->fields[$i]['value'] = $_REQUEST[$this->fields[$i]['name']];
  2979. }
  2980. }
  2981. if (array_key_exists($this->fields[$i]['name'],$_REQUEST)) {
  2982. switch ($this->fields[$i]['type']) {
  2983. case "DATE":
  2984. $date = explode("/",$this->fields[$i]['value']);
  2985. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  2986. $query .= aux::first_comma("addItem".$this->name,", ").
  2987. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2988. break;
  2989. case LONGDATE:
  2990. $date = explode("/",$this->fields[$i]['value']);
  2991. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  2992. $time = explode(":", $_REQUEST[$this->fields[$i]['name']."_time"]);
  2993. $this->fields[$i]['value'] .= $time[0].$time[1];
  2994. $query .= aux::first_comma("addItem".$this->name,", ").
  2995. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  2996. break;
  2997. case FILE:
  2998. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  2999. $query .= ", {$this->fields[$i]['name']}=''";
  3000. $query .= ", {$this->fields[$i]['name']}_filename=''";
  3001. $query .= ", {$this->fields[$i]['name']}_size=''";
  3002. $query .= ", {$this->fields[$i]['name']}_type=''";
  3003. } else {
  3004. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  3005. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  3006. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  3007. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  3008. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  3009. $buffer = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3010. if ($this->addslashes) {
  3011. $filename = addslashes($filename);
  3012. } else {
  3013. #$buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3014. }
  3015. if (get_magic_quotes_gpc()) {
  3016. /*
  3017. Here instead of trim one should use stripslashes but doesn't work.
  3018. */
  3019. $buffer = mysql_real_escape_string(trim($buffer));
  3020. } else {
  3021. /*
  3022. It could be that here something different is required.
  3023. */
  3024. $buffer = mysql_real_escape_string(trim($buffer));
  3025. }
  3026. fclose($fp);
  3027. $query .= ", {$this->fields[$i]['name']}='{$buffer}'";
  3028. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  3029. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  3030. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  3031. }
  3032. }
  3033. break;
  3034. case FILE2FOLDER:
  3035. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  3036. if (file_exists("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}")) {
  3037. unlink("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}");
  3038. }
  3039. $query .= ", {$this->fields[$i]['name']}_reference = ''";
  3040. $query .= ", {$this->fields[$i]['name']}_filename = ''";
  3041. $query .= ", {$this->fields[$i]['name']}_size = ''";
  3042. $query .= ", {$this->fields[$i]['name']}_type = ''";
  3043. } else {
  3044. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  3045. if ($_REQUEST[$this->fields[$i]['name']."_reference"] != "") {
  3046. if (file_exists("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}")) {
  3047. unlink("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$this->fields[$i]['name']."_reference"]}");
  3048. }
  3049. }
  3050. $filename_local = md5(uniqid(time()));
  3051. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  3052. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  3053. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  3054. if (ereg("\.([[:alnum:]]*)$", $filename, $token)) {
  3055. if (isset($this->fields[$i]['exts'][$token[1]])) {
  3056. if ($this->fields[$i]['exts'][$token[1]] == AUTO) {
  3057. $extension = ".{$token[1]}";
  3058. } else {
  3059. $extension = ".{$this->fields[$i]['exts'][$token[1]]}";
  3060. }
  3061. } else {
  3062. $extension = "";
  3063. }
  3064. }
  3065. $filename_local = $filename_local.$extension;
  3066. move_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'], $GLOBALS['config']['upload_folder']."/$filename_local");
  3067. if ($this->addslashes) {
  3068. $filename = addslashes($filename);
  3069. }
  3070. $query .= ", {$this->fields[$i]['name']}_reference='{$filename_local}'";
  3071. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  3072. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  3073. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  3074. }
  3075. }
  3076. break;
  3077. case "IMAGE":
  3078. if ($_REQUEST[$this->fields[$i]['name']."_delete"]) {
  3079. $query .= ", {$this->fields[$i]['name']}=''";
  3080. $query .= ", {$this->fields[$i]['name']}_thumb=''";
  3081. $query .= ", {$this->fields[$i]['name']}_filename=''";
  3082. $query .= ", {$this->fields[$i]['name']}_size=''";
  3083. $query .= ", {$this->fields[$i]['name']}_type=''";
  3084. } else {
  3085. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  3086. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  3087. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  3088. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  3089. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  3090. $buffer = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3091. if ($this->addslashes) {
  3092. $filename = addslashes($filename);
  3093. } else {
  3094. #$buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3095. }
  3096. if (get_magic_quotes_gpc()) {
  3097. /*
  3098. Here instead of trim one should use stripslashes but doesn't work.
  3099. */
  3100. $buffer = mysql_real_escape_string(trim($buffer));
  3101. } else {
  3102. /*
  3103. It could be that here something different is required.
  3104. */
  3105. $buffer = mysql_real_escape_string(trim($buffer));
  3106. }
  3107. fclose($fp);
  3108. /* ** */
  3109. #list($width, $height) = getimagesize($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3110. $newwidth = 100; // $width * $percent;
  3111. $newheight = 100; //$height * $percent;
  3112. $thumb = imagecreatetruecolor($newwidth, $newheight);
  3113. $source = imagecreatefromjpeg($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3114. // Resize
  3115. imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  3116. imagejpeg($thumb,$_FILES[$this->fields[$i]['name']]['tmp_name']);
  3117. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  3118. $buffer_thumb = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3119. /* ** */
  3120. $query .= ", {$this->fields[$i]['name']}='{$buffer}'";
  3121. $query .= ". {$this->fields[$i]['name']}_thumb='{$buffer_thumb}}'";
  3122. $query .= ", {$this->fields[$i]['name']}_filename='{$filename}'";
  3123. $query .= ", {$this->fields[$i]['name']}_size='{$filesize}'";
  3124. $query .= ", {$this->fields[$i]['name']}_type='{$filetype}'";
  3125. }
  3126. }
  3127. break;
  3128. case POSITION:
  3129. $query .= aux::first_comma("addItem".$this->name,", ").
  3130. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  3131. $this->positions[$this->fields[$i]['name']]['index'] = $i;
  3132. $this->positions[$this->fields[$i]['name']]['all'] = $_REQUEST["{$this->fields[$i]['name']}_all"];
  3133. $this->positions[$this->fields[$i]['name']]['value'] = $this->fields[$i]['value'];
  3134. #echo "edit ", $_REQUEST["{$this->fields[$i]['name']}_all"];
  3135. break;
  3136. case PASSWORD:
  3137. # if ($this->fields[$i]['value'] != "") {
  3138. if (isset($this->fields[$i]['value'])) {
  3139. $query .= aux::first_comma("addItem".$this->name,", ").
  3140. "{$this->fields[$i]['name']}=MD5('{$this->fields[$i]['value']}')";
  3141. }
  3142. break;
  3143. default:
  3144. /* HTMLENTITIES */
  3145. #$this->fields[$i]['value'] = htmlentities($this->fields[$i]['value']);
  3146. if (!isset($this->fields[$i]['value'])) {
  3147. $this->fields[$i]['value'] = "";
  3148. }
  3149. $query .= aux::first_comma("addItem".$this->name,", ").
  3150. "{$this->fields[$i]['name']}='{$this->fields[$i]['value']}'";
  3151. break;
  3152. }
  3153. }
  3154. }
  3155. $query .= " WHERE {$this->fields[0]['name']}='{$_REQUEST[$this->fields[0]['name']]}'";
  3156. $oid = mysql_query($query);
  3157. if (!$oid) {
  3158. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_QUERY)." (".basename(__FILE__).":".__LINE__.")";
  3159. echo mysql_error();
  3160. echo "<hr>";
  3161. echo $query;
  3162. exit;
  3163. }
  3164. if (count($this->positions) > 0) {
  3165. $insert_id = $_REQUEST[$this->fields[0]['name']];
  3166. foreach($this->positions as $position_key => $position_value) {
  3167. /* Warning: this must be tested, in other words the editItem() function has been
  3168. modified in order to have forms with only part of the fields of the entity, and as
  3169. such also position widgets can be included or excluded - the following should be executed
  3170. only if the position widget is in the form.
  3171. */
  3172. if (array_key_exists($position_key, $_REQUEST)) {
  3173. $positions = explode(":", $position_value['all']);
  3174. array_pop($positions);
  3175. foreach($positions as $single_key => $single_value) {
  3176. if ($single_value == 0) {
  3177. $id = $insert_id;
  3178. } else {
  3179. $id = $single_value;
  3180. }
  3181. $position = $single_key+1;
  3182. $query = "UPDATE {$this->name} SET {$position_key} = {$position} WHERE {$this->fields[0]['name']} = '{$id}'";
  3183. #echo "{$query}<br>";
  3184. $oid = mysql_query($query);
  3185. if (!$oid) {
  3186. return false;
  3187. }
  3188. }
  3189. }
  3190. }
  3191. }
  3192. if (!$oid) {
  3193. return false;
  3194. } else {
  3195. return true;
  3196. }
  3197. }
  3198. /**
  3199. * Performs the insert action of the entity in the DB.
  3200. *
  3201. * @return unknown
  3202. */
  3203. function addItem() {
  3204. $session_id_name = "S_".md5($this->name);
  3205. if (($_REQUEST[$session_id_name] == $_SESSION[$session_id_name])) {
  3206. $_SESSION[$session_id_name] = "*";
  3207. } else {
  3208. $this->reload = true;
  3209. return false;
  3210. }
  3211. // init query
  3212. $query = "INSERT INTO {$this->name} VALUES(";
  3213. if ($this->owner) {
  3214. $_REQUEST['creation'] = date('YmdHi');
  3215. $_REQUEST['lastModified'] = date('YmdHi');
  3216. }
  3217. $commaId = md5(microtime());
  3218. if (($this->standardKey) and ($this->fields[0]['primary key'])) {
  3219. $query .= aux::first_comma($commaId,", ")."NULL";
  3220. for($i=1; $i<count($this->fields); $i++) {
  3221. /* HTML ENTITIES ? */
  3222. #$_REQUEST[$this->fields[$i]['name']] = htmlentities($_REQUEST[$this->fields[$i]['name']]);
  3223. if ($this->addslashes) {
  3224. if (isset($_REQUEST[$this->fields[$i]['name']])) {
  3225. $this->fields[$i]['value'] = addslashes($_REQUEST[$this->fields[$i]['name']]);
  3226. }
  3227. } else {
  3228. if (isset($_REQUEST[$this->fields[$i]['name']])) {
  3229. $this->fields[$i]['value'] = $_REQUEST[$this->fields[$i]['name']];
  3230. }
  3231. }
  3232. switch ($this->fields[$i]['type']) {
  3233. case "DATE":
  3234. $date = explode("/",$this->fields[$i]['value']);
  3235. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  3236. $query .= aux::first_comma($commaId,", ")."'{$this->fields[$i]['value']}'";
  3237. break;
  3238. case LONGDATE:
  3239. $date = explode("/",$this->fields[$i]['value']);
  3240. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  3241. $time = explode(":", $_REQUEST[$this->fields[$i]['name']."_time"]);
  3242. $this->fields[$i]['value'] .= $time[0].$time[1];
  3243. $query .= aux::first_comma($commaId,", ")."'{$this->fields[$i]['value']}'";
  3244. break;
  3245. case FILE:
  3246. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  3247. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  3248. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  3249. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  3250. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  3251. $buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3252. /*
  3253. if ($this->addslashes) {
  3254. $buffer = addslashes(file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3255. } else {
  3256. $buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3257. }
  3258. */
  3259. #$buffer = aux::quote_smart(file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3260. if (get_magic_quotes_gpc()) {
  3261. /*
  3262. Here instead of trim one should use stripslashes but doesn't work.
  3263. */
  3264. $buffer = mysql_real_escape_string(trim($buffer));
  3265. } else {
  3266. /*
  3267. It could be that here something different is required.
  3268. */
  3269. $buffer = mysql_real_escape_string(trim($buffer));
  3270. }
  3271. fclose($fp);
  3272. } else {
  3273. $buffer = "";
  3274. $filename = "";
  3275. $filezize = 0;
  3276. $filetype = "";
  3277. }
  3278. $buffer = (isset($buffer)) ? $buffer:"";
  3279. $query .= aux::first_comma($commaId,", ")."'{$buffer}'";
  3280. $filename = (isset($filename)) ? $filename:"";
  3281. $query .= aux::first_comma($commaId,", ")."'{$filename}'";
  3282. $filesize = (isset($filesize)) ? $filesize:"";
  3283. $query .= aux::first_comma($commaId,", ")."'{$filesize}'";
  3284. $filetype = (isset($filetype)) ? $filetype:"";
  3285. $query .= aux::first_comma($commaId,", ")."'{$filetype}'";
  3286. break;
  3287. case FILE2FOLDER:
  3288. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  3289. $filename_local = md5(uniqid(time()));
  3290. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  3291. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  3292. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  3293. if (ereg("\.([[:alnum:]]*)$", $filename, $token)) {
  3294. if (isset($this->fields[$i]['exts'][$token[1]])) {
  3295. if ($this->fields[$i]['exts'][$token[1]] == AUTO) {
  3296. $extension = ".{$token[1]}";
  3297. } else {
  3298. $extension = ".{$this->fields[$i]['exts'][$token[1]]}";
  3299. }
  3300. } else {
  3301. $extension = "";
  3302. }
  3303. }
  3304. $filename_local = $filename_local.$extension;
  3305. move_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'], "{$GLOBALS['config']['upload_folder']}/{$filename_local}");
  3306. } else {
  3307. $filename_local = "";
  3308. $filename = "";
  3309. $filesize = 0;
  3310. $filetype = "";
  3311. }
  3312. $query .= aux::first_comma($commaId,", ")."'{$filename_local}'";
  3313. $filename = (isset($filename)) ? $filename:"";
  3314. $query .= aux::first_comma($commaId,", ")."'{$filename}'";
  3315. $filesize = (isset($filesize)) ? $filesize:"";
  3316. $query .= aux::first_comma($commaId,", ")."'{$filesize}'";
  3317. $filetype = (isset($filetype)) ? $filetype:"";
  3318. $query .= aux::first_comma($commaId,", ")."'{$filetype}'";
  3319. break;
  3320. case "IMAGE":
  3321. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  3322. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  3323. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  3324. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  3325. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  3326. $buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3327. if (get_magic_quotes_gpc()) {
  3328. /*
  3329. Here instead of trim one should use stripslashes but doesn't work.
  3330. */
  3331. $buffer = mysql_real_escape_string(trim($buffer));
  3332. } else {
  3333. /*
  3334. It could be that here something different is required.
  3335. */
  3336. $buffer = mysql_real_escape_string(trim($buffer));
  3337. }
  3338. fclose($fp);
  3339. }
  3340. /* ** */
  3341. list($width, $height) = getimagesize($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3342. $newwidth = 100; // $width * $percent;
  3343. $newheight = 100; //$height * $percent;
  3344. $thumb = imagecreatetruecolor($newwidth, $newheight);
  3345. $source = imagecreatefromjpeg($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3346. // Resize
  3347. imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  3348. /* $buffer = imagejpeg($thumb); */
  3349. $buffer = (isset($buffer)) ? $buffer:"";
  3350. $query .= aux::first_comma($commaId,", ")."'{$buffer}'";
  3351. /* Thumb */
  3352. $buffer = imagejpeg($thumb);
  3353. $buffer = (isset($buffer)) ? $buffer:"";
  3354. $query .= aux::first_comma($commaId,", ")."'{$buffer}'";
  3355. $filename = (isset($filename)) ? $filename:"";
  3356. $query .= aux::first_comma($commaId,", ")."'{$filename}'";
  3357. $filesize = (isset($filesize)) ? $filesize:"";
  3358. $query .= aux::first_comma($commaId,", ")."'{$filesize}'";
  3359. $filetype = (isset($filetype)) ? $filetype:"";
  3360. $query .= aux::first_comma($commaId,", ")."'{$filetype}'";
  3361. break;
  3362. case "POSITION":
  3363. $query .= aux::first_comma($commaId,", ")."'{$this->fields[$i]['value']}'";
  3364. $this->positions[$this->fields[$i]['name']]['index'] = $i;
  3365. $this->positions[$this->fields[$i]['name']]['all'] = $_REQUEST["{$this->fields[$i]['name']}_all"];
  3366. $this->positions[$this->fields[$i]['name']]['value'] = $this->fields[$i]['value'];
  3367. break;
  3368. case "PASSWORD":
  3369. #$query .= aux::first_comma("addItem".$this->name,", ")."MD5('{$this->fields[$i]['value']}')";
  3370. $query .= aux::first_comma($commaId,", ")."MD5('{$this->fields[$i]['value']}')";
  3371. break;
  3372. default:
  3373. /*
  3374. The following add a field for all the other cases, including the case WITH_OWNER
  3375. where the username in the session is added
  3376. 4/08/2008 - a variant is added for the WITH_OWNER case in order to deal with the
  3377. case in which
  3378. - the logged user is an administrator, and
  3379. - the manager-script for the WITH_OWNER-entity allows administrator to choose
  3380. the user for the owner
  3381. */
  3382. if (isset($this->fields[$i]['owner'])) {
  3383. /* the user is admin and the script has an selectfromreference for user */
  3384. if (($_SESSION['user']['admin']) and (isset($this->fields[$i]['value']))) {
  3385. $query .= aux::first_comma($commaId,", ")."'{$this->fields[$i]['value']}'";
  3386. } else {
  3387. $query .= aux::first_comma($commaId,", ")."'{$_SESSION['user']['username']}'";
  3388. }
  3389. } else {
  3390. if (!isset($this->fields[$i]['value'])) {
  3391. $this->fields[$i]['value'] = "";
  3392. }
  3393. $query .= aux::first_comma($commaId,", ")."'{$this->fields[$i]['value']}'";
  3394. }
  3395. break;
  3396. }
  3397. }
  3398. } else {
  3399. for($i=0; $i<count($this->fields); $i++) {
  3400. /* HTML ENTITIES ? */
  3401. #$_REQUEST[$this->fields[$i]['name']] = htmlentities($_REQUEST[$this->fields[$i]['name']]);
  3402. if ($this->addslashes) {
  3403. $this->fields[$i]['value'] = addslashes($_REQUEST[$this->fields[$i]['name']]);
  3404. } else {
  3405. $this->fields[$i]['value'] = $_REQUEST[$this->fields[$i]['name']];
  3406. }
  3407. #echo "<br>** ",$this->fields[$i]['type'];
  3408. switch ($this->fields[$i]['type']) {
  3409. case "DATE":
  3410. $date = explode("/",$this->fields[$i]['value']);
  3411. $this->fields[$i]['value'] = $date[2].$date[1].$date[0];
  3412. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$this->fields[$i]['value']}'";
  3413. $query .= aux::first_comma($commaId,", ")."'{$this->fields[$i]['value']}'";
  3414. break;
  3415. case FILE:
  3416. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  3417. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  3418. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  3419. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  3420. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  3421. #$buffer = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3422. if ($this->addslashes) {
  3423. $buffer = addslashes(file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3424. } else {
  3425. $buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3426. }
  3427. fclose($fp);
  3428. }
  3429. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$buffer}'";
  3430. $query .= aux::first_comma($commaId,", ")."'{$buffer}'";
  3431. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$filename}'";
  3432. $query .= aux::first_comma($commaId,", ")."'{$filename}'";
  3433. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$filesize}'";
  3434. $query .= aux::first_comma($commaId,", ")."'{$filesize}'";
  3435. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$filetype}'";
  3436. $query .= aux::first_comma($commaId,", ")."'{$filetype}'";
  3437. break;
  3438. case "IMAGE":
  3439. if (is_uploaded_file($_FILES[$this->fields[$i]['name']]['tmp_name'])) {
  3440. $filename = $_FILES[$this->fields[$i]['name']]['name'];
  3441. $filesize = $_FILES[$this->fields[$i]['name']]['size'];
  3442. $filetype = $_FILES[$this->fields[$i]['name']]['type'];
  3443. $fp = fopen($_FILES[$this->fields[$i]['name']]['tmp_name'],"r");
  3444. #$buffer = fread($fp, filesize($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3445. if ($this->addslashes) {
  3446. $buffer = addslashes(file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']));
  3447. } else {
  3448. $buffer = file_get_contents($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3449. }
  3450. fclose($fp);
  3451. }
  3452. /* ** */
  3453. list($width, $height) = getimagesize($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3454. $newwidth = 100; // $width * $percent;
  3455. $newheight = 100; //$height * $percent;
  3456. $thumb = imagecreatetruecolor($newwidth, $newheight);
  3457. $source = imagecreatefromjpeg($_FILES[$this->fields[$i]['name']]['tmp_name']);
  3458. // Resize
  3459. imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  3460. /* $buffer = imagejpeg($thumb); */
  3461. /* ** */
  3462. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$buffer}'";
  3463. $query .= aux::first_comma($commaId,", ")."'{$buffer}'";
  3464. /* THUMB */
  3465. $buffer = imagejpeg($thumb);
  3466. $query .= aux::first_comma($commaId,", ")."'{$buffer}'";
  3467. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$filename}'";
  3468. $query .= aux::first_comma($commaId,", ")."'{$filename}'";
  3469. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$filesize}'";
  3470. $query .= aux::first_comma($commaId,", ")."'{$filesize}'";
  3471. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$filetype}'";
  3472. $query .= aux::first_comma($commaId,", ")."'{$filetype}'";
  3473. break;
  3474. case "POSITION":
  3475. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$this->fields[$i]['value']}'";
  3476. $query .= aux::first_comma($commaId,", ")."'{$this->fields[$i]['value']}'";
  3477. $this->positions[$this->fields[$i]['name']]['index'] = $i;
  3478. $this->positions[$this->fields[$i]['name']]['all'] = $_REQUEST["{$this->fields[$i]['name']}_all"];
  3479. $this->positions[$this->fields[$i]['name']]['value'] = $this->fields[$i]['value'];
  3480. break;
  3481. case "PASSWORD":
  3482. #$query .= aux::first_comma("addItem".$this->name,", ")."MD5('{$this->fields[$i]['value']}')";
  3483. $query .= aux::first_comma($commaId,", ")."MD5('{$this->fields[$i]['value']}')";
  3484. break;
  3485. default:
  3486. /* the following add a field for all the other cases, including the case WITH_OWNER
  3487. where the username in the session is added */
  3488. if (isset($this->fields[$i]['owner'])) {
  3489. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$_SESSION['user']['username']}'";
  3490. $query .= aux::first_comma($commaId,", ")."'{$_SESSION['user']['username']}'";
  3491. } else {
  3492. $this->fields[$i]['value'] = htmlentities($this->fields[$i]['value']);
  3493. #$query .= aux::first_comma("addItem".$this->name,", ")."'{$this->fields[$i]['value']}'";
  3494. $query .= aux::first_comma($commaId,", ")."'{$this->fields[$i]['value']}'";
  3495. }
  3496. break;
  3497. }
  3498. }
  3499. }
  3500. $query .= ")";
  3501. $oid = mysql_query($query);
  3502. if (!$oid) {
  3503. /*
  3504. There was a problem in executing the query, the function is
  3505. returning FALSE, the error will be handled by the wrapper (very
  3506. likely is a duplicate_key error).
  3507. */
  3508. return false;
  3509. } else {
  3510. $_REQUEST['insertid'] = mysql_insert_id();
  3511. $GLOBALS['logEntity']->insertItem(NULL,
  3512. 'ADD',
  3513. $this->name,
  3514. $_REQUEST['insertid'],
  3515. basename($_SERVER['SCRIPT_FILENAME']),
  3516. $_SESSION['user']['username'],
  3517. date("YmdHi"),
  3518. $_SERVER['HTTP_HOST']);
  3519. $GLOBALS['becontent']->clearCache(HTML_IMG);
  3520. if (count($this->positions) > 0) {
  3521. $insert_id = $_REQUEST['insertid'];
  3522. foreach($this->positions as $position_key => $position_value) {
  3523. $positions = explode(":", $position_value['all']);
  3524. array_pop($positions);
  3525. foreach($positions as $single_key => $single_value) {
  3526. if ($single_value == 0) {
  3527. /* there is a problem here ! */
  3528. $id = $insert_id;
  3529. } else {
  3530. $id = $single_value;
  3531. }
  3532. $position = $single_key+1;
  3533. $query = "UPDATE {$this->name} SET {$position_key} = {$position} WHERE {$this->fields[0]['name']} = '{$id}'";
  3534. $oid = mysql_query($query);
  3535. if (!$oid) {
  3536. return false;
  3537. }
  3538. }
  3539. }
  3540. $this->addItem_postInsertion();
  3541. return true; // specify better
  3542. } else {
  3543. $this->addItem_postInsertion();
  3544. return true;
  3545. }
  3546. }
  3547. }
  3548. /**
  3549. * Returns if Entity is referred or not.
  3550. *
  3551. * @return bool (1 or 0)
  3552. */
  3553. function noReferred() {
  3554. return (count($this->referredBy) == 0);
  3555. }
  3556. function pre_delete() {}
  3557. function post_delete() {}
  3558. function post_delete_success() {}
  3559. function post_delete_failure() {}
  3560. /**
  3561. * Perform deletion of the entity item from the DB.
  3562. * Checks if the entity is deletable or rather if entity is referred
  3563. *
  3564. * @return bool
  3565. */
  3566. function deleteItem() {
  3567. $this->pre_delete();
  3568. $deletable = false;
  3569. if (count($this->referredBy) > 0) {
  3570. $deletable = true;
  3571. foreach($this->referredBy as $k => $v) {
  3572. $currentEntity = $this->name;
  3573. $referredEntity = $k;
  3574. for($i=0; $i<count($v['entity']); $i++) {
  3575. $primaryKey = $this->fields[0]['name'];
  3576. $foreignKey = $v['foreign key'][$i];
  3577. $oid = mysql_query("SELECT IF (T2.{$v['entity'][$i]->fields[0]['name']} IS NULL, '*','') AS referred
  3578. FROM {$this->name} AS T1
  3579. LEFT JOIN {$k} AS T2
  3580. ON T2.{$foreignKey} = T1.{$primaryKey}
  3581. WHERE T1.{$primaryKey} = '{$_REQUEST[$primaryKey]}'");
  3582. /* $oid = mysql_query("SELECT IF ({$k}.{$v['entity'][$i]->fields[0]['name']} IS NULL, '*','') AS referred
  3583. FROM {$this->name}
  3584. LEFT JOIN {$k}
  3585. ON {$k}.{$foreignKey} = {$this->name}.{$primaryKey}
  3586. WHERE {$this->name}.{$primaryKey} = '{$_REQUEST[$primaryKey]}'"); */
  3587. if (!$oid) {
  3588. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_DELETION)." (".basename(__FILE__).":".__LINE__.")";
  3589. exit;
  3590. }
  3591. $data = mysql_fetch_assoc($oid);
  3592. if ($data['referred'] != "*") {
  3593. $deletable = false;
  3594. }
  3595. }
  3596. }
  3597. } else {
  3598. $deletable = true;
  3599. }
  3600. if ($deletable) {
  3601. $index = false;
  3602. foreach($_REQUEST as $k => $v) {
  3603. if (ereg("reference", $k)) {
  3604. $index = $k;
  3605. }
  3606. }
  3607. if (($index != false) and ($_REQUEST[$index] != "")) {
  3608. unlink("{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$index]}");
  3609. }
  3610. $query = "DELETE FROM {$this->name}
  3611. WHERE {$this->fields[0]['name']}='{$_REQUEST[$this->fields[0]['name']]}'";
  3612. $oid = mysql_query($query);
  3613. if (!$oid) {
  3614. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_DELETION)." (".basename(__FILE__).":".__LINE__.")";
  3615. exit;
  3616. }
  3617. /* here goes the code for deleting elements from the relation - but there is a problem
  3618. to delete the information in the relation one has to know what are the relations ...
  3619. */
  3620. if (count($this->relations)>0) {
  3621. foreach($this->relations as $relation) {
  3622. /* if ($this->standardKey) {
  3623. $idName = "id_{$this->name}";
  3624. } else {
  3625. $idName = "username";
  3626. }*/
  3627. /*
  3628. $query = "DELETE FROM {$relation->name}
  3629. WHERE {$this->fields[0]['name']} = '{$_REQUEST[$this->fields[0]['name']]}'";
  3630. */
  3631. /*
  3632. This may cause problems because the field to take into account depends on the
  3633. form oreintation, at least I fear so.
  3634. */
  3635. $query = "DELETE FROM {$relation->name}
  3636. WHERE {$relation->fields[0]['name']} = '{$_REQUEST[$this->fields[0]['name']]}'";
  3637. $oid = mysql_query($query);
  3638. if (!$oid) {
  3639. echo $query;
  3640. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  3641. exit;
  3642. }
  3643. }
  3644. }
  3645. $GLOBALS['logEntity']->insertItem(NULL,
  3646. 'DELETE',
  3647. $this->name,
  3648. $_REQUEST[$this->fields[0]['name']],
  3649. basename($_SERVER['SCRIPT_FILENAME']),
  3650. $_SESSION['user']['username'],
  3651. date("YmdHi"),
  3652. $_SERVER['HTTP_HOST']);
  3653. $GLOBALS['becontent']->clearCache(HTML_IMG);
  3654. $this->post_delete_success();
  3655. return true;
  3656. } else {
  3657. $this->post_delete_failure();
  3658. return false;
  3659. }
  3660. } // deleteItem
  3661. /**
  3662. * This function returns the data contained in the entity according to the
  3663. * presentation given by setPresentation().
  3664. *
  3665. * @param optional parameter BY_POSITION
  3666. * @return data contained in the entity as associative array
  3667. */
  3668. function getPresentation() {
  3669. $id1 = md5(microtime());
  3670. $id2 = md5(microtime());
  3671. $fields = "";
  3672. $fieldsToConcat = "";
  3673. /*if ($this->name == "users") {
  3674. if (strpos($this->presentation[0], "%") === false) {
  3675. echo "false";
  3676. } else {
  3677. echo strpos($this->presentation[0], "%");
  3678. }
  3679. exit;
  3680. }*/
  3681. if (strpos($this->presentation[0], "%") === false) {
  3682. foreach($this->presentation as $value) {
  3683. $fields .= aux::first_comma($id1,", ")."$value";
  3684. foreach($this->fields as $k => $v) {
  3685. if (($v['name'] == $value) and ($v['type'] == DATE)) {
  3686. $value = "DATE_FORMAT({$value},'%d/%m/%Y')";
  3687. }
  3688. }
  3689. $fieldsToConcat .= aux::first_comma($id2,",' ', ")."{$value}";
  3690. }
  3691. } else {
  3692. $presentation = $this->presentation[0];
  3693. $finito = false;
  3694. do {
  3695. $pos = strpos($presentation, "%");
  3696. if ($pos !== false) {
  3697. $value = substr($presentation, 0, $pos);
  3698. $fieldsToConcat .= aux::first_comma($id2,",")."'{$value}'";
  3699. $presentation = substr($presentation, $pos);
  3700. ereg("^\%([[:alnum:]]*)", $presentation, $token);
  3701. $fields .= aux::first_comma($id1,", ").$token[1];
  3702. $fieldsToConcat .= aux::first_comma($id2,",")."{$token[1]}";
  3703. $presentation = substr($presentation, strlen($token[1])+1);
  3704. } else {
  3705. $fieldsToConcat .= aux::first_comma($id2,",")."'{$presentation}'";
  3706. $finito = true;
  3707. }
  3708. } while (!$finito);
  3709. }
  3710. $result['fields'] = $fields;
  3711. $result['fieldsToConcat'] = $fieldsToConcat;
  3712. /*if ($this->name == "users") {
  3713. print_r($result); exit;
  3714. }*/
  3715. return $result;
  3716. }
  3717. /**
  3718. * Checks reference with condition.
  3719. *
  3720. * @param string $condition where condition clause
  3721. * @return array(value,text)
  3722. */
  3723. function getReferenceWithCondition($condition = "true") {
  3724. $presentation = $this->getPresentation();
  3725. $fields = $presentation['fields'];
  3726. $fieldsToConcat = $presentation['fieldsToConcat'];
  3727. if ($this->owner) { // check user owner
  3728. $query = "SELECT {$this->fields[0]['name']} AS value,
  3729. CONCAT({$fieldsToConcat}) AS text
  3730. FROM {$this->name}
  3731. WHERE username = '{$_SESSION['user']['username']}' AND {$condition}
  3732. ORDER BY {$fields}";
  3733. } else {
  3734. $query = "SELECT {$this->fields[0]['name']} AS value,
  3735. CONCAT({$fieldsToConcat}) AS text
  3736. FROM {$this->name}
  3737. WHERE $condition
  3738. ORDER BY {$fields}";
  3739. }
  3740. $oid = mysql_query($query);
  3741. if (!$oid) {
  3742. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_PRESENTATION)." {$this->name} "." (".basename(__FILE__).":".__LINE__.")";
  3743. exit;
  3744. }
  3745. $content = array();
  3746. do {
  3747. $data = mysql_fetch_assoc($oid);
  3748. if ($data) {
  3749. $content[] = $data;
  3750. }
  3751. } while ($data);
  3752. return $content;
  3753. }
  3754. /**
  3755. * Gets reference by a relation.
  3756. *
  3757. * @param Array $filter must contains key mode
  3758. * @param costant $method BY_POSITION all
  3759. * @return Array(value, text)
  3760. */
  3761. function getReferenceByRelation($filter, $method = "") {
  3762. #echo "getReferenceByRelation ";
  3763. #echo $filter['relation']->name;
  3764. /*
  3765. $id1 = md5(microtime());
  3766. $id2 = md5(microtime());
  3767. #echo $id1,"<br>$id2";
  3768. $fields = "";
  3769. $fieldsToConcat = "";
  3770. foreach($this->presentation as $value) {
  3771. $fields .= aux::first_comma($id1,", ")."$value";
  3772. foreach($this->fields as $k => $v) {
  3773. if (($v['name'] == $value) and ($v['type'] == DATE)) {
  3774. $value = "DATE_FORMAT({$value},'%d/%m/%Y')";
  3775. }
  3776. }
  3777. $fieldsToConcat .= aux::first_comma($id2,",' ', ")."$value";
  3778. }
  3779. #echo $fields;exit; */
  3780. $presentation = $this->getPresentation();
  3781. $fields = $presentation['fields'];
  3782. $fieldsToConcat = $presentation['fieldsToConcat'];
  3783. switch ($method) {
  3784. case BY_POSITION:
  3785. $args = func_get_args();
  3786. $query = "SELECT {$this->fields[0]['name']} AS value,
  3787. CONCAT({$fieldsToConcat}) AS text,
  3788. '{$this->fields[0]['name']}' AS primarykey
  3789. FROM {$this->name}
  3790. ORDER BY {$args[1]}";
  3791. break;
  3792. case "all":
  3793. $query = "SELECT {$this->fields[0]['name']} AS value,
  3794. CONCAT({$fieldsToConcat}) AS text,
  3795. '{$this->fields[0]['name']}' AS primarykey
  3796. FROM {$this->name}
  3797. ORDER BY {$fields}";
  3798. break;
  3799. default:
  3800. if ($this->owner) {
  3801. switch($filter['mode']) {
  3802. case PRESENT:
  3803. $query = "SELECT DISTINCT {$this->name}.{$this->fields[0]['name']} AS value,
  3804. CONCAT({$fieldsToConcat}) AS text,
  3805. '{$this->fields[0]['name']}' AS primarykey
  3806. FROM {$this->name}
  3807. LEFT JOIN {$filter['relation']->name}
  3808. ON {$filter['relation']->fields[0]['name']} = {$this->name}.{$this->fields[0]['name']}
  3809. WHERE username = '{$_SESSION['user']['username']}'
  3810. AND {$filter['relation']->name}.{$filter['relation']->fields[0]['name']} IS NOT NULL
  3811. ORDER BY {$fields}";
  3812. break;
  3813. } //switch
  3814. } else {
  3815. $query = "SELECT {$this->fields[0]['name']} AS value,
  3816. CONCAT({$fieldsToConcat}) AS text,
  3817. '{$this->fields[0]['name']}' AS primarykey
  3818. FROM {$this->name}
  3819. ORDER BY {$fields}";
  3820. }
  3821. break;
  3822. }
  3823. $oid = mysql_query($query);
  3824. if (!$oid) {
  3825. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_PRESENTATION)." {$this->name} "." (".basename(__FILE__).":".__LINE__.")";
  3826. exit;
  3827. }
  3828. $content = array();
  3829. do {
  3830. $data = mysql_fetch_assoc($oid);
  3831. if ($data) {
  3832. $content[] = $data;
  3833. }
  3834. } while ($data);
  3835. return $content;
  3836. }
  3837. /**
  3838. * Gets a reference.
  3839. * @example $method: BY_POSITION, ALL, LIMIT, COUNT, NORMAL
  3840. *
  3841. * @param constant $method
  3842. * @return unknown
  3843. */
  3844. function getReference($method = "") {
  3845. /*$id1 = md5(microtime());
  3846. $id2 = md5(microtime());
  3847. $fields = "";
  3848. $fieldsToConcat = "";
  3849. foreach($this->presentation as $value) {
  3850. $fields .= aux::first_comma($id1,", ")."$value";
  3851. foreach($this->fields as $k => $v) {
  3852. if (($v['name'] == $value) and ($v['type'] == DATE)) {
  3853. $value = "DATE_FORMAT({$value},'%d/%m/%Y')";
  3854. } elseif (($v['name'] == $value) and ($v['type'] == LONGDATE)) {
  3855. $value = "DATE_FORMAT({$value},'%d/%m/%Y %H:%i')";
  3856. }
  3857. }
  3858. $fieldsToConcat .= aux::first_comma($id2,",' ', ")."$value";
  3859. } */
  3860. $presentation = $this->getPresentation();
  3861. $fields = $presentation['fields'];
  3862. $fieldsToConcat = $presentation['fieldsToConcat'];
  3863. $trovato = false;
  3864. if (count($this->referredBy) > 0) {
  3865. foreach($this->referredBy as $k => $v) {
  3866. if ($k == $this->name) {
  3867. $trovato = true;
  3868. $reference = $this->referredBy[$k]['foreign key'][0];
  3869. $reference_field = ", {$reference} AS reference ";
  3870. }
  3871. }
  3872. }
  3873. switch ($method) {
  3874. case BY_POSITION:
  3875. $args = func_get_args();
  3876. if (($this->owner) and (!$_SESSION['user']['admin'])) {
  3877. $first_case = "AND username = '{$_SESSION['user']['username']}'";
  3878. $second_case = "WHERE username = '{$_SESSION['user']['username']}'";
  3879. } else {
  3880. $first_case = "";
  3881. $second_case = "";
  3882. }
  3883. if (isset($args[2])) {
  3884. $query = "SELECT {$this->fields[0]['name']} AS value,
  3885. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  3886. '{$this->fields[0]['name']}' AS primarykey
  3887. FROM {$this->name}
  3888. WHERE $args[2] {$first_case}
  3889. ORDER BY {$args[1]}";
  3890. } else {
  3891. $query = "SELECT {$this->fields[0]['name']} AS value,
  3892. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  3893. '{$this->fields[0]['name']}' AS primarykey
  3894. FROM {$this->name}
  3895. {$second_case}
  3896. ORDER BY {$args[1]}";
  3897. }
  3898. break;
  3899. case "all":
  3900. if (($this->owner) and (!$_SESSION['user']['admin'])) {
  3901. $case = "WHERE username = '{$_SESSION['user']['username']}'";
  3902. } else {
  3903. $case = "";
  3904. }
  3905. $query = "SELECT {$this->fields[0]['name']} AS value,
  3906. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  3907. '{$this->fields[0]['name']}' AS primarykey
  3908. FROM {$this->name}
  3909. {$case}
  3910. ORDER BY {$fields}";
  3911. break;
  3912. case LIMIT:
  3913. $args = func_get_args();
  3914. $startIndex = $args[1];
  3915. $endIndex = $args[2];
  3916. if (count($args) > 3) {
  3917. $condition = $args[3];
  3918. } else {
  3919. $condition = "true";
  3920. }
  3921. if ($this->referenceOrder == true) {
  3922. $fields = $this->referenceOrder;
  3923. } else {
  3924. $fields = "text";
  3925. }
  3926. if ($this->owner) {
  3927. /* The entity is a WITH_OWNER entity */
  3928. if (in_array(ADMIN, $_SESSION['user']['groups'])) {
  3929. /* ADMIN: the amdinistrators have the complete visibility */
  3930. $query = "
  3931. SELECT {$this->fields[0]['name']} AS value,
  3932. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  3933. username AS owner,
  3934. lastmodified,
  3935. '{$this->fields[0]['name']}' AS primarykey
  3936. FROM {$this->name}
  3937. WHERE {$condition}
  3938. ORDER BY {$fields} LIMIT {$startIndex}, {$endIndex}";
  3939. } else {
  3940. /*
  3941. Here it will be checked whether the user is in the SUPERUSER GROUP for this
  3942. specific service
  3943. */
  3944. $superuser_group = $_SESSION['user']['services'][basename($_SERVER['SCRIPT_FILENAME'])]['superuser_group'];
  3945. if (in_array($superuser_group, $_SESSION['user']['groups'])) {
  3946. /* SUPERUSER_GROUP : the user has complete visibility */
  3947. $query = "SELECT {$this->fields[0]['name']} AS value,
  3948. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  3949. username AS owner,
  3950. lastmodified,
  3951. '{$this->fields[0]['name']}' AS primarykey
  3952. FROM {$this->name}
  3953. WHERE {$condition}
  3954. ORDER BY {$fields} LIMIT {$startIndex}, {$endIndex}";
  3955. } else {
  3956. /* FILTERED */
  3957. $query = "SELECT {$this->fields[0]['name']} AS value,
  3958. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  3959. username AS owner,
  3960. lastmodified,
  3961. '{$this->fields[0]['name']}' AS primarykey
  3962. FROM {$this->name}
  3963. WHERE username = '{$_SESSION['user']['username']}'
  3964. AND {$condition}
  3965. ORDER BY {$fields} LIMIT {$startIndex}, {$endIndex}";
  3966. }
  3967. }
  3968. } else {
  3969. $query = "
  3970. SELECT {$this->fields[0]['name']} AS value,
  3971. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  3972. '{$this->fields[0]['name']}' AS primarykey
  3973. FROM {$this->name}
  3974. WHERE {$condition}
  3975. ORDER BY {$fields} LIMIT {$startIndex}, {$endIndex}";
  3976. }
  3977. break;
  3978. case COUNT:
  3979. if (count($args) > 1) {
  3980. $condition = $args[1];
  3981. } else {
  3982. $condition = "true";
  3983. }
  3984. if ($this->owner) {
  3985. /* The entity is a WITH_OWNER entity */
  3986. if (in_array(ADMIN, $_SESSION['user']['groups'])) {
  3987. /* ADMIN: the amdinistrators have the complete visibility */
  3988. $query = "
  3989. SELECT COUNT(*) as count
  3990. FROM {$this->name}
  3991. WHERE {$condition}";
  3992. } else {
  3993. /*
  3994. Here it will be checked whether the user is in the SUPERUSER GROUP for this
  3995. specific service
  3996. */
  3997. $superuser_group = $_SESSION['user']['services'][basename($_SERVER['SCRIPT_FILENAME'])]['superuser_group'];
  3998. if (in_array($superuser_group, $_SESSION['user']['groups'])) {
  3999. /* SUPERUSER_GROUP : the user has complete visibility */
  4000. $query = "SELECT COUNT(*) as count
  4001. FROM {$this->name}
  4002. WHERE {$condition}";
  4003. } else {
  4004. /* FILTERED */
  4005. $query = "SELECT COUNT(*) as count
  4006. FROM {$this->name}
  4007. WHERE username = '{$_SESSION['user']['username']}'
  4008. AND {$condition}";
  4009. }
  4010. }
  4011. } else {
  4012. $query = "
  4013. SELECT COUNT(*) as count
  4014. FROM {$this->name}
  4015. WHERE {$condition}";
  4016. }
  4017. break;
  4018. case NORMAL:
  4019. default:
  4020. if (count($args) > 1) {
  4021. $condition = $args[1];
  4022. } else {
  4023. $condition = "true";
  4024. }
  4025. if ($GLOBALS['becontent']->entities[$this->name]->referenceOrder == true) {
  4026. #echo "|", $GLOBALS['becontent']->entities[$this->name]->referenceOrder, "|";
  4027. $fields = $this->referenceOrder;
  4028. } else {
  4029. $fields = "text";
  4030. }
  4031. if ($this->owner) {
  4032. /* The entity is a WITH_OWNER entity */
  4033. $fields = "creation";
  4034. if (in_array(ADMIN, $_SESSION['user']['groups'])) {
  4035. /* ADMIN: the amdinistrators have the complete visibility */
  4036. $query = "
  4037. SELECT {$this->fields[0]['name']} AS value,
  4038. CONCAT({$fieldsToConcat}, '') AS text {$reference_field},
  4039. username AS owner,
  4040. lastmodified,
  4041. '{$this->fields[0]['name']}' AS primarykey
  4042. FROM {$this->name}
  4043. WHERE {$condition}
  4044. ORDER BY {$fields}";
  4045. } else {
  4046. /*
  4047. Here it will be checked whether the user is in the SUPERUSER GROUP for this
  4048. specific service
  4049. */
  4050. $superuser_group = $_SESSION['user']['services'][basename($_SERVER['SCRIPT_FILENAME'])]['superuser_group'];
  4051. if (in_array($superuser_group, $_SESSION['user']['groups'])) {
  4052. /* SUPERUSER_GROUP : the user has complete visibility */
  4053. $query = "SELECT {$this->fields[0]['name']} AS value,
  4054. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  4055. username AS owner,
  4056. lastmodified,
  4057. '{$this->fields[0]['name']}' AS primarykey
  4058. FROM {$this->name}
  4059. WHERE {$condition}
  4060. ORDER BY {$fields}";
  4061. } else {
  4062. /* FILTERED */
  4063. $query = "SELECT {$this->fields[0]['name']} AS value,
  4064. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  4065. username AS owner,
  4066. lastmodified,
  4067. '{$this->fields[0]['name']}' AS primarykey
  4068. FROM {$this->name}
  4069. WHERE username = '{$_SESSION['user']['username']}'
  4070. AND {$condition}
  4071. ORDER BY {$fields}";
  4072. }
  4073. }
  4074. } else {
  4075. $query = "
  4076. SELECT {$this->fields[0]['name']} AS value,
  4077. CONCAT({$fieldsToConcat}) AS text {$reference_field},
  4078. '{$this->fields[0]['name']}' AS primarykey
  4079. FROM {$this->name}
  4080. WHERE {$condition}
  4081. ORDER BY {$fields}";
  4082. }
  4083. break;
  4084. }
  4085. $oid = mysql_query($query);
  4086. if (!$oid) {
  4087. echo "** ", $query;
  4088. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_PRESENTATION)." {$this->name} "." (".basename(__FILE__).":".__LINE__.")";
  4089. exit;
  4090. }
  4091. $content = array();
  4092. do {
  4093. $data = mysql_fetch_assoc($oid);
  4094. if ($data) {
  4095. $content[] = $data;
  4096. }
  4097. } while ($data);
  4098. if ($method == COUNT) {
  4099. /* it returns the total number of rows */
  4100. return $content[0]['count'];
  4101. } else {
  4102. /* it returns the rows */
  4103. return $content;
  4104. }
  4105. }
  4106. function insertItem2() {
  4107. $args = func_get_args();
  4108. $count = count($args);
  4109. $query = "INSERT INTO {$this->name} VALUES(";
  4110. for($i=0; $i<$count; $i++) {
  4111. $query .= "'".func_get_arg($i)."'";
  4112. if ($i < $count - 1) {
  4113. $query .= ",";
  4114. }
  4115. }
  4116. $query .= ")";
  4117. $oid = mysql_query($query);
  4118. if (!$oid) {
  4119. if (mysql_errno() != "1062") {
  4120. if (mysql_errno() == "1136") {
  4121. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_INIT)." {$this->name} "." (".basename(__FILE__).":".__LINE__.")";
  4122. exit;
  4123. }
  4124. } else {
  4125. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_PRESENTATION)." {$this->name} "." (".basename(__FILE__).":".__LINE__.")";
  4126. exit;
  4127. }
  4128. }
  4129. }
  4130. function insertItem() {
  4131. $id = md5(uniqid(time()));
  4132. $query = "INSERT INTO {$this->name} VALUES(";
  4133. $args = func_get_args();
  4134. if (is_array($args[0])) {
  4135. foreach($this->fields as $k => $field) {
  4136. switch($field['type']) {
  4137. case FILE:
  4138. $query .= aux::first_comma("{$id}", ", ")."'{$args[0][$field['name']]}'";
  4139. $query .= aux::first_comma("{$id}", ", ")."'".$args[0][$field['name']."_filename"]."'";
  4140. $query .= aux::first_comma("{$id}", ", ")."'".$args[0][$field['name']."_size"]."'";
  4141. $query .= aux::first_comma("{$id}", ", ")."'".$args[0][$field['name']."_type"]."'";
  4142. break;
  4143. default:
  4144. $query .= aux::first_comma("{$id}", ", ")."'{$args[0][$field['name']]}'";
  4145. break;
  4146. }
  4147. }
  4148. } else {
  4149. foreach($args as $k => $field) {
  4150. $query .= aux::first_comma("{$id}", ", ")."'{$field}'";
  4151. }
  4152. }
  4153. $query .= ")";
  4154. $oid = mysql_query($query);
  4155. if (!$oid) {
  4156. if (mysql_errno() != "1062") {
  4157. if (mysql_errno() == "1136") {
  4158. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_INIT)." {$this->name} "." (".basename(__FILE__).":".__LINE__.")";
  4159. exit;
  4160. }
  4161. } else {
  4162. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_PRESENTATION)." {$this->name} "." (".basename(__FILE__).":".__LINE__.")";
  4163. exit;
  4164. }
  4165. }
  4166. }
  4167. /**
  4168. * Adds an RSS filter.
  4169. * Filter item according to given criteria.
  4170. *
  4171. * @param unknown_type $filter
  4172. */
  4173. function addRssFilter($filter) {
  4174. $this->rssFilter = $filter;
  4175. }
  4176. // Inizializza le proprieta per la gestione degli rss
  4177. function addRss($channel,$parametri)
  4178. {
  4179. $this->channel=new Relation($this,$channel);
  4180. $this->channel->connect();
  4181. $this->rss=true;
  4182. $this->rssPresentation=aux::parsePars($parametri);
  4183. $oid=mysql_query("SELECT modality FROM bc_rss_mod WHERE entity=\"{$this->name}\"");
  4184. if($oid)
  4185. if(mysql_num_rows($oid)==0)
  4186. $GLOBALS['rssMod']->insertItem($this->name,"MOD1");
  4187. if($this->owner)
  4188. {
  4189. $this->rssPresentation['pubDate']='creation';
  4190. $this->rssPresentation['author']='username';
  4191. }
  4192. $x=0;
  4193. while ($x<count($GLOBALS['becontent']->entities)) {
  4194. if (isset($GLOBALS['becontent']->entities[$x])) {
  4195. if ($GLOBALS['becontent']->entities[$x]->name == $this->name) {
  4196. $GLOBALS['becontent']->entities[$x]->rssPresentation=$this->rssPresentation;
  4197. $GLOBALS['becontent']->entities[$x]->rss=$this->rss;
  4198. }
  4199. }
  4200. $x++;
  4201. }
  4202. }
  4203. }
  4204. Class ModeratedEntity extends Entity {
  4205. function ModeratedEntity($database, $name, $owner = "") {
  4206. Entity::Entity($database,$name,$owner);
  4207. $this->addField("passed", VARCHAR, 1);
  4208. }
  4209. function addItem_postInsertion() {
  4210. $script = basename($_SERVER['SCRIPT_FILENAME']);
  4211. if (ereg("([[:alnum:]]*)\-manager", $script, $token)) {
  4212. $entityName = $token[1];
  4213. }
  4214. $content_id = mysql_insert_id();
  4215. $oid = mysql_query("SELECT users.username
  4216. FROM users
  4217. RIGHT JOIN users_groups
  4218. ON users_groups.username = users.username
  4219. RIGHT JOIN entities
  4220. ON entities.priviledged_group = users_groups.id_groups
  4221. AND entities.priviledged_group = users_groups.id_groups
  4222. WHERE users.username = '{$_SESSION['user']['username']}'
  4223. AND entities.name = '$entityName'");
  4224. if (!$oid) {
  4225. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  4226. exit;
  4227. }
  4228. if (mysql_num_rows($oid) != 0) {
  4229. /*
  4230. the logged user is "priviledged", no need to moderate his/her contents!
  4231. */
  4232. $entity = $GLOBALS['database']->getEntityByName($entityName);
  4233. $oid = mysql_query("UPDATE {$entityName} SET passed='*' WHERE {$entity->fields[0]['name']}='{$content_id}'");
  4234. if (!$oid) {
  4235. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  4236. exit;
  4237. }
  4238. } else {
  4239. /*
  4240. the logged user is not "priviledged", it is necessary to contact all moderators!
  4241. */
  4242. $oid = mysql_query("SELECT * FROM entities WHERE name='{$entityName}'");
  4243. if (!$oid) {
  4244. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  4245. exit;
  4246. }
  4247. $data = mysql_fetch_assoc($oid);
  4248. $author = "{$_SESSION['user']['name']} {$_SESSION['user']['surname']} <{$_SESSION['user']['email']}>";
  4249. $content = $data['content_name'];
  4250. $script = "{$script}?action=validate&page=1&value={$content_id}";
  4251. $oid = mysql_query("SELECT users.name, users.surname, users.email
  4252. FROM users
  4253. LEFT JOIN users_groups
  4254. ON users_groups.username = users.username
  4255. WHERE users_groups.id_groups = {$data['moderator_group']}");
  4256. if (!$oid) {
  4257. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  4258. exit;
  4259. }
  4260. do {
  4261. $data = mysql_fetch_array($oid);
  4262. if ($data) {
  4263. $mail = new Template("dtml/mail_moderation_validate.html");
  4264. $mail->setContent("author", $author);
  4265. $mail->setContent("content", $content);
  4266. $mail->setContent("script", $script);
  4267. $mail->setContent("name", $data['name']);
  4268. mail($data['email'],"[model-transformation.org] new content to moderate",$mail->get(), "From: {$_SESSION['user']['email']}");
  4269. }
  4270. } while ($data);
  4271. }
  4272. }
  4273. }
  4274. Class Relation extends Entity {
  4275. var
  4276. $entity_1,
  4277. $entity_2;
  4278. function Relation(&$entity_1, &$entity_2, $name = "") {
  4279. $this->entity_1 = $entity_1;
  4280. $this->entity_2 = $entity_2;
  4281. if (!$this->entity_1->name) {
  4282. echo $GLOBALS['message']->getMessage(MSG_ERROR_UNKNOWN_ENTITY)." (".basename(__FILE__).":".__LINE__.")";
  4283. exit;
  4284. }
  4285. if ($name != "") {
  4286. $this->Entity($GLOBALS['database'],"{$name}");
  4287. } else {
  4288. $this->Entity($GLOBALS['database'],"{$this->entity_1->name}_{$this->entity_2->name}");
  4289. }
  4290. /*
  4291. Relations do not have any primary key.
  4292. */
  4293. $this->noKey();
  4294. if ($this->entity_1->standardKey) {
  4295. $this->addField("id_{$this->entity_1->name}", INT);
  4296. } else {
  4297. $this->addField($this->entity_1->fields[0]['name'],
  4298. $this->entity_1->fields[0]['type'],
  4299. $this->entity_1->fields[0]['length']);
  4300. }
  4301. if ($this->entity_2->standardKey) {
  4302. $this->addField("id_{$this->entity_2->name}", INT);
  4303. } else {
  4304. $this->addField($this->entity_2->fields[0]['name'],
  4305. $this->entity_2->fields[0]['type'],
  4306. $this->entity_2->fields[0]['length']);
  4307. }
  4308. $entity_1->relations[] = $this;
  4309. $entity_2->relations[] = $this;
  4310. }
  4311. }
  4312. /* **********************************************************************
  4313. FORM
  4314. ********************************************************************** */
  4315. Class Form {
  4316. var
  4317. $labels,
  4318. $name,
  4319. /* $mainTable, -- let's discard it, it seems it has been not used */
  4320. $helpers,
  4321. $relations,
  4322. $method,
  4323. $enctype,
  4324. $elements,
  4325. $conditions,
  4326. $entity,
  4327. $withPosition,
  4328. $positions,
  4329. $noDelete,
  4330. $triggered,
  4331. $triggeredForm,
  4332. $triggeredForms,
  4333. $relationManager,
  4334. $templatePath,
  4335. $moderationMode,
  4336. $description,
  4337. $mainFormEntity, //utilizzato per la gestione Rss
  4338. $filterRelation,
  4339. $relationData, // used to persist data inserted in N-M relations
  4340. $reportTemplate, // These are to customize liveReport behaviour
  4341. $reportQuery,
  4342. $pager,
  4343. $lastid; // The pager is used to customize the report functionality
  4344. function Form($name, $entity, $method = "GET") {
  4345. /* can the name of the form be given in an automated way,
  4346. using maybe an identified which is generated from the
  4347. timestamp ? */
  4348. $this->name = $name;
  4349. $this->method = $method;
  4350. /* this is used to control the visibility of the "delete" button
  4351. in the form while the EDIT mode */
  4352. $this->noDelete = false;
  4353. /* this is used to denote that the form has a POSITION widget type */
  4354. $this->withPosition = false;
  4355. /* the following denotes that the current form will be
  4356. triggered by some other form, the invoking form is referred
  4357. in triggerForm */
  4358. $this->triggered = false;
  4359. $this->triggeredForm = false;
  4360. $this->triggeredForms = false;
  4361. $this->moderationMode = false;
  4362. /* the following is the DTML template path */
  4363. $this->templatePath = "dtml";
  4364. $this->labels[ADD] = "Aggiungi";
  4365. $this->labels[EDIT] = "Modifica";
  4366. $this->labels[DELETE] = "Rimuovi";
  4367. $this->labels['MSG_SURE'] = "Sei sicuro";
  4368. $this->labels['MSG_UPDATE'] = "The item has been correctly updated!";
  4369. $this->entity = $entity;
  4370. $content_js = "<script language=\"JavaScript\" src=\"js/calendar.js\"></script>\n";
  4371. $content_js .= "<script language=\"JavaScript\" src=\"js/position.js\"></script>\n";
  4372. $content_js .= "<script src=\"js/plugin_colorpicker.js\" type=\"text/JavaScript\"></script>\n";
  4373. $content_js .= "<script language=\"JavaScript\" src=\"js/ajax-decode-2.js\"></script>\n";
  4374. $content_style = "<LINK REL=STYLESHEET HREF=\"css/calendar.css\" TYPE=\"text/css\">\n";
  4375. $content_style .= "<link href=\"css/plugin_colorpicker.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
  4376. $GLOBALS['main']->setContentOnce("javascript","{$content_js}");
  4377. $GLOBALS['main']->setContentOnce("style",$content_style);
  4378. /* RSS enabled entities management */
  4379. if ($this->entity->rss) {
  4380. $new_form=new Form("Channel-gestion",$this->entity->channel);
  4381. $new_form->mainFormEntity=$this->entity;
  4382. $new_form->addRelationManager("bc_channel",'<img src="img/rss/rss.gif" />');
  4383. $this->triggers($new_form);
  4384. }
  4385. $this->reportTemplate = "dtml/report.html";
  4386. $this->reportQuery = "";
  4387. $GLOBALS['currentform'] = &$this;
  4388. }
  4389. function triggers(&$form) {
  4390. if (version_compare(phpversion(),"5.0", "<")) {
  4391. $relationName = "relation";
  4392. } else {
  4393. $relationName = "Relation";
  4394. }
  4395. if (get_class($form->entity) != $relationName) {
  4396. echo $GLOBALS['message']->getMessage(MSG_ERROR_TRIGGERS)." (".basename(__FILE__).":".__LINE__.")";
  4397. exit;
  4398. }
  4399. $this->triggeredForm = &$form;
  4400. $this->triggeredForms[] = &$form;
  4401. $form->triggered = true;
  4402. }
  4403. function setModerationMode() {
  4404. $this->moderationMode = true;
  4405. }
  4406. function addHelper($field,$text) {
  4407. $this->helpers[$field] = $text;
  4408. }
  4409. function addValidation($el_1, $el_2, $condition, $message = "") {
  4410. foreach($this->elements as $k => $v) {
  4411. if ($v['name'] == $el_1) {
  4412. $label_1 = $v['label'];
  4413. $obj_1 = $v;
  4414. }
  4415. if ($v['name'] == $el_2) {
  4416. $label_2 = $v['label'];
  4417. $obj_2 = $v;
  4418. }
  4419. }
  4420. $this->conditions[] = array("element_1" => $el_1,
  4421. "element_2" => $el_2,
  4422. "label_1" => $label_1,
  4423. "label_2" => $label_2,
  4424. "obj_1" => $obj_1,
  4425. "obj_2" => $obj_2,
  4426. "condition" => $condition,
  4427. "message" => $message);
  4428. }
  4429. function setFilterByExtension($name, $extension, $message = "") {
  4430. foreach($this->elements as $k => $v) {
  4431. if ($v['name'] == $name) {
  4432. $this->elements[$k]['filterByExtension'] = $extension;
  4433. $this->elements[$k]['message'] = $message;
  4434. }
  4435. }
  4436. }
  4437. function setSubmitString($name) {
  4438. $this->labels["add"] = $name;
  4439. }
  4440. function addSection($name, $text = "") {
  4441. $this->elements[] = array(
  4442. "type" => "section",
  4443. "name" => $name,
  4444. "text" => $text
  4445. );
  4446. }
  4447. function addDescription($text) {
  4448. $this->description = $text;
  4449. }
  4450. function addHidden($name, $value) {
  4451. $this->elements[] = array("name" => $name,
  4452. "type" => HIDDEN,
  4453. "value" => $value
  4454. );
  4455. }
  4456. function addText($name, $label, $size = "20", $mandatory = "off", $maxlength = "") {
  4457. $this->elements[] = array("name" => $name,
  4458. "type" => "text",
  4459. "label" => $label,
  4460. "size" => $size,
  4461. "mandatory" => $mandatory,
  4462. "maxlength" => $maxlength
  4463. );
  4464. #$this->elements[] = new Text($name, $label, $size, )
  4465. }
  4466. function addLink($name,
  4467. $label,
  4468. $size = "20",
  4469. $mandatory = "off",
  4470. $maxlength = "") {
  4471. $this->elements[] = array("name" => $name,
  4472. "type" => "link",
  4473. "label" => $label,
  4474. "size" => $size,
  4475. "mandatory" => $mandatory,
  4476. "maxlength" => $maxlength
  4477. );
  4478. }
  4479. function addPassword($name,
  4480. $label,
  4481. $size = "20",
  4482. $mandatory = "off",
  4483. $maxlength = "") {
  4484. $this->elements[] = array("name" => $name,
  4485. "type" => "password",
  4486. "label" => $label,
  4487. "size" => $size,
  4488. "mandatory" => $mandatory,
  4489. "maxlength" => $maxlength
  4490. );
  4491. $this->method = POST;
  4492. }
  4493. function addPosition($name, $label, $controlledField, $size = "8", $mandatory = "off") {
  4494. $this->elements[] = array("name" => $name,
  4495. "controlledField" => $controlledField,
  4496. "type" => "position",
  4497. "label" => $label,
  4498. "size" => $size,
  4499. "mandatory" => $mandatory
  4500. );
  4501. $this->withPosition = true;
  4502. $this->positions[] = count($this->elements) - 1;
  4503. }
  4504. function addHierarchicalPosition($name, $label, $controlledField, $referenceField, $size = "8") {
  4505. foreach($this->elements as $k=>$v) {
  4506. if ($v['name'] == $referenceField) {
  4507. $reference_index = $k;
  4508. }
  4509. }
  4510. $this->elements[] = array(
  4511. "name" => $name,
  4512. "controlledField" => $controlledField,
  4513. "type" => "hierarchicalPosition",
  4514. "label" => $label,
  4515. "size" => $size,
  4516. "referenceField" => $referenceField,
  4517. "reference_index" => $reference_index,
  4518. "size" => $size
  4519. );
  4520. $this->withPosition = true;
  4521. $this->positions[] = count($this->elements) - 1;
  4522. }
  4523. function addColor($name, $label, $preset = 'FFFFFF') {
  4524. $this->elements[] = array("name" => $name,
  4525. "type" => "color",
  4526. "label" => $label,
  4527. "size" => "7",
  4528. "mandatory" => MANDATORY,
  4529. "maxlength" => "7",
  4530. "preset" => $preset
  4531. );
  4532. }
  4533. function addRadio($name,
  4534. $label) {
  4535. $values = func_get_args();
  4536. $this->elements[] = array("name" => $name,
  4537. "type" => "radio",
  4538. "label" => $label,
  4539. "values" => $values
  4540. );
  4541. }
  4542. function addDate($name, $label, $mandatory = "off") {
  4543. $this->elements[] = array("name" => $name,
  4544. "type" => "date",
  4545. "mandatory" => $mandatory,
  4546. "label" => $label
  4547. );
  4548. }
  4549. function addLongDate($name,$label, $mandatory = "off") {
  4550. $this->elements[] = array("name" => $name,
  4551. "type" => LONGDATE,
  4552. "mandatory" => $mandatory,
  4553. "label" => $label
  4554. );
  4555. }
  4556. function addFile($name,$label,$mandatory = "off") {
  4557. $this->elements[] = array("name" => $name,
  4558. "type" => FILE,
  4559. "label" => $label,
  4560. "mandatory" => $mandatory
  4561. );
  4562. $this->method = "POST";
  4563. $this->enctype = "enctype=\"multipart/form-data\"";
  4564. }
  4565. function addFileToFolder($name,$label,$mandatory = "off") {
  4566. $this->elements[] = array("name" => $name,
  4567. "type" => FILE2FOLDER,
  4568. "label" => $label,
  4569. "mandatory" => $mandatory
  4570. );
  4571. $this->method = "POST";
  4572. $this->enctype = "enctype=\"multipart/form-data\"";
  4573. }
  4574. function addImage($name,$label,$mandatory = "off") {
  4575. $this->elements[] = array("name" => $name,
  4576. "type" => "image",
  4577. "label" => $label,
  4578. "mandatory" => $mandatory,
  4579. "thumb_size" => "100",
  4580. );
  4581. $this->method = "POST";
  4582. $this->enctype = "enctype=\"multipart/form-data\"";
  4583. }
  4584. function addselect2($name, $label) {
  4585. $values = func_get_args();
  4586. if (gettype($values[2]) == "string") {
  4587. if (($values[count($values)-1] == strtolower("yes")) or ($values[count($values)-1] == strtolower("no"))) {
  4588. $mandatory = $values[count($values)-1];
  4589. unset($values[count($values)-1]);
  4590. }
  4591. $this->elements[] = array(
  4592. "name" => $name,
  4593. "type" => "select",
  4594. "label" => $label,
  4595. "values" => $values,
  4596. "mandatory" => $mandatory
  4597. );
  4598. }
  4599. }
  4600. function addSelect($name, $label, $values, $mandatory = "no") {
  4601. /* SYNTAX : */
  4602. $this->elements[] = array(
  4603. "name" => $name,
  4604. "type" => "select",
  4605. "label" => $label,
  4606. "values" => $values,
  4607. "mandatory" => $mandatory
  4608. );
  4609. }
  4610. function addYear($name, $label, $start = -15, $end = 1) {
  4611. $year = date("Y");
  4612. $values = "";
  4613. for($y=$year+$start; $y<=$year+$end; $y++) {
  4614. if ($y == $year) {
  4615. $values .= aux::first_comma($name,",")."${y}:{$y}:CHECKED";
  4616. } else {
  4617. $values .= aux::first_comma($name,",")."{$y}:${y}";
  4618. }
  4619. }
  4620. $this->addSelect($name, $label, $values);
  4621. }
  4622. function addSelectFromReference(&$entity, $label , $mandatory = "no") {
  4623. $this->elements[] = array(
  4624. "name" => "id_".$entity->name,
  4625. "type" => "selectFromReference",
  4626. "label" => $label,
  4627. "entity" => $entity,
  4628. "mandatory" => $mandatory
  4629. );
  4630. }
  4631. function addSelectFromReference2($entity, $name, $label , $mandatory = "no") {
  4632. $this->elements[] = array(
  4633. "name" => $name,
  4634. "type" => "selectFromReference",
  4635. "label" => $label,
  4636. "entity" => $entity,
  4637. "entity_name" => $entity->name,
  4638. "mandatory" => $mandatory
  4639. );
  4640. }
  4641. function addSelfReferenceManager($name, $label , $position_field) {
  4642. $this->elements[] = array(
  4643. "name" => $name,
  4644. "type" => "SelfReferenceManager",
  4645. "label" => $label,
  4646. "entity" => $this->entity,
  4647. "position_field" => $position_field
  4648. );
  4649. }
  4650. function addRadioFromReference($entity, $name, $label , $mandatory = "no") {
  4651. $this->elements[] = array(
  4652. "name" => $name,
  4653. "type" => RADIO_FROM_REFERENCE,
  4654. "label" => $label,
  4655. "entity" => $entity,
  4656. "mandatory" => $mandatory
  4657. );
  4658. }
  4659. function restrictReference($name, $condition = "true") {
  4660. $i=0;
  4661. $trovato = false;
  4662. while (($i<count($this->elements)) and (!$trovato)) {
  4663. if ($this->elements[$i]['name'] == $name) {
  4664. $trovato = true;
  4665. $this->elements[$i]['condition'] = $condition;
  4666. }
  4667. $i++;
  4668. }
  4669. }
  4670. function addCheck($label) {
  4671. $values = func_get_args();
  4672. $this->elements[] = array(
  4673. "type" => CHECKBOX,
  4674. "label" => $label,
  4675. "values" => $values
  4676. );
  4677. }
  4678. function addTextarea($name,$label, $rows, $cols, $mandatory = "no") {
  4679. $this->elements[] = array(
  4680. "name" => $name,
  4681. "type" => "textarea",
  4682. "label" => $label,
  4683. "rows" => $rows,
  4684. "cols" => $cols,
  4685. "mandatory" => $mandatory
  4686. );
  4687. $this->method = POST;
  4688. }
  4689. function addEditor($name,$label, $rows, $cols, $mandatory = "no") {
  4690. $this->elements[] = array(
  4691. "name" => $name,
  4692. "type" => "editor",
  4693. "label" => $label,
  4694. "rows" => $rows,
  4695. "cols" => $cols,
  4696. "mandatory" => $mandatory
  4697. );
  4698. $this->method = POST;
  4699. }
  4700. function addRelationManager2($name, $label, $orientation = RIGHT) {
  4701. if (get_class($this->entity) != "relation") {
  4702. echo $GLOBALS['message']->getMessage(MSG_ERROR_RELATION_MANAGER)." (".basename(__FILE__).":".__LINE__.")";
  4703. exit;
  4704. }
  4705. $this->elements[] = array(
  4706. "name" => $name,
  4707. "label" => $label,
  4708. "type" => "relation manager2",
  4709. "orientation" => $orientation,
  4710. "mandatory" => "no",
  4711. "condition" => true
  4712. );
  4713. $this->relationManager = count($this->elements)-1;
  4714. }
  4715. function addRelationManager($name, $label, $orientation = RIGHT) {
  4716. if (version_compare(phpversion(),"5.0", "<")) {
  4717. $relationName = "relation";
  4718. } else {
  4719. $relationName = "Relation";
  4720. }
  4721. if (get_class($this->entity) != $relationName) {
  4722. echo $GLOBALS['message']->getMessage(MSG_ERROR_RELATION_MANAGER)." (".basename(__FILE__).":".__LINE__.")";
  4723. exit;
  4724. }
  4725. $this->elements[] = array(
  4726. "name" => $name,
  4727. "label" => $label,
  4728. "type" => RELATION_MANAGER,
  4729. "orientation" => $orientation,
  4730. "mandatory" => "no",
  4731. "condition" => true
  4732. );
  4733. $this->relationManager = count($this->elements)-1;
  4734. }
  4735. function setMandatory($name) {
  4736. foreach($this->elements as $k =>$v) {
  4737. if ($v['name'] == $name) {
  4738. $this->elements[$k]['mandatory'] = "yes";
  4739. }
  4740. }
  4741. }
  4742. function filterByRelation($relation, $mode = PRESENT) {
  4743. $this->filterRelation['relation'] = $relation;
  4744. $this->filterRelation['mode'] = $mode;
  4745. }
  4746. function addFilter($name, $condition = true) {
  4747. foreach($this->elements as $k => $value) {
  4748. if ($value['name'] == $name) {
  4749. $index = $k;
  4750. }
  4751. }
  4752. $this->elements[$index]['condition'] = $condition;
  4753. }
  4754. function getElementByName($name) {
  4755. $result = false;
  4756. foreach($this->elements as $value) {
  4757. if ($value['name'] == $name) {
  4758. $result = $value;
  4759. }
  4760. }
  4761. return $result;
  4762. }
  4763. /* Transaction */
  4764. function addItem() {
  4765. if (!isset($_REQUEST['page'])) {
  4766. $page = 0;
  4767. } else {
  4768. $page = $_REQUEST['page'];
  4769. }
  4770. switch ($page) {
  4771. case 0:
  4772. /* EMIT FORM */
  4773. $this->addItem_preEmitForm();
  4774. $content = $this->display(ADD,1);
  4775. $this->addItem_postEmitForm();
  4776. break;
  4777. case 1:
  4778. /* INSERTION */
  4779. $this->addItem_preInsertion();
  4780. $entity = $this->entity;
  4781. //ADD ITEM ALTERNATIVO
  4782. $temp = $this->addItem_sub();
  4783. if (!isset($temp))
  4784. $temp=$entity->addItem();
  4785. if (!$temp) {
  4786. if ($entity->reload) {
  4787. $GLOBALS['main']->setContent("message",
  4788. $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_RELOAD));
  4789. $content = $this->display(ADD,1);
  4790. } else {
  4791. $error = mysql_errno();
  4792. if ($error == 1062) {
  4793. $GLOBALS['main']->setContent("message",
  4794. $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_DUPLICATE_KEY));
  4795. $content = $this->display(ADD,1,PRELOAD);
  4796. } else {
  4797. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  4798. echo "<hr>", $error, mysql_error();
  4799. exit;
  4800. }
  4801. }
  4802. } else {
  4803. if ($this->entity->standardKey) {
  4804. $id = $_REQUEST['insertid'];
  4805. } else {
  4806. $id = $_REQUEST["{$this->entity->fields[0]['name']}"];
  4807. }
  4808. $this->lastid = $id;
  4809. if ((count($this->triggeredForms) > 0) and ($this->triggeredForms != "")) {
  4810. /* if ($this->entity->standardKey) {
  4811. #$id = mysql_insert_id();
  4812. $id = $_REQUEST['insertid'];
  4813. } else {
  4814. $id = $_REQUEST["{$this->entity->fields[0]['name']}"];
  4815. } */
  4816. foreach($this->triggeredForms as $k => $form) {
  4817. foreach($_REQUEST as $key=>$value) {
  4818. if (ereg("{$form->elements[0]['name']}_",$key)) {
  4819. switch ($form->elements[0]['orientation']) {
  4820. case RIGHT:
  4821. $query = "INSERT INTO {$form->entity->name} VALUES('{$id}','{$_REQUEST[$key]}')";
  4822. $par[0] = $id;
  4823. $par[1] = $_REQUEST[$key];
  4824. break;
  4825. case LEFT:
  4826. $query = "INSERT INTO {$form->entity->name} VALUES('{$_REQUEST[$key]}','{$id}')";
  4827. $par[0] = $_REQUEST[$key];
  4828. $par[1] = $id;
  4829. break;
  4830. }
  4831. $this->relationData[$form->entity->name][] = array($par[0],$par[1]);
  4832. $oid = mysql_query($query);
  4833. if (!$oid) {
  4834. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_RELATION_INSERT)." (".basename(__FILE__).":".__LINE__.")";
  4835. exit;
  4836. }
  4837. }
  4838. }
  4839. }
  4840. }
  4841. $content = $this->display(ADD,1);
  4842. if(!isset($temp)) {
  4843. $GLOBALS['main']->setContent("message",$GLOBALS['message']->getMessage(NOTIFY_ITEM_UPDATED));
  4844. } else {
  4845. $GLOBALS['main']->setContent("message",$GLOBALS['message']->getMessage(NOTIFY_ITEM_ADDED));
  4846. }
  4847. }
  4848. $this->addItem_postInsertion();
  4849. break;
  4850. }
  4851. return $content;
  4852. }
  4853. function setReportTemplate($template) {
  4854. $this->reportTemplate = $template;
  4855. }
  4856. function setReportQuery($query) {
  4857. $this->reportQuery = $query;
  4858. }
  4859. function setPager(&$pager) {
  4860. $this->pager = $pager;
  4861. }
  4862. function editItem($noDelete = false) {
  4863. if (!isset($_REQUEST['page'])) {
  4864. $page = 0;
  4865. } else {
  4866. $page = $_REQUEST['page'];
  4867. }
  4868. switch ($page) {
  4869. case 0:
  4870. $entity = $this->entity;
  4871. if (!isset($this->pager)) {
  4872. /* the pager is going to instantiate the template object as well */
  4873. $this->pager = &new beContentPager();
  4874. }
  4875. if (!isset($_REQUEST['mode']) or ($_REQUEST['mode'] != AJAX)) {
  4876. /*
  4877. FORM - EDIT ITEM - PAGE 0
  4878. The following is executed as the first step in the editItem() procedure.
  4879. */
  4880. $this->editItem_preSelection();
  4881. if (isset($_REQUEST['msgCode'])) {
  4882. $GLOBALS['main']->setContent("message",$GLOBALS['message']->getMessage($_REQUEST['msgCode']));
  4883. }
  4884. $body = new Template("{$this->reportTemplate}");
  4885. $body->setContent("page", 1);
  4886. $body->setContent("item", $this->entity->name, "length=\"{$this->pager->length}\"");
  4887. $content = "<div id=\"becontent\">\n\n".$body->get()."\n</div>\n";
  4888. $this->editItem_postSelection();
  4889. } else {
  4890. /*
  4891. 22.01.2008
  4892. FORM - EDIT ITEM - PAGE 0 - AJAX:
  4893. The following is executed by an AJAX request, it is intended to
  4894. replace the the externa ajax-report.php script, which caused lots
  4895. of loosy coupling with the rest.
  4896. It is invoked by the code which is generated by
  4897. FORM - EDIT FORM - PAGE 0 (ie the previous sub-step)
  4898. */
  4899. /*
  4900. Warning: in the following stripslashes is necessary because of the
  4901. folloing directive in the PHP.INI file
  4902. magic_quotes_sybase = Off
  4903. it should not cause problems also in the case is On
  4904. */
  4905. $form = unserialize(stripslashes($_REQUEST['form']));
  4906. if ($form['update'] != "") {
  4907. /* Look for eventual checkboxes (and others) which have clicked */
  4908. foreach($this->entity->fields as $k => $v) {
  4909. if (array_key_exists($v['name'], $form)) {
  4910. $fields[] = $this->entity->fields[$k]['name'];
  4911. }
  4912. }
  4913. $query = "UPDATE {$this->entity->name} SET ";
  4914. if (is_array($fields)) {
  4915. foreach($fields as $field) {
  4916. $query .= aux::first_comma("UPDATE AJAX", ", ")."{$field} = '{$form[$field]}'";
  4917. }
  4918. }
  4919. $query .= " WHERE {$this->entity->fields[0]['name']} = '{$form['value']}'";
  4920. $oid = mysql_query($query);
  4921. }
  4922. $_REQUEST['pagelength'] = $this->pager->length;
  4923. $startIndex = ($_REQUEST['currentpage'] - 1)*$_REQUEST['pagelength'];
  4924. if ($startIndex < 0) {
  4925. $startIndex = 1;
  4926. }
  4927. $length = $_REQUEST['pagelength'];
  4928. if ($_REQUEST['currentpage']*$_REQUEST['pagelength'] > $_REQUEST['totallength']) {
  4929. $length = $_REQUEST['pagelength'] - (($_REQUEST['currentpage']*$_REQUEST['pagelength']) - $_REQUEST['totallength']);
  4930. }
  4931. $endIndex = $startIndex + $length;
  4932. if ($this->pager->query != "") {
  4933. if (($form['operation'] == "search") and ($form['search'] != "")) {
  4934. #$this->pager->query = aux::refineQuery($this->pager->query, aux::evaluate($this->pager->filter, $form));
  4935. $query = aux::refineQuery($this->pager->query, aux::evaluate($this->pager->filter, $form));
  4936. $startIndex = ($_REQUEST['currentpage'] - 1)*$_REQUEST['pagelength'];
  4937. $length = $_REQUEST['pagelength'];
  4938. if ($_REQUEST['currentpage']*$_REQUEST['pagelength'] > $_REQUEST['totallength']) {
  4939. $length = $_REQUEST['pagelength'] - (($_REQUEST['currentpage']*$_REQUEST['pagelength']) - $_REQUEST['totallength']);
  4940. }
  4941. $endIndex = $startIndex + $length;
  4942. } else {
  4943. $query = aux::getResult($this->pager->getQuery(),PARSE);
  4944. }
  4945. $oid = mysql_query($query);
  4946. $_REQUEST['totallength'] = mysql_num_rows($oid);
  4947. if ($endIndex > $_REQUEST['totallength']) {
  4948. $endIndex = $_REQUEST['totallength'];
  4949. }
  4950. $query .= " LIMIT {$startIndex}, {$length}";
  4951. $data = aux::getResult($query);
  4952. } else {
  4953. if (($form['operation'] == "search") and ($form['search'] != "")) {
  4954. $condition = "";
  4955. foreach($this->entity->presentation as $v) {
  4956. $condition .= aux::first_comma("condition", " OR ");
  4957. $condition .= " {$v} LIKE '%{$form['search']}%' ";
  4958. }
  4959. if ($this->entity->owner) {
  4960. $condition .= aux::first_comma("condition", " OR ");
  4961. $condition .= " username LIKE '%{$form['search']}%' ";
  4962. }
  4963. $condition .= aux::first_comma("condition", " OR ");
  4964. $condition .= " {$this->entity->fields[0]['name']} LIKE '%{$form['search']}%' ";
  4965. $data = $entity->getReference(LIMIT, $startIndex, $length, $condition);
  4966. } else {
  4967. $data = $entity->getReference(LIMIT, $startIndex, $length);
  4968. }
  4969. }
  4970. $totalPages = ceil($_REQUEST['totallength']/$_REQUEST['pagelength']);
  4971. #echo $_REQUEST['totallength'], " ";
  4972. //if (is_array($data) or (count($data) > 0)) {
  4973. if ($_REQUEST['totallength'] > 0) {
  4974. $content['content'] = $this->pager->get($data);
  4975. $content['content'] = ereg_replace("\n", "", $content['content']);
  4976. } else {
  4977. $empty = new Template("dtml/empty-report.html");
  4978. $content['content'] = ereg_replace("\n", "", $empty->get());
  4979. }
  4980. $content['startIndex'] = $startIndex + 1;
  4981. $content['endIndex'] = $endIndex;
  4982. $content['currentPage'] = $_REQUEST['currentpage'];
  4983. $content['totalPages'] = $totalPages."";
  4984. $content['totallength'] = $_REQUEST['totallength'];
  4985. #echo $content['totallength'];exit;
  4986. echo (aux::AjaxEncode($content));
  4987. exit;
  4988. }
  4989. break;
  4990. case 1:
  4991. /* FORM FEED */
  4992. $this->editItem_preFormFeed();
  4993. $oid = mysql_query("SELECT * FROM {$this->entity->name}
  4994. WHERE {$this->entity->fields[0]['name']}='{$_REQUEST['value']}'");
  4995. if (!$oid) {
  4996. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  4997. exit;
  4998. }
  4999. $data = mysql_fetch_assoc($oid);
  5000. if ((count($data) > 0) and ($data != "")) {
  5001. foreach($data as $k => $v) {
  5002. $_REQUEST[$k] = $v;
  5003. }
  5004. }
  5005. /* the following is about N-M relations */
  5006. if ((count($this->triggeredForms)>0) and ($this->triggeredForms != "")) {
  5007. foreach($this->triggeredForms as $k => $form) {
  5008. switch($form->elements[0]['orientation']) {
  5009. case RIGHT:
  5010. $query = "SELECT *
  5011. FROM {$form->entity->name}
  5012. WHERE {$form->entity->fields[0]['name']}='{$_REQUEST['value']}'";
  5013. break;
  5014. case LEFT:
  5015. $query = "SELECT *
  5016. FROM {$form->entity->name}
  5017. WHERE {$form->entity->fields[1]['name']}='{$_REQUEST['value']}'";
  5018. break;
  5019. }
  5020. $oid = mysql_query($query);
  5021. if (!$oid) {
  5022. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5023. exit;
  5024. }
  5025. do {
  5026. $data = mysql_fetch_array($oid);
  5027. if ($data) {
  5028. switch($form->elements[0]['orientation']) {
  5029. case RIGHT:
  5030. $_REQUEST["{$form->elements[0]['name']}_".aux::encode_name($data[1])] = $data[1];
  5031. #$_REQUEST["{$form->elements[0]['name']}_{$data[1]}"] = $data[1];
  5032. break;
  5033. case LEFT:
  5034. $_REQUEST["{$form->elements[0]['name']}_".aux::encode_name($data[0])] = $data[0];
  5035. #$_REQUEST["{$form->elements[0]['name']}_{$data[0]}"] = $data[0];
  5036. break;
  5037. }
  5038. }
  5039. } while ($data);
  5040. }
  5041. }
  5042. $this->noDelete = $noDelete;
  5043. $content = $this->display(EDIT,2,PRELOAD);
  5044. $this->editItem_postFormFeed();
  5045. break;
  5046. case 2:
  5047. /* UPDATE */
  5048. foreach($this->elements as $k => $v) {
  5049. if ($v['type'] == CHECKBOX) {
  5050. $token = explode(":", $v['values'][1]);
  5051. if (!isset($_REQUEST[$token[1]])) {
  5052. $_REQUEST[$token[1]] = '';
  5053. }
  5054. }
  5055. }
  5056. $this->editItem_preUpdate();
  5057. $entity = $this->entity;
  5058. if (!$entity->editItem()) {
  5059. /* An error occourred */
  5060. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5061. } else {
  5062. /* Pivotal entity has been succesfully updated */
  5063. if (!isset($_REQUEST['value'])) {
  5064. $_REQUEST['value'] = "";
  5065. }
  5066. $query = "SELECT * FROM {$this->entity->name} WHERE {$this->entity->fields[0]['name']}='{$_REQUEST['value']}'";
  5067. $oid = mysql_query($query);
  5068. if (!$oid) {
  5069. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5070. exit;
  5071. }
  5072. $data = mysql_fetch_assoc($oid);
  5073. if ((count($data) > 0) and ($data != "")) {
  5074. foreach($data as $k => $v) {
  5075. $_REQUEST[$k] = $v;
  5076. }
  5077. }
  5078. /* RELATION MANAGER MANAGEMENT BELOW */
  5079. if ((count($this->triggeredForms)>0) and ($this->triggeredForms != "")) {
  5080. foreach($this->triggeredForms as $k => $form) {
  5081. switch ($form->elements[0]['orientation']) {
  5082. case RIGHT:
  5083. $query = "DELETE FROM {$form->entity->name} WHERE {$form->entity->fields[0]['name']}='{$_REQUEST['value']}'";
  5084. break;
  5085. case LEFT:
  5086. $query = "DELETE FROM {$form->entity->name} WHERE {$form->entity->fields[1]['name']}='{$_REQUEST['value']}'";
  5087. break;
  5088. }
  5089. $oid = mysql_query($query);
  5090. if (!$oid) {
  5091. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5092. exit;
  5093. }
  5094. if (($this->entity->standardKey) and (isset($_REQUEST[$form->entity->entity_1->fields[0]['name']]))) {
  5095. $_REQUEST[$form->entity->fields[0]['name']] = $_REQUEST[$form->entity->entity_1->fields[0]['name']];
  5096. }
  5097. foreach($_REQUEST as $key2=>$value2) {
  5098. if (ereg("{$form->elements[0]['name']}_",$key2)) {
  5099. switch ($form->elements[0]['orientation']) {
  5100. case RIGHT:
  5101. $query = "INSERT INTO {$form->entity->name} VALUES('{$_REQUEST[$form->entity->fields[0]['name']]}','{$_REQUEST[$key2]}')";
  5102. break;
  5103. case LEFT:
  5104. $query = "INSERT INTO {$form->entity->name} VALUES('{$_REQUEST[$key2]}','{$_REQUEST['value']}')";
  5105. break;
  5106. }
  5107. $oid = mysql_query($query);
  5108. if (!$oid) {
  5109. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_RELATION_INSERT)." (".basename(__FILE__).":".__LINE__.")";
  5110. exit;
  5111. }
  5112. }
  5113. }
  5114. }
  5115. }
  5116. $this->noDelete = $noDelete;
  5117. $content = $this->display(EDIT,2,PRELOAD);
  5118. if (!$this->moderationMode) {
  5119. $GLOBALS['main']->setContent("message",$GLOBALS['message']->getMessage(NOTIFY_ITEM_UPDATED));
  5120. }
  5121. }
  5122. $this->editItem_postUpdate();
  5123. break;
  5124. case 3:
  5125. /* DELETION */
  5126. $this->editItem_preDeletion();
  5127. if ($this->entity->deleteItem()) {
  5128. $msgCode = NOTIFY_ITEM_DELETED;
  5129. } else {
  5130. $msgCode = NOTIFY_ITEM_INTEGRITY_VIOLATION;
  5131. }
  5132. $this->editItem_postDeletion();
  5133. Header("Location: ".basename($_SERVER['SCRIPT_NAME'])."?action=edit&page=0&msgCode={$msgCode}");
  5134. exit;
  5135. break;
  5136. }
  5137. return $content;
  5138. }
  5139. function editItem2($noDelete = false) {
  5140. if (!isset($_REQUEST['page'])) {
  5141. $page = 0;
  5142. } else {
  5143. $page = $_REQUEST['page'];
  5144. }
  5145. switch ($page) {
  5146. case 0:
  5147. /* SHOW ITEMS - SELECTION LIST */
  5148. /*
  5149. $this->editItem_preSelection();
  5150. if (isset($_REQUEST['msgCode'])) {
  5151. $GLOBALS['main']->setContent("message",$GLOBALS['message']->getMessage($_REQUEST['msgCode']));
  5152. }
  5153. */
  5154. /* sono dentro form */
  5155. /*
  5156. if (isset($this->filterRelation)) {
  5157. $data = $this->entity->getReferenceByRelation($this->filterRelation);
  5158. } else {
  5159. $data = $this->entity->getReference();
  5160. }
  5161. $body = new Template("{$this->templatePath}/report.html");
  5162. $body->setContent("item",$data);
  5163. $content = $body->get();
  5164. $this->editItem_postSelection();
  5165. */
  5166. $this->editItem_preSelection();
  5167. if (isset($_REQUEST['msgCode'])) {
  5168. $GLOBALS['main']->setContent("message",$GLOBALS['message']->getMessage($_REQUEST['msgCode']));
  5169. }
  5170. /* sono dentro form */
  5171. $body = new Template("{$this->reportTemplate}");
  5172. $body->setContent("page", 1);
  5173. $body->setContent("item", $this->entity->name);
  5174. $content = "<div id=\"becontent\">\n\n".$body->get()."\n</div>\n";
  5175. $this->editItem_postSelection();
  5176. break;
  5177. case 1:
  5178. /* FORM FEED */
  5179. $this->editItem_preFormFeed();
  5180. $oid = mysql_query("SELECT * FROM {$this->entity->name}
  5181. WHERE {$this->entity->fields[0]['name']}='{$_REQUEST['value']}'");
  5182. if (!$oid) {
  5183. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5184. exit;
  5185. }
  5186. $data = mysql_fetch_assoc($oid);
  5187. if ((count($data) > 0) and ($data != "")) {
  5188. foreach($data as $k => $v) {
  5189. $_REQUEST[$k] = $v;
  5190. }
  5191. }
  5192. /* the following is about N-M relations */
  5193. if ((count($this->triggeredForms)>0) and ($this->triggeredForms != "")) {
  5194. foreach($this->triggeredForms as $k => $form) {
  5195. switch($form->elements[0]['orientation']) {
  5196. case RIGHT:
  5197. $query = "SELECT * FROM {$form->entity->name}
  5198. WHERE {$form->entity->fields[0]['name']}='{$_REQUEST['value']}'";
  5199. break;
  5200. case LEFT:
  5201. $query = "SELECT * FROM {$form->entity->name}
  5202. WHERE {$form->entity->fields[1]['name']}='{$_REQUEST['value']}'";
  5203. break;
  5204. }
  5205. $oid = mysql_query($query);
  5206. if (!$oid) {
  5207. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5208. exit;
  5209. }
  5210. do {
  5211. $data = mysql_fetch_array($oid);
  5212. #print_r($data);
  5213. #echo "<hr>";
  5214. if ($data) {
  5215. switch($form->elements[0]['orientation']) {
  5216. case RIGHT:
  5217. #echo "RIGHT <br>";
  5218. $_REQUEST["{$form->elements[0]['name']}_{$data[1]}"] = $data[1];
  5219. break;
  5220. case LEFT:
  5221. #echo "LEFT <br>";
  5222. $_REQUEST["{$form->elements[0]['name']}_{$data[0]}"] = $data[0];
  5223. break;
  5224. }
  5225. #echo " right REQUEST[{$form->elements[0]['name']}_{$data[1]}] = {$data[1]}<br>";
  5226. #echo " left REQUEST[{$form->elements[0]['name']}_{$data[0]}] = {$data[0]} <br>";
  5227. }
  5228. } while ($data);
  5229. }
  5230. }
  5231. /* here */
  5232. $this->noDelete = $noDelete;
  5233. $content = $this->display(EDIT,2,PRELOAD);
  5234. $this->editItem_postFormFeed();
  5235. break;
  5236. case 2:
  5237. /* UPDATE */
  5238. $this->editItem_preUpdate();
  5239. $entity = $this->entity;
  5240. if (!$entity->editItem()) {
  5241. /* An error occourred */
  5242. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5243. } else {
  5244. /* Pivotal entity has been succesfully updated */
  5245. if (!isset($_REQUEST['value'])) {
  5246. $_REQUEST['value'] = "";
  5247. }
  5248. $query = "SELECT * FROM {$this->entity->name} WHERE {$this->entity->fields[0]['name']}='{$_REQUEST['value']}'";
  5249. $oid = mysql_query($query);
  5250. if (!$oid) {
  5251. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5252. exit;
  5253. }
  5254. $data = mysql_fetch_assoc($oid);
  5255. if ((count($data) > 0) and ($data != "")) {
  5256. foreach($data as $k => $v) {
  5257. $_REQUEST[$k] = $v;
  5258. }
  5259. }
  5260. if ((count($this->triggeredForms)>0) and ($this->triggeredForms != "")) {
  5261. foreach($this->triggeredForms as $k => $form) {
  5262. #echo "<hr><b>{$form->name}</b> ";
  5263. #echo "{$form->entity->entity_1->fields[0]['name']}: {$_REQUEST[$form->entity->entity_1->fields[0]['name']]}<hr>";
  5264. #print_r($_REQUEST);
  5265. #echo "<hr>";
  5266. switch ($form->elements[0]['orientation']) {
  5267. case RIGHT:
  5268. #$query = "DELETE FROM {$form->entity->name} WHERE {$form->entity->fields[0]['name']}='{$_REQUEST[$form->entity->fields[0]['name']]}'";
  5269. $query = "DELETE FROM {$form->entity->name} WHERE {$form->entity->fields[0]['name']}='{$_REQUEST['value']}'";
  5270. break;
  5271. case LEFT:
  5272. $query = "DELETE FROM {$form->entity->name} WHERE {$form->entity->fields[1]['name']}='{$_REQUEST['value']}'";
  5273. break;
  5274. }
  5275. #echo "$query<hr>";
  5276. $oid = mysql_query($query);
  5277. if (!$oid) {
  5278. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5279. exit;
  5280. }
  5281. if (($this->entity->standardKey) and (isset($_REQUEST[$form->entity->entity_1->fields[0]['name']]))) {
  5282. $_REQUEST[$form->entity->fields[0]['name']] = $_REQUEST[$form->entity->entity_1->fields[0]['name']];
  5283. }
  5284. foreach($_REQUEST as $key2=>$value2) {
  5285. if (ereg("{$form->elements[0]['name']}_",$key2)) {
  5286. switch ($form->elements[0]['orientation']) {
  5287. case RIGHT:
  5288. $query = "INSERT INTO {$form->entity->name} VALUES('{$_REQUEST[$form->entity->fields[0]['name']]}','{$_REQUEST[$key2]}')";
  5289. break;
  5290. case LEFT:
  5291. $query = "INSERT INTO {$form->entity->name} VALUES('{$_REQUEST[$key2]}','{$_REQUEST['value']}')";
  5292. break;
  5293. }
  5294. #echo "<b>Insert:</b> $query<hr>";
  5295. $oid = mysql_query($query);
  5296. if (!$oid) {
  5297. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_RELATION_INSERT)." (".basename(__FILE__).":".__LINE__.")";
  5298. exit;
  5299. }
  5300. }
  5301. }
  5302. }
  5303. }
  5304. $this->noDelete = $noDelete;
  5305. $content = $this->display(EDIT,2,PRELOAD);
  5306. if (!$this->moderationMode) {
  5307. $GLOBALS['main']->setContent("message",$GLOBALS['message']->getMessage(NOTIFY_ITEM_UPDATED));
  5308. }
  5309. }
  5310. $this->editItem_postUpdate();
  5311. break;
  5312. case 3:
  5313. /* DELETION */
  5314. $this->editItem_preDeletion();
  5315. if ($this->entity->deleteItem()) {
  5316. $msgCode = NOTIFY_ITEM_DELETED;
  5317. } else {
  5318. $msgCode = NOTIFY_ITEM_INTEGRITY_VIOLATION;
  5319. }
  5320. $this->editItem_postDeletion();
  5321. Header("Location: ".basename($_SERVER['SCRIPT_NAME'])."?action=edit&page=0&msgCode={$msgCode}");
  5322. exit;
  5323. break;
  5324. }
  5325. return $content;
  5326. }
  5327. function validateItem() {
  5328. /*
  5329. This method is used by the Moderator, s/he can edit the item and
  5330. accept it, the AAD check is done by auth.inc.php.
  5331. */
  5332. $this->setModerationMode();
  5333. $script = basename($_SERVER['SCRIPT_FILENAME']);
  5334. if (ereg("([[:alnum:]]*)\-manager", $script, $token)) {
  5335. $entityName = $token[1];
  5336. }
  5337. $entity = $GLOBALS['database']->getEntityByName($entityName);
  5338. $keyName = $entity->fields[0]['name'];
  5339. if (isset($_REQUEST['moderationResult'])) {
  5340. $oid = mysql_query("SELECT {$entityName}.username,
  5341. users.name,
  5342. users.surname,
  5343. users.email
  5344. FROM {$entityName}
  5345. LEFT JOIN users
  5346. ON users.username = {$entityName}.username
  5347. WHERE {$entityName}.{$keyName}='{$_REQUEST[$keyName]}'");
  5348. if (!$oid) {
  5349. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5350. exit;
  5351. }
  5352. $data = mysql_fetch_assoc($oid);
  5353. switch ($_REQUEST['moderationResult']) {
  5354. case "ACCEPT":
  5355. $oid = mysql_query("UPDATE {$entityName} SET passed = '' WHERE {$keyName}='{$_REQUEST[$keyName]}'");
  5356. if (!$oid) {
  5357. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5358. exit;
  5359. }
  5360. $mail = new Template("dtml/mail_moderation_accept.html");
  5361. $msgCode = MODERATION_ACCEPT;
  5362. break;
  5363. case "REFUSE":
  5364. $oid = mysql_query("DELETE FROM {$entityName} WHERE {$keyName}='{$_REQUEST[$keyName]}'");
  5365. if (!$oid) {
  5366. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5367. exit;
  5368. }
  5369. $mail = new Template("dtml/mail_moderation_refuse.html");
  5370. if (isset($_REQUEST['refuse']) and (strip_tags($_REQUEST['refuse']))) {
  5371. $_REQUEST['refuse'] = "\nThe editor motivated his/her decision as follows:\n\n".$_REQUEST['refuse']."\n";
  5372. $_REQUEST['refuse'] = ereg_replace("<br />","\n", $_REQUEST['refuse']);
  5373. $mail->setContent("refuse", strip_tags($_REQUEST['refuse']));
  5374. }
  5375. $msgCode = MODERATION_REFUSE;
  5376. break;
  5377. }
  5378. $mail->setContent("name", "{$data['name']} ({$data['username']})");
  5379. mail($data['email'], "model-transformation.org", $mail->get(),"From: {$_SESSION['user']['username']}");
  5380. Header("Location: message.php?msgCode={$msgCode}");
  5381. exit;
  5382. }
  5383. $this->addSection("Note for the author");
  5384. $this->addTextarea("refuse","Why refuse?", 10,70);
  5385. $oid = mysql_query("SELECT *
  5386. FROM {$entityName}
  5387. WHERE {$entityName}.{$keyName}='{$_REQUEST['value']}' AND {$entityName}.passed='*'");
  5388. if (!$oid) {
  5389. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC)." (".basename(__FILE__).":".__LINE__.")";
  5390. exit;
  5391. }
  5392. if (mysql_num_rows($oid) == 0) {
  5393. $msgCode = MODERATION_EXPIRED;
  5394. Header("Location: message.php?msgCode={$msgCode}");
  5395. exit;
  5396. }
  5397. return $this->editItem(true);
  5398. }
  5399. function isPositionController($name) {
  5400. $trovato = false;
  5401. $i = 0;
  5402. do {
  5403. if ($this->elements[$i]['controlledField'] == $name) {
  5404. $trovato = true;
  5405. }
  5406. $i++;
  5407. } while ((not($trovato)) or ($i<count($this->elements)));
  5408. return $trovato;
  5409. }
  5410. function getPositionFromController($name) {
  5411. $trovato = false;
  5412. $i = 0;
  5413. do {
  5414. if ((isset($this->elements[$i]['controlledField'])) && ($this->elements[$i]['controlledField'] == $name)) {
  5415. $positionName = $this->elements[$i]['name'];
  5416. $trovato = true;
  5417. }
  5418. $i++;
  5419. } while ((!$trovato) and ($i<count($this->elements)));
  5420. if ($trovato) {
  5421. $trovato = false;
  5422. $i = 0;
  5423. do {
  5424. if ($this->elements[$i]['name'] == $positionName) {
  5425. $positionIndex = $i;
  5426. $trovato = true;
  5427. }
  5428. $i++;
  5429. } while ((!$trovato) and ($i<count($this->elements)));
  5430. return $this->elements[$positionIndex];
  5431. } else {
  5432. return false;
  5433. }
  5434. }
  5435. function update() {
  5436. /* This must be invoked only on N-M relations */
  5437. $relationManager = $this->elements[$this->relationManager];
  5438. #echo "<br>",$this->entity->name; // groups_services
  5439. #echo "<br>e1: ",$this->entity->entity_1->name; // groups
  5440. #echo "<br>e2: ",$this->entity->entity_2->name; // services
  5441. switch($relationManager['orientation']) {
  5442. case LEFT:
  5443. $leftEntity = $this->entity->entity_1;
  5444. $rightEntity = $this->entity->entity_2;
  5445. break;
  5446. case RIGHT:
  5447. $leftEntity = $this->entity->entity_2;
  5448. $rightEntity = $this->entity->entity_1;
  5449. break;
  5450. }
  5451. $prova = $leftEntity->getReference();
  5452. /*
  5453. $data = getResult("SELECT groups.name AS groups_name,
  5454. groups.id AS groups_id,
  5455. services.name AS services_name,
  5456. services.id AS services_id,
  5457. IF ( groups_services.id_groups IS NULL ,'','*') AS enabled
  5458. FROM groups, services
  5459. LEFT JOIN groups_services
  5460. ON groups_services.id_groups = groups.id
  5461. AND groups_services.id_services = services.id
  5462. ORDER BY groups.id, services_id");
  5463. */
  5464. $data = aux::getResult("
  5465. SELECT {$leftEntity->name}.name AS groups_name,
  5466. groups.id AS groups_id,
  5467. services.name AS services_name,
  5468. services.id AS services_id,
  5469. IF ( groups_services.id_groups IS NULL ,'','*') AS enabled
  5470. FROM groups, services
  5471. LEFT JOIN groups_services
  5472. ON groups_services.id_groups = groups.id
  5473. AND groups_services.id_services = services.id
  5474. ORDER BY groups.id, services_id");
  5475. switch($relationManager['orientation']) {
  5476. case LEFT:
  5477. $content .= "\n<!-- BEGIN RELATION MANAGER ORIENT_LEFT -->\n";
  5478. $content .= "<table border=\"0\">\n";
  5479. $content .= "</table>\n";
  5480. $content .= "<!-- END RELATION MANAGER -->\n";
  5481. break;
  5482. }
  5483. return $content;
  5484. }
  5485. function emitJavaScript($operation, $page, $preload) {
  5486. $content = "";
  5487. if (!$this->triggered) { // if it is a main form
  5488. /* javascript validation prefix is generated only if the form is the main
  5489. form and not the triggered one.
  5490. ** Rationale: the emitJS function is invoked recursively over the triggered
  5491. form, thus we need to generate the js prefix only for the main form, for
  5492. the triggered form only eventual validation is required. */
  5493. $content .= "<!-- open main form script -->\n";
  5494. $content .= "<script>\n\n";
  5495. if ($operation == EDIT) {
  5496. $content .= "function delete_{$this->name}() {\n";
  5497. $content .= "var form = document.forms['{$this->name}'];\n\n";
  5498. $content .= " form.page.value=3;\n";
  5499. $content .= " if (!confirm('".$GLOBALS['message']->getMessage(MSG_JS_SURE)."')) {\n";
  5500. $content .= " return; \n";
  5501. $content .= " }\n";
  5502. $content .= " form.submit();\n";
  5503. $content .= "}\n\n\n";
  5504. if ($this->moderationMode) {
  5505. $content .= "function accept_{$this->name}() {\n";
  5506. $content .= "var form = document.forms['{$this->name}'];\n\n";
  5507. $content .= " form.moderationResult.value='ACCEPT';\n\n";
  5508. $content .= " form.submit();\n";
  5509. $content .= "}\n\n\n";
  5510. $content .= "function refuse_{$this->name}() {\n";
  5511. $content .= "var form = document.forms['{$this->name}'];\n\n";
  5512. $content .= " form.moderationResult.value='REFUSE';\n\n";
  5513. $content .= " if (!confirm('".$GLOBALS['message']->getMessage(MSG_JS_SURE)."')) {\n";
  5514. $content .= " return; \n";
  5515. $content .= " }\n";
  5516. //$content .= " if (form.refuse.value == '') {\n";
  5517. //$content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_MODERATION)."');";
  5518. //$content .= " return; \n";
  5519. //$content .= " }\n";
  5520. $content .= " form.submit();\n";
  5521. $content .= "}\n\n\n";
  5522. }
  5523. }
  5524. $content .= "function submit_{$this->name}() {\n";
  5525. $content .= "var form = document.forms['{$this->name}'];\n\n";
  5526. }
  5527. /* the rest is executed for both the triggering and triggered form */
  5528. foreach($this->elements as $k => $v) {
  5529. if ((isset($v["mandatory"])) && ($v["mandatory"] == strtolower("yes"))) {
  5530. switch ($v["type"]) {
  5531. case "text":
  5532. case "date":
  5533. case "link":
  5534. $content .= " if (form.{$v['name']}.value == '') {\n";
  5535. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_INSERT,$v)."');\n";
  5536. $content .= " return;\n";
  5537. $content .= " }\n";
  5538. break;
  5539. case LONGDATE:
  5540. $content .= " if (form.{$v['name']}.value == '') {\n";
  5541. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_INSERT,$v)."');\n";
  5542. $content .= " return;\n";
  5543. $content .= " }\n";
  5544. $content .= " if (form.{$v['name']}_time.value == '') {\n";
  5545. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_INSERT_TIME,$v)."');\n";
  5546. $content .= " return;\n";
  5547. $content .= " }\n";
  5548. break;
  5549. case "password":
  5550. /* The password even if specified mandatory must be entered only in the
  5551. ADD operation, while in the EDIT one if password is empty must be left
  5552. simply unchanged */
  5553. if ($operation == ADD) {
  5554. $content .= " if (form.{$v['name']}.value == '') {\n";
  5555. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_INSERT,$v)."');\n";
  5556. $content .= " return;\n";
  5557. $content .= " }\n";
  5558. }
  5559. break;
  5560. case "textarea":
  5561. case "editor":
  5562. case FILE:
  5563. case FILE2FOLDER:
  5564. $content .= " if (form.{$v['name']}.value == '') {\n";
  5565. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_INSERT,$v)."');\n";
  5566. $content .= " return;\n";
  5567. $content .= " }\n";
  5568. break;
  5569. case "select":
  5570. $content .= " if (form.{$v['name']}.selectedIndex == 0) {\n";
  5571. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_SELECT,$v)."');\n";
  5572. $content .= " return;\n";
  5573. $content .= " }\n";
  5574. break;
  5575. case "selectFromReference":
  5576. $content .= " if (form.{$v['name']}.selectedIndex == 0) {\n";
  5577. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_SELECT,$v)."');\n";
  5578. $content .= " return;\n";
  5579. $content .= " }\n";
  5580. break;
  5581. case RADIO_FROM_REFERENCE:
  5582. $content .=" ischecked = false;\n";
  5583. $content .=" for(i=0;i<form.{$v['name']}.length;i++) {\n";
  5584. $content .=" if (form.{$v['name']}[i].checked == true) {\n";
  5585. $content .=" ischecked = true;\n";
  5586. $content .=" }\n";
  5587. $content .=" }\n";
  5588. $content .=" if (ischecked == false) {\n";
  5589. $content .=" alert('".$GLOBALS['message']->getMessage(MSG_JS_RADIO,$v)."');\n";
  5590. $content .=" return;\n";
  5591. $content .=" }\n";
  5592. break;
  5593. case RELATION_MANAGER:
  5594. $content .= " /* Relation Manager */\n\n";
  5595. $content .= " trovato = false;\n";
  5596. $content .= " for(i=0;i<form.elements.length;i++) {\n";
  5597. $content .= " if (!isUndefined(form.elements[i].name)) {\n";
  5598. $content .= " if (form.elements[i].name.search('{$v['name']}_') == 0) {\n";
  5599. $content .= " if (form.elements[i].checked) {\n";
  5600. $content .= " trovato = true;\n";
  5601. $content .= " }\n";
  5602. $content .= " }\n";
  5603. $content .= " }\n";
  5604. #$content .= " }\n";
  5605. $content .= " if (trovato == false) {\n";
  5606. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_RELATIONMANAGER,$v)."');\n";
  5607. $content .= " return;\n";
  5608. $content .= " }\n";
  5609. break;
  5610. }
  5611. }
  5612. if ($v['type'] == "position") { // POSITION ALL
  5613. $content .= " for(var i=0; i<form.{$v['name']}.options.length; i++) {\n";
  5614. $content .= " j=i+1;\n";
  5615. $content .= " form.{$v['name']}_all.value = form.{$v['name']}_all.value+form.{$v['name']}.options[i].value+':';\n";
  5616. $content .= " }\n";
  5617. }
  5618. if ($v['type'] == "hierarchicalPosition") { // POSITION ALL
  5619. $content .= " for(var i=0; i<form.{$v['name']}.options.length; i++) {\n";
  5620. $content .= " j=i+1;\n";
  5621. $content .= " form.{$v['name']}_all.value = form.{$v['name']}_all.value+form.{$v['name']}.options[i].value+':';\n";
  5622. $content .= " }\n";
  5623. }
  5624. if ($v['type'] == "color") { // COLOR
  5625. $content .= " var color_obj = document.getElementById('plugHEX');\n";
  5626. $content .= " form.{$v['name']}.value = color_obj.innerHTML;\n";
  5627. }
  5628. if (($v['type'] == FILE2FOLDER) or ($v['type'] == FILE) and (isset($v['filterByExtension']))) {
  5629. #if (isset($v['filterByExtension'])) {
  5630. $count = strlen($v['filterByExtension']);
  5631. $content .= " if (form.{$v['name']}.value != '') {\n";
  5632. $content .= " if (form.{$v['name']}.value.match('.{$v['filterByExtension']}') == null) {\n";
  5633. if ($v['message'] == "") {
  5634. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_EXTENSION,$v)."');\n";
  5635. } else {
  5636. $content .= " alert('".$GLOBALS['message']->getMessage(WARNING,$v).": {$v['message']}');\n";
  5637. }
  5638. $content .= " return;\n";
  5639. $content .= " }\n";
  5640. $content .= " }\n";
  5641. }
  5642. }
  5643. if (count($this->conditions)>0) {
  5644. foreach($this->conditions as $k => $v) {
  5645. switch($v['condition']) {
  5646. case "equal":
  5647. $content .= " if (form.{$v['element_1']}.value != form.{$v['element_2']}.value) { \n";
  5648. if ($v['message'] == "") {
  5649. $content .= " alert('Warning: \'{$v['label_1']}\' and \'{$v['label_2']}\' are not equal!');\n";
  5650. } else {
  5651. $content .= " alert('Warning: {$v['message']}!');\n";
  5652. }
  5653. $content .= " return;";
  5654. $content .= " }\n";
  5655. break;
  5656. case IMPLIES:
  5657. if ($operation == EDIT) {
  5658. switch ($v['obj_1']['type']) {
  5659. case "selectFromReference":
  5660. case "select":
  5661. $content .= " if (form.{$v['element_1']}.selectedIndex != 0) {\n";
  5662. break;
  5663. case "text":
  5664. case FILE:
  5665. case FILE2FOLDER:
  5666. $content .= " if ((form.{$v['element_1']}_hidden.value != '')||(form.{$v['element_1']}.value != '')) {\n";
  5667. break;
  5668. }
  5669. switch ($v['obj_2']['type']) {
  5670. case "selectFromReference":
  5671. case "select":
  5672. $content .= " if (form.{$v['element_2']}.selectedIndex == 0) {\n";
  5673. break;
  5674. case "text":
  5675. case FILE:
  5676. $content .= " if (form.{$v['element_2']}.value == '') {\n";
  5677. break;
  5678. }
  5679. if ($v['message'] == "") {
  5680. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_IMPLIES,$v)."');\n";
  5681. } else {
  5682. $content .= " alert('".$GLOBALS['message']->getMessage(WARNING,$v).": {$v['message']}');\n";
  5683. }
  5684. $content .= " return;";
  5685. $content .= " }\n";
  5686. $content .= " }\n";
  5687. } else {
  5688. switch ($v['obj_1']['type']) {
  5689. case "selectFromReference":
  5690. case "select":
  5691. $content .= " if (form.{$v['element_1']}.selectedIndex != 0) {\n";
  5692. break;
  5693. case "text":
  5694. case FILE:
  5695. case FILE2FOLDER:
  5696. $content .= " if (form.{$v['element_1']}.value != '') {\n";
  5697. break;
  5698. }
  5699. switch ($v['obj_2']['type']) {
  5700. case "selectFromReference":
  5701. case "select":
  5702. $content .= " if (form.{$v['element_2']}.selectedIndex == 0) {\n";
  5703. break;
  5704. case "text":
  5705. $content .= " if (form.{$v['element_2']}.value == '') {\n";
  5706. break;
  5707. }
  5708. if ($v['message'] == "") {
  5709. $content .= " alert('".$GLOBALS['message']->getMessage(MSG_JS_IMPLIES,$v)."');\n";
  5710. } else {
  5711. $content .= " alert('".$GLOBALS['message']->getMessage(WARNING,$v).": {$v['message']}');\n";
  5712. }
  5713. $content .= " return;";
  5714. $content .= " }\n";
  5715. $content .= " }\n";
  5716. }
  5717. break;
  5718. case "date le":
  5719. case "date less equal":
  5720. $content .= " d1 = form.{$v['element_1']}.value.substring(0,2);";
  5721. $content .= " d2 = form.{$v['element_2']}.value.substring(0,2);";
  5722. $content .= " m1 = form.{$v['element_1']}.value.substring(3,5);";
  5723. $content .= " m2 = form.{$v['element_2']}.value.substring(3,5);";
  5724. $content .= " y1 = form.{$v['element_1']}.value.substring(6,10);";
  5725. $content .= " y2 = form.{$v['element_2']}.value.substring(6,10);";
  5726. $content .= " el_1 = y1+m1+d1;";
  5727. $content .= " el_2 = y2+m2+d2;";
  5728. #$content .= " alert(y1);\n";
  5729. $content .= " if (el_1 > el_2) { \n";
  5730. if ($v['message'] == "") {
  5731. $content .= " alert('Warning: \'{$v['label_1']}\' and \'{$v['label_2']}\' are not equal!');\n";
  5732. } else {
  5733. $content .= " alert('Warning: {$v['message']}!');\n";
  5734. }
  5735. $content .= " return;";
  5736. $content .= " }\n";
  5737. break;
  5738. }
  5739. }
  5740. }
  5741. if ((count($this->triggeredForms)>0) and ($this->triggeredForms != "")) {
  5742. foreach($this->triggeredForms as $k => $form) {
  5743. $content .= $form->emitJavaScript($operation, $page, $preload);
  5744. }
  5745. }
  5746. if (!$this->triggered) { // if it is the main form
  5747. /* The submit function is closed only in the case of the main function ?? */
  5748. $content .= " form.submit();\n";
  5749. $content .= "}\n\n";
  5750. $content .= "</script>\n";
  5751. $content .= "<!-- close main form script -->\n\n ";
  5752. }
  5753. return $content;
  5754. }
  5755. function emitHTML($operation, $page, $preload) {
  5756. #global $data, $tree_value, $tree_text;
  5757. /* Preamble */
  5758. $content = "";
  5759. if (!$this->triggered) { // if it is the main form
  5760. $content .= "\n<!-- MAIN FORM START -->\n";
  5761. $content .= "<div id=\"becontent\">\n";
  5762. $content .= "<form name=\"{$this->name}\" method=\"{$this->method}\" {$this->enctype}>\n";
  5763. $content .= " <input type=\"hidden\" name=\"page\" value=\"{$page}\">\n";
  5764. switch($operation) {
  5765. case ADD:
  5766. /*
  5767. it generates an session_id and a name session_id_name for it dependant from the entity name. These
  5768. are used for form
  5769. <input type=\"hidden\" name=\"{$session_id_name}\" value=\"{$session_id}\">
  5770. and in the sessione
  5771. $_SESSION[$session_id_name] = $session_id;
  5772. Thus, once the data are sent back to the application the following holds
  5773. $_REQUEST[$session_id_name] == $_SESION[$session_id_name].
  5774. We want to distinguish the following cases:
  5775. 1. the form is freshly generated
  5776. 2. the data are valid
  5777. 3. the data are not valid
  5778. */
  5779. $session_id_name = "S_".md5($this->entity->name);
  5780. $session_id = md5(microtime());
  5781. $_SESSION[$session_id_name] = $session_id;
  5782. $content .= " <input type=\"hidden\" name=\"{$session_id_name}\" value=\"{$session_id}\">\n";
  5783. $content .= " <input type=\"hidden\" name=\"action\" value=\"add\">\n";
  5784. break;
  5785. case EDIT:
  5786. /* this is used also for the validation */
  5787. if (!isset($_REQUEST[$this->entity->fields[0]['name']])) {
  5788. $_REQUEST[$this->entity->fields[0]['name']] = "";
  5789. }
  5790. $content .= " <input type=\"hidden\" name=\"{$this->entity->fields[0]['name']}\" value=\"{$_REQUEST[$this->entity->fields[0]['name']]}\">\n";
  5791. $content .= " <input type=\"hidden\" name=\"value\" value=\"{$_REQUEST[$this->entity->fields[0]['name']]}\">\n";
  5792. /* Moderation Mode deprecated ? */
  5793. if (!$this->moderationMode) {
  5794. $content .= " <input type=\"hidden\" name=\"action\" value=\"edit\">\n";
  5795. } else {
  5796. $content .= " <input type=\"hidden\" name=\"action\" value=\"validate\">\n";
  5797. }
  5798. if ($this->entity->owner) {
  5799. $content .= " <input type=\"hidden\" name=\"creation\" value=\"{$_REQUEST['creation']}\">\n";
  5800. $content .= " <input type=\"hidden\" name=\"username\" value=\"{$_REQUEST['username']}\">\n";
  5801. }
  5802. break;
  5803. }
  5804. $content .= " <table border=\"0\">\n";
  5805. }
  5806. /* Emitting widgets */
  5807. foreach($this->elements as $k => $v) {
  5808. if (($operation == EDIT) and ($v['name'] == $this->entity->fields[0]['name'])) {
  5809. $disabled = " disabled";
  5810. } else {
  5811. $disabled = "";
  5812. }
  5813. $content .= " <tr>\n";
  5814. switch ($v["type"]) {
  5815. case HIDDEN:
  5816. $content.= "<input type=\"hidden\" name=\"{$v['name']}\" value=\"{$v['value']}\" />\n";
  5817. break;
  5818. case "text": // TEXT
  5819. $onChange = "";
  5820. if ($position = $this->getPositionFromController($v['name'])) {
  5821. if ($preload) {
  5822. $onChange = " onChange=\"my_updatePosition_preload('{$this->name}', '{$position['name']}', this, '{$this->entity->fields[0]['name']}');\"";
  5823. } else {
  5824. $onChange = " onChange=\"my_updatePosition('{$this->name}', '{$position['name']}', this);\"";
  5825. }
  5826. }
  5827. if ($v['mandatory']) {
  5828. $mandatory = "";
  5829. } else {
  5830. $mandatory = "";
  5831. }
  5832. if (isset($this->helpers[$v['name']])) {
  5833. $content .= " <td>{$v["label"]} <a href=\"javascript:showHelper(this,'{$this->helpers[$v['name']]}')\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  5834. } else {
  5835. $content .= " <td>{$v["label"]} {$mandatory}</td>\n";
  5836. }
  5837. if ($preload) {
  5838. if (($this->entity->addslashes) && (isset($_REQUEST[$v['name']]))) {
  5839. $_REQUEST[$v['name']] = stripslashes($_REQUEST[$v['name']]);
  5840. }
  5841. /* HTML ENTITIES DECODE ? */
  5842. #$_REQUEST[$v['name']] = html_entity_decode($_REQUEST[$v['name']]);
  5843. if ($v['maxlength'] != "") {
  5844. if (!isset($_REQUEST[$v['name']])) {
  5845. $_REQUEST[$v['name']] = "";
  5846. }
  5847. $content .= " <td><input type=\"{$v['type']}\" id=\"{$v['name']}\" name=\"{$v['name']}\" value=\"{$_REQUEST[$v['name']]}\" size=\"{$v['size']}\" {$onChange} {$disabled}></td>\n";
  5848. } else {
  5849. if (!isset($_REQUEST[$v['name']])) {
  5850. $_REQUEST[$v['name']] = '';
  5851. }
  5852. $content .= " <td><input type=\"{$v['type']}\" id=\"{$v['name']}\" name=\"{$v['name']}\" value=\"{$_REQUEST[$v['name']]}\" size=\"{$v['size']}\" maxlength=\"{$v[maxlength]}\" {$onChange} {$disabled}></td>\n";
  5853. }
  5854. } else {
  5855. if ($v['maxlength'] == "") {
  5856. $content .= " <td><input type=\"{$v['type']}\" id=\"{$v['name']}\" name=\"{$v['name']}\" size=\"$v[size]\" {$onChange} {$disabled}></td>\n";
  5857. } else {
  5858. $content .= " <td><input type=\"{$v['type']}\" id=\"{$v['name']}\" name=\"{$v['name']}\" size=\"{$v['size']}\" maxlength=\"{$v['maxlength']}\" {$onChange} {$disabled}></td>\n";
  5859. }
  5860. }
  5861. break;
  5862. case "link": // LINK
  5863. $onChange = "";
  5864. if ($position = $this->getPositionFromController($v['name'])) {
  5865. if ($preload) {
  5866. $onChange = " onChange=\"my_updatePosition_preload('{$this->name}', '{$position['name']}', this, '{$this->entity->fields[0]['name']}');\"";
  5867. } else {
  5868. $onChange = " onChange=\"my_updatePosition('{$this->name}', '{$position['name']}', this);\"";
  5869. }
  5870. }
  5871. if ($v['mandatory']) {
  5872. $mandatory = "";
  5873. } else {
  5874. $mandatory = "";
  5875. }
  5876. if (isset($this->helpers[$v['name']])) {
  5877. $content .= " <td>{$v["label"]} <a href=\"javascript:showHelper(this,'{$this->helpers[$v['name']]}')\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  5878. } else {
  5879. $content .= " <td>{$v["label"]} {$mandatory}</td>\n";
  5880. }
  5881. if ($preload) {
  5882. if (($this->entity->addslashes) && (isset($_REQUEST[$v['name']]))) {
  5883. $_REQUEST[$v['name']] = stripslashes($_REQUEST[$v['name']]);
  5884. }
  5885. /* HTML ENTITIES DECODE ? */
  5886. #$_REQUEST[$v['name']] = html_entity_decode($_REQUEST[$v['name']]);
  5887. if (isset($v['maxlength'])) {
  5888. if (!isset($_REQUEST[$v['name']])) {
  5889. $_REQUEST[$v['name']] = "";
  5890. }
  5891. $content .= " <td><input type=\"{$v['type']}\" id=\"{$v['name']}\" name=\"{$v['name']}\" value=\"{$_REQUEST[$v['name']]}\" size=\"{$v['size']}\" {$onChange} {$disabled}></td>\n";
  5892. } else {
  5893. if (!isset($_REQUEST[$v['name']])) {
  5894. $_REQUEST[$v['name']] = '';
  5895. }
  5896. $content .= " <td><input type=\"{$v['type']}\" id=\"{$v['name']}\" name=\"{$v['name']}\" value=\"{$_REQUEST[$v['name']]}\" size=\"{$v['size']}\" maxlength=\"{$v[maxlength]}\" {$onChange} {$disabled}></td>\n";
  5897. }
  5898. } else {
  5899. if ($v['maxlength']) {
  5900. $content .= " <td><input type=\"{$v['type']}\" id=\"{$v['name']}\" name=\"{$v['name']}\" size=\"$v[size]\" {$onChange} {$disabled}></td>\n";
  5901. } else {
  5902. $content .= " <td><input type=\"{$v['type']}\" id=\"{$v['name']}\" name=\"{$v['name']}\" size=\"{$v['size']}\" maxlength=\"{$v['maxlength']}\" {$onChange} {$disabled}></td>\n";
  5903. }
  5904. }
  5905. break;
  5906. case "password": // PASSWORD
  5907. #$content .= " <td>{$v["label"]}</td>\n";
  5908. if (isset($this->helpers[$v['name']])) {
  5909. $content .= " <td>{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  5910. } else {
  5911. $content .= " <td>{$v["label"]}</td>\n";
  5912. }
  5913. if ($v['maxlength']) {
  5914. $content .= " <td><input type=\"{$v['type']}\" name=\"{$v['name']}\" size=\"{$v['size']}\"></td>\n";
  5915. } else {
  5916. $content .= " <td><input type=\"{$v['type']}\" name=\"{$v['name']}\" size=\"{$v['size']}\" maxlength=\"{$v['maxlength']}\"></td>\n";
  5917. }
  5918. break;
  5919. case FILE: // FILE
  5920. if ($preload) {
  5921. if (isset($this->helpers[$v['name']])) {
  5922. $content .= " <td>{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  5923. } else {
  5924. $content .= " <td>{$v["label"]}</td>\n";
  5925. }
  5926. $content .= " <td><input style=\"float:left;\" type=\"file\" name=\"{$v['name']}\"> <input type=\"hidden\" name=\"{$v['name']}_hidden\" value=\"{$_REQUEST[$v['name']."_filename"]}\" />\n";
  5927. if ($_REQUEST[$v['name']]) {
  5928. switch ($_REQUEST[$v['name']."_type"]) {
  5929. case "image/jpeg":
  5930. case "image/gif":
  5931. /* IMAGE */
  5932. $content .= " <div class=\"image-show\" id=\"{$v['name']}\" >\n<input type=\"text\" class=\"file\" value=\"".$_REQUEST[$v['name']."_filename"]."\" disabled /><img src=\"img/beContent/show-gray.jpg\" onClick=\"image_show('{$v['name']}')\"><div id=\"{$v['name']}_img\">";
  5933. $content .= "<span>".$_REQUEST[$v['name']."_type"]."</span><br />\n<img class=\"left\" src=\"show.php?token=".md5($this->entity->name.$v['name'])."&id={$_REQUEST['value']}&width=188\">\n</div>\n</div>";
  5934. $content .= "&nbsp; <input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_delete\" value=\"*\"> ".$GLOBALS['message']->getMessage(MSG_FILE_DELETE);
  5935. break;
  5936. case "video/x-flv":
  5937. case "application/octet-stream":
  5938. /*
  5939. FLASH VIDEO FLV
  5940. The extension should be checked since anything can be
  5941. uploaded here.
  5942. */
  5943. $content .= " <div class=\"image-show\" id=\"{$v['name']}\" >\n<input type=\"text\" class=\"file\" value=\"".$_REQUEST[$v['name']."_filename"]."\" disabled /><img src=\"img/beContent/show-gray.jpg\" onClick=\"image_show('{$v['name']}')\">\n<div id=\"{$v['name']}_img\">\n";
  5944. $src= "show.php?token=".md5($this->entity->name.$v['name'])."&id={$_REQUEST['value']}";
  5945. $width = 200;
  5946. $height = 150;
  5947. $content .= "<script type=\"text/javascript\">\nAC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0','width','{$width}','height','{$height}','id','FLVPlayer2','src','FLVPlayer_Progressive','flashvars','&MM_ComponentVersion=1&skinName=includes/flv/players/player-unov&streamName={$src}&autoPlay=false&autoRewind=false','scale','noscale','name','FLVPlayer','salign','lt','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','FLVPlayer_Progressive' );\n</script>\n<noscript>\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"{$width}\" height=\"{$height}\" id=\"FLVPlayer2\">\n<param name=\"movie\" value=\"FLVPlayer_Progressive.swf\" />\n<param name=\"salign\" value=\"lt\" />\n<param name=\"scale\" value=\"noscale\" />\n<param name=\"FlashVars\" value=\"&MM_ComponentVersion=1&skinName=includes/flv/players/player-unov&streamName={$src}&autoPlay=false&autoRewind=false\" />\n<embed src=\"FLVPlayer_Progressive.swf\" flashvars=\"&MM_ComponentVersion=1&skinName=includes/flv/players/player-unov&streamName={$src}&autoPlay=false&autoRewind=false\" scale=\"noscale\" width=\"{$width}\" height=\"{$height}\" name=\"FLVPlayer\" salign=\"LT\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash\" />\n</object>\n</noscript>\n";
  5948. $content .= "</div>\n";
  5949. break;
  5950. default:
  5951. /* UNKNOWN MIME TYPE */
  5952. $content .= " <div class=\"image-show\" id=\"{$v['name']}\" ><input type=\"text\" class=\"file\" value=\"".$_REQUEST[$v['name']."_filename"]."\" disabled /><a target=\"_blank\" title=\"{$_REQUEST[$v['name']."_filename"]}\" href=\"show.php?token=".md5($this->entity->name.$v['name'])."&id={$_REQUEST['value']}\"><img src=\"img/beContent/show-gray-link.jpg\"></a></div>";
  5953. $content .= "<input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_delete\" value=\"*\"> ".$GLOBALS['message']->getMessage(MSG_FILE_DELETE);
  5954. break;
  5955. }
  5956. $content .= " </td>\n";
  5957. } else {
  5958. /* EMPTY */
  5959. $content .= " <div class=\"image-show\" ><input type=\"text\" class=\"file\" value=\"".$GLOBALS['message']->getMessage(MSG_FILE_NONE)."\" disabled /><img src=\"img/beContent/show-gray-disabled.jpg\"></div> </td>\n";
  5960. #$content .= "(".$GLOBALS['message']->getMessage(MSG_FILE_NONE).") </td>\n";
  5961. }
  5962. } else {
  5963. #$content .= " <td>{$v["label"]}</td>\n";
  5964. if (isset($this->helpers[$v['name']])) {
  5965. $content .= " <td>{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  5966. } else {
  5967. $content .= " <td>{$v["label"]}</td>\n";
  5968. }
  5969. $content .= " <td><input type=\"file\" name=\"{$v['name']}\"></td>\n";
  5970. }
  5971. break;
  5972. case FILE2FOLDER:
  5973. if ($preload) {
  5974. if (isset($this->helpers[$v['name']])) {
  5975. $content .= " <td>{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  5976. } else {
  5977. $content .= " <td>{$v["label"]}</td>\n";
  5978. }
  5979. $content .= " <td><input style=\"float:left;\" type=\"file\" name=\"{$v['name']}\"> <input type=\"hidden\" name=\"{$v['name']}_hidden\" value=\"{$_REQUEST[$v['name']."_reference"]}\" /> <input type=\"hidden\" name=\"{$v['name']}_reference\" value=\"{$_REQUEST[$v['name']."_reference"]}\" />\n";
  5980. if ($_REQUEST[$v['name']."_reference"]) {
  5981. switch ($_REQUEST[$v['name']."_type"]) {
  5982. case "image/jpeg":
  5983. case "image/gif":
  5984. $content .= " <div class=\"image-show\" id=\"{$v['name']}\" >\n<input type=\"text\" class=\"file\" value=\"".$_REQUEST[$v['name']."_filename"]."\" disabled /><img src=\"img/beContent/show-gray.jpg\" onClick=\"image_show('{$v['name']}')\"><div id=\"{$v['name']}_img\">";
  5985. $content .= "<span>".$_REQUEST[$v['name']."_type"]."</span><br />\n<img class=\"left\" src=\"show.php?token=".md5($this->entity->name.$v['name'])."&id={$_REQUEST['value']}&width=188\">\n</div>\n</div>";
  5986. $content .= "<input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_delete\" value=\"*\"> ".$GLOBALS['message']->getMessage(MSG_FILE_DELETE);
  5987. break;
  5988. case "video/x-flv":
  5989. case "application/octet-stream":
  5990. /*
  5991. 06.01.2008
  5992. FLASH VIDEO FLV
  5993. It may be suitable to check for the .flv extension since
  5994. the MIME may include anything.
  5995. */
  5996. $content .= " <div class=\"image-show\" id=\"{$v['name']}\" >\n<input type=\"text\" class=\"file\" value=\"".$_REQUEST[$v['name']."_filename"]."\" disabled /><img src=\"img/beContent/show-gray.jpg\" onClick=\"image_show('{$v['name']}')\">";
  5997. $content .= "<input class=\"file_delete\" type=\"checkbox\" name=\"{$v['name']}_delete\" value=\"*\"><span class=\"delete\">".$GLOBALS['message']->getMessage(MSG_FILE_DELETE)."</span>\n";
  5998. $content .= "<div id=\"{$v['name']}_img\">";
  5999. $src = "{$GLOBALS['config']['upload_folder']}/{$_REQUEST[$v['name']."_reference"]}";
  6000. $width = 186;
  6001. $height = 149;
  6002. $content .= "\n\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"{$width}\" height=\"{$height}\" id=\"FLVPlayer\">\n<param name=\"movie\" value=\"FLVPlayer_Progressive.swf\" />\n<param name=\"salign\" value=\"lt\" />\n<param name=\"quality\" value=\"high\" />\n<param name=\"scale\" value=\"scale\" />\n<param name=\"FlashVars\" value=\"&skinName=includes/flv/players/player-unov&streamName={$src}&autoPlay=false&autoRewind=false\" />\n<embed src=\"FLVPlayer_Progressive.swf\" flashvars=\"&skinName=includes/flv/players/player-unov&streamName={$src}&autoPlay=false&autoRewind=false\" quality=\"high\" scale=\"noscale\" width=\"{$width}\" height=\"{$height}\" name=\"FLVPlayer\" salign=\"LT\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />\n</object>\n\n";
  6003. $content .= "</div>\n";
  6004. break;
  6005. default:
  6006. /* UNKNOWN MIME TYPE */
  6007. $content .= " <div class=\"image-show\" id=\"{$v['name']}\" ><input type=\"text\" class=\"file\" value=\"".$_REQUEST[$v['name']."_filename"]."\" disabled /><a target=\"_blank\" title=\"{$_REQUEST[$v['name']."_filename"]}\" href=\"show.php?token=".md5($this->entity->name.$v['name'])."&id={$_REQUEST['value']}\"><img src=\"img/beContent/show-gray-link.jpg\"></a></div>";
  6008. $content .= "<input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_delete\" value=\"*\"> ".$GLOBALS['message']->getMessage(MSG_FILE_DELETE);
  6009. break;
  6010. }
  6011. $content .= " </td>\n";
  6012. } else {
  6013. /* Empty */
  6014. $content .= " <div class=\"image-show\" ><input type=\"text\" class=\"file\" value=\"".$GLOBALS['message']->getMessage(MSG_FILE_NONE)."\" disabled /><img src=\"img/beContent/show-gray-disabled.jpg\"></div> </td>\n";
  6015. }
  6016. } else {
  6017. if (isset($this->helpers[$v['name']])) {
  6018. $content .= " <td>{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6019. } else {
  6020. $content .= " <td>{$v["label"]}</td>\n";
  6021. }
  6022. $content .= " <td><input type=\"file\" name=\"{$v['name']}\"></td>\n";
  6023. }
  6024. break;
  6025. case "date": // DATE
  6026. if (isset($this->helpers[$v['name']])) {
  6027. $content .= " <td>{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6028. } else {
  6029. $content .= " <td>{$v["label"]}</td>\n";
  6030. }
  6031. if ($preload) {
  6032. $date = aux::formatDate($_REQUEST[$v['name']], STANDARD);
  6033. $content .= " <td><input name=\"{$v['name']}\" value=\"{$date}\"{$disabled}><img width=16 height=16 src=\"img/calendar/calendar.ico\" onclick=\"displayDatePicker('{$v['name']}');\" style=\"padding: 0px 0px 0px 2px;\"></td>\n";
  6034. } else {
  6035. if ($v['mandatory'] == MANDATORY) {
  6036. $today = date("d/m/Y");
  6037. } else {
  6038. $today = "";
  6039. }
  6040. $content .= " <td><input name=\"{$v['name']}\" value=\"{$today}\"{$disabled}><img width=16 height=16 src=\"img/calendar/calendar.ico\" onclick=\"displayDatePicker('{$v['name']}');\" style=\"padding: 0px 0px 0px 2px;\"></td>\n";
  6041. }
  6042. break;
  6043. case LONGDATE:
  6044. /* **** */
  6045. if (isset($this->helpers[$v['name']])) {
  6046. $content .= " <td>{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6047. } else {
  6048. $content .= " <td>{$v["label"]}</td>\n";
  6049. }
  6050. if ($preload) {
  6051. $date = aux::formatDate($_REQUEST[$v['name']], STANDARD);
  6052. ereg("([0-9][0-9])([0-9][0-9])$", $_REQUEST[$v['name']], $token);
  6053. $time = "{$token[1]}:{$token[2]}";
  6054. $content .= " <td><input name=\"{$v['name']}\" value=\"{$date}\"{$disabled}><img width=16 height=16 src=\"img/calendar/calendar.ico\" onclick=\"displayDatePicker('{$v['name']}');\" style=\"padding: 0px 0px 0px 2px;\"> <input name=\"{$v['name']}_time\" value=\"{$time}\" size=\"3\" {$disabled}> <span style=\"color: silver;\">(HH:mm)</span></td>\n";
  6055. } else {
  6056. if ($v['mandatory'] == MANDATORY) {
  6057. $today = date("d/m/Y");
  6058. $now = date("H:i");
  6059. } else {
  6060. $today = "";
  6061. $now = "";
  6062. }
  6063. $content .= " <td><input name=\"{$v['name']}\" value=\"{$today}\"{$disabled}><img width=16 height=16 src=\"img/calendar/calendar.ico\" onclick=\"displayDatePicker('{$v['name']}');\" style=\"padding: 0px 0px 0px 2px;\"> <input name=\"{$v['name']}_time\" value=\"{$now}\" size=\"3\" {$disabled}> <span style=\"color: silver;\">(HH:mm)</span></td>\n";
  6064. }
  6065. break;
  6066. case "color": // COLOR
  6067. if (isset($this->helpers[$v['name']])) {
  6068. $content .= " <td valign=\"top\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6069. } else {
  6070. $content .= " <td valign=\"top\">{$v["label"]}</td>\n";
  6071. }
  6072. if ($preload) {
  6073. $content .= "<input type='hidden' name='{$v['name']}' value='{$_REQUEST[$v['name']]}'>\n";
  6074. $content .= " <td valign=\"top\"><div id=\"plugin\" onmousedown=\"HSVslide('drag','plugin',event)\">
  6075. <div id=\"plugHEX\" onmousedown=\"stop=0; setTimeout('stop=1',100);\">{$_REQUEST[$v['name']]}</div>
  6076. <div id=\"SV\" onmousedown=\"HSVslide('SVslide','plugin',event)\" title=\"Saturation + Value\">
  6077. <div id=\"SVslide\" ><br /></div>
  6078. </div>
  6079. <div id=\"H\" onmousedown=\"HSVslide('Hslide','plugin',event)\" title=\"Hue\">
  6080. <div id=\"Hslide\" style=\"TOP: -7px; LEFT: -8px;\"></div>
  6081. <div id=\"Hmodel\"></div>
  6082. <br/>
  6083. <br/>
  6084. <br/>
  6085. </div>
  6086. </div></td>\n";
  6087. $content .= "<script type=\"text/javascript\"> function mkColor(v) { }
  6088. loadSV(); updateH('{$_REQUEST[$v['name']]}');
  6089. </script>";
  6090. } else {
  6091. $content .= "<input type='hidden' name='{$v['name']}' value='{$v['preset']}'>\n";
  6092. $content .= " <td valign=\"top\"><div id=\"plugin\" onmousedown=\"HSVslide('drag','plugin',event)\">
  6093. <div id=\"plugHEX\" onmousedown=\"stop=0; setTimeout('stop=1',100);\">{$v['preset']}</div>
  6094. <div id=\"SV\" onmousedown=\"HSVslide('SVslide','plugin',event)\" title=\"Saturation + Value\">
  6095. <div id=\"SVslide\" ><br /></div>
  6096. </div>
  6097. <div id=\"H\" onmousedown=\"HSVslide('Hslide','plugin',event)\" title=\"Hue\">
  6098. <div id=\"Hslide\" style=\"TOP: -7px; LEFT: -8px;\"></div>
  6099. <div id=\"Hmodel\"></div>
  6100. <br/>
  6101. <br/>
  6102. <br/>
  6103. </div>
  6104. </div></td>\n";
  6105. $content .= "<script type=\"text/javascript\"> function mkColor(v) { }
  6106. loadSV(); updateH('{$v['preset']}');
  6107. </script>";
  6108. }
  6109. break;
  6110. case "textarea": // TEXTAREA
  6111. #$content .= " <td valign=\"TOP\">{$v['label']}</td>\n";
  6112. if (isset($this->helpers[$v['name']])) {
  6113. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6114. } else {
  6115. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6116. }
  6117. if ($preload) {
  6118. if ($this->entity->addslashes) {
  6119. if (isset($_REQUEST[$v['name']])) {
  6120. $_REQUEST[$v['name']] = stripslashes($_REQUEST[$v['name']]);
  6121. } else {
  6122. $_REQUEST[$v['name']] = '';
  6123. }
  6124. }
  6125. /* HTML ENTITIES DECODE ? */
  6126. #$_REQUEST[$v['name']] = html_entity_decode($_REQUEST[$v['name']]);
  6127. if (!isset($_REQUEST[$v['name']])) {
  6128. $content .= " <td><textarea name=\"{$v['name']}\" cols=\"{$v['cols']}\" rows=\"{$v['rows']}\"></textarea></td>\n";
  6129. } else {
  6130. $content .= " <td><textarea name=\"{$v['name']}\" cols=\"{$v['cols']}\" rows=\"{$v['rows']}\">{$_REQUEST[$v['name']]}</textarea></td>\n";
  6131. }
  6132. } else {
  6133. $content .= " <td><textarea name=\"{$v['name']}\" cols=\"{$v['cols']}\" rows=\"{$v['rows']}\"></textarea></td>\n";
  6134. }
  6135. break;
  6136. case "editor": // EDITOR
  6137. #$content .= " <td valign=\"TOP\">{$v['label']}</td>\n";
  6138. if (isset($this->helpers[$v['name']])) {
  6139. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6140. } else {
  6141. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6142. }
  6143. if ($preload) {
  6144. if ($this->entity->addslashes) {
  6145. $_REQUEST[$v['name']] = stripslashes($_REQUEST[$v['name']]);
  6146. }
  6147. /* HTML ENTITIES DECODE ? */
  6148. #$_REQUEST[$v['name']] = html_entity_decode($_REQUEST[$v['name']]);
  6149. $content .= " <td><textarea class=\"mceEditor\" id=\"{$v['name']}\" name=\"{$v['name']}\" cols=\"{$v['cols']}\" rows=\"{$v['rows']}\">{$_REQUEST[$v['name']]}</textarea></td>\n";
  6150. } else {
  6151. $content .= " <td><textarea class=\"mceEditor\" id=\"{$v['name']}\" name=\"{$v['name']}\" cols=\"{$v['cols']}\" rows=\"{$v['rows']}\"></textarea></td>\n";
  6152. }
  6153. break;
  6154. case "radio": // RADIO
  6155. #$content .= " <td>{$v["label"]}</td>\n";
  6156. if (isset($this->helpers[$v['name']])) {
  6157. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6158. } else {
  6159. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6160. }
  6161. $content .= " <td>";
  6162. if ($preload) {
  6163. for($i=2;$i<count($v['values']);$i++) {
  6164. $value = explode(":",$v[values][$i]);
  6165. if ($value[1] == $_REQUEST[$v['name']]) {
  6166. $content .= "<input type=\"radio\" name=\"{$v['name']}\" value=\"{$value[1]}\" CHECKED style=\"border: 0px;\"> {$value[0]} &nbsp;&nbsp;";
  6167. } else {
  6168. $content .= "<input type=\"radio\" name=\"{$v['name']}\" value=\"{$value[1]}\" style=\"border: 0px;\"> {$value[0]} &nbsp;&nbsp;";
  6169. }
  6170. }
  6171. } else {
  6172. for($i=2;$i<count($v['values']);$i++) {
  6173. $value = explode(":",$v[values][$i]);
  6174. if ($value[2]) {
  6175. $content .= "<input type=\"radio\" name=\"{$v['name']}\" value=\"{$value[1]}\" CHECKED style=\"border: 0px;\"> {$value[0]} &nbsp;&nbsp;";
  6176. } else {
  6177. $content .= "<input type=\"radio\" name=\"{$v['name']}\" value=\"{$value[1]}\" style=\"border: 0px;\"> {$value[0]} &nbsp;&nbsp;";
  6178. }
  6179. }
  6180. }
  6181. $content .= " </td>";
  6182. break;
  6183. case CHECKBOX: // CHECKBOX
  6184. #$content .= " <td>{$v["label"]}</td>\n";
  6185. if (isset($this->helpers[$v['name']])) {
  6186. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6187. } else {
  6188. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6189. }
  6190. $content .= " <td>";
  6191. for($i=1;$i<count($v['values']);$i++) {
  6192. $value = explode(":",$v[values][$i]);
  6193. if ($preload) {
  6194. if ($_REQUEST[$value[1]]) {
  6195. $content .= "<input class='clear' type=\"checkbox\" name=\"{$value[1]}\" value=\"{$value[2]}\" CHECKED> {$value[0]} &nbsp;&nbsp;";
  6196. } else {
  6197. $content .= "<input class='clear' type=\"checkbox\" name=\"{$value[1]}\" value=\"{$value[2]}\"> {$value[0]} &nbsp;&nbsp;";
  6198. }
  6199. } else {
  6200. if ($value[3]) {
  6201. $content .= "<input class='clear' type=\"checkbox\" name=\"{$value[1]}\" value=\"{$value[2]}\" CHECKED> {$value[0]} &nbsp;&nbsp;";
  6202. } else {
  6203. $content .= "<input class='clear' type=\"checkbox\" name=\"{$value[1]}\" value=\"{$value[2]}\"> {$value[0]} &nbsp;&nbsp;";
  6204. }
  6205. }
  6206. }
  6207. $content .= " </td>";
  6208. break;
  6209. case "select": // SELECT
  6210. if (isset($this->helpers[$v['name']])) {
  6211. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6212. } else {
  6213. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6214. }
  6215. $content .= " <td>";
  6216. $content .= "<select class=\"becontent\" name=\"{$v['name']}\">\n";
  6217. $content .= "<option></option>\n";
  6218. if ($preload) {
  6219. $values = explode(",", $v['values']);
  6220. foreach($values as $k => $value) {
  6221. $items = explode(":", $value);
  6222. if ($_REQUEST[$v['name']] == $items[1]) {
  6223. $content .= "<option value=\"{$items[1]}\" SELECTED> {$items[0]} </option>\n";
  6224. } else {
  6225. $content .= "<option value=\"{$items[1]}\" > {$items[0]} </option>\n";
  6226. }
  6227. }
  6228. } else {
  6229. $values = explode(",", $v['values']);
  6230. foreach($values as $k => $value) {
  6231. $items = explode(":", $value);
  6232. if ($items[2] == "CHECKED") {
  6233. $content .= "<option value=\"{$items[1]}\" SELECTED> {$items[0]} </option>\n";
  6234. } else {
  6235. $content .= "<option value=\"{$items[1]}\" > {$items[0]} </option>\n";
  6236. }
  6237. }
  6238. }
  6239. $content .= "</select>\n";
  6240. $content .= " </td>\n";
  6241. break;
  6242. case "select-old": // SELECT
  6243. if (isset($this->helpers[$v['name']])) {
  6244. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6245. } else {
  6246. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6247. }
  6248. #$content .= " <td>{$v["label"]}</td>\n";
  6249. $content .= " <td>";
  6250. $content .= "<select class=\"becontent\" name=\"{$v['name']}\">\n";
  6251. $content .= "<option></option>\n";
  6252. if ($preload) {
  6253. for($i=2;$i<count($v['values']);$i++) {
  6254. $value = explode(":",$v[values][$i]);
  6255. if ($_REQUEST[$v['name']] == $value[1]) {
  6256. $content .= "<option value=\"{$value[1]}\" SELECTED> {$value[0]} </option>\n";
  6257. } else {
  6258. $content .= "<option value=\"{$value[1]}\" > {$value[0]} </option>\n";
  6259. }
  6260. }
  6261. } else {
  6262. for($i=2;$i<count($v['values']);$i++) {
  6263. $value = explode(":",$v[values][$i]);
  6264. if ($value[2]) {
  6265. $content .= "<option value=\"{$value[1]}\" SELECTED> {$value[0]} </option>\n";
  6266. } else {
  6267. $content .= "<option value=\"{$value[1]}\" > {$value[0]} </option>\n";
  6268. }
  6269. }
  6270. }
  6271. $content .= "</select>\n";
  6272. $content .= " </td>\n";
  6273. break;
  6274. case "relation manager-2colonne": // RELATION MANAGER
  6275. $content .= " <td valign=\"TOP\"></td>\n";
  6276. switch ($v['orientation']) {
  6277. case RIGHT:
  6278. $mainEntity = $this->entity->entity_1;
  6279. $secondaryEntity = $this->entity->entity_2;
  6280. break;
  6281. case LEFT:
  6282. $mainEntity = &$this->entity->entity_2;
  6283. $secondaryEntity = &$this->entity->entity_1;
  6284. break;
  6285. }
  6286. //setto i valori necessari in caso di gestione degli Rss
  6287. if($this->mainFormEntity->rss)
  6288. {
  6289. $query1="SELECT bc_channel.title FROM bc_channel
  6290. LEFT JOIN channel_entity
  6291. ON bc_channel.id=channel_entity.id_bc_channel
  6292. WHERE entity=\"{$this->mainFormEntity->name}\"";
  6293. $listChannel=aux::getResultArray($query1,'title');
  6294. if(!is_array($listChannel))$listChannel=array();
  6295. $cont=count($listChannel);
  6296. $query1="SELECT modality FROM bc_rss_mod WHERE entity=\"{$this->mainFormEntity->name}\"";
  6297. $rssMod=aux::getResultArray($query1,'modality');
  6298. }
  6299. /* this fetches all the item which should be put into checkboxes */
  6300. $data = $secondaryEntity->getReferenceWithCondition($v['condition']);
  6301. $content .= "<td>\n";
  6302. #print_r($_REQUEST);
  6303. #echo "<hr>";
  6304. if ((($this->entity->entity_2->owner) and ($v['orientation'] == RIGHT)) or
  6305. (($this->entity->entity_1->owner) and ($v['orientation'] == LEFT))) {
  6306. $your = $GLOBALS['message']->getMessage(FIELDSET);
  6307. } else {
  6308. $your = "";
  6309. }
  6310. $id = uniqid(time());
  6311. if ($preload) {
  6312. $content .= "<fieldset><legend>{$your} {$v["label"]}</legend>\n";
  6313. if ($this->description != "") {
  6314. $content .= "{$this->description}<br/><br/>\n";
  6315. }
  6316. $content .= "<table width=\"90%\">";
  6317. $counter = 0;
  6318. if ((count($data) > 0) and ($data != "")) {
  6319. $first=true;
  6320. $c=0;
  6321. foreach($data as $key => $value) {
  6322. $counter++;
  6323. if (isset($_REQUEST["{$v['name']}_{$value['value']}"])) {
  6324. if($this->mainFormEntity->rss) {
  6325. if (in_array($value['text'],$listChannel)) {
  6326. switch ($rssMod[0]) {
  6327. case MOD3:
  6328. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED> {$value['text']}<br>\n";
  6329. break;
  6330. case MOD2:
  6331. $c++;
  6332. if($first) {
  6333. $first=false;
  6334. $content .= " <input id=\"0\"class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\" CHECKED> ".$GLOBALS['message']->getMessage(RSS_MODALITY2_MSG)."\n";
  6335. }
  6336. $content .= " <input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED>\n";
  6337. break;
  6338. case MOD1:
  6339. $content .= " <input style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED>\n";
  6340. if ($first) {
  6341. $content .= $GLOBALS['message']->getMessage(RSS_MODALITY1_MSG);
  6342. $first = false;
  6343. }
  6344. break;
  6345. }
  6346. }
  6347. } else {
  6348. if (($counter % 2) == 1) {
  6349. $content .= aux::first_comma($id, "</td></tr>");
  6350. $content .= "<tr><td>";
  6351. } else {
  6352. $content .= "</td><td>";
  6353. }
  6354. $name = "{$v['name']}_".aux::encode_name($value['value']);
  6355. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$name}\" value=\"{$value['value']}\" CHECKED> {$value['text']}\n";
  6356. }
  6357. } else {
  6358. if($this->mainFormEntity->rss)
  6359. {
  6360. if (in_array($value['text'],$listChannel))
  6361. {
  6362. switch ($rssMod[0])
  6363. {
  6364. case MOD3:
  6365. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"> {$value['text']}<br>\n";
  6366. break;
  6367. case MOD2:
  6368. $c++;
  6369. if($first)
  6370. {
  6371. $first=false;
  6372. $content .= " <input id=\"0\"class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\" CHECKED> ".$GLOBALS['message']->getMessage(RSS_MODALITY2_MSG)."\n";
  6373. }
  6374. $content .= " <input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\">\n";
  6375. break;
  6376. case MOD1:
  6377. $content .= " <input style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED>\n";
  6378. if ($first) {
  6379. $content .= $GLOBALS['message']->getMessage(RSS_MODALITY1_MSG); $first = false;
  6380. }
  6381. break;
  6382. }
  6383. }
  6384. }else{
  6385. if (($counter % 2) == 1) {
  6386. $content .= aux::first_comma($id, "</td></tr>");
  6387. $content .= "<tr><td>";
  6388. } else {
  6389. $content .= "</td><td>";
  6390. }
  6391. $name = "{$v['name']}_".aux::encode_name($value['value']);
  6392. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$name}\" value=\"{$value['value']}\"> {$value['text']}\n";
  6393. }
  6394. }
  6395. }
  6396. }
  6397. $content .= "</td></tr></table>";
  6398. $content .= "</fieldset>\n";
  6399. } else {
  6400. $content .= "<fieldset><legend>{$your}{$v["label"]}</legend>\n";
  6401. if ($this->description != "") {
  6402. $content .= "{$this->description}<br/><br/>\n";
  6403. }
  6404. $content .= "<table width=\"90%\">\n";
  6405. $content .= "<tr>";
  6406. if ((count($data)>0) && ($data != "")) {
  6407. $first=true;
  6408. $c=0;
  6409. foreach($data as $key => $value) {
  6410. if($this->mainFormEntity->rss)
  6411. {
  6412. if (in_array($value['text'],$listChannel))
  6413. {
  6414. switch ($rssMod[0])
  6415. {
  6416. case MOD3:
  6417. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"> {$value['text']}<br>\n";
  6418. break;
  6419. case MOD2: if($first)
  6420. {
  6421. $first=false;
  6422. $content .= " <input id=\"0\"class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\" CHECKED> ".$GLOBALS['message']->getMessage(RSS_MODALITY2_MSG)."\n";
  6423. }
  6424. $c++;
  6425. $content .= " <input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\">\n";
  6426. break;
  6427. case MOD1:
  6428. $content .= " <input style=\"display : none;\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED>\n";
  6429. if ($first) {
  6430. $content .= $GLOBALS['message']->getMessage(RSS_MODALITY1_MSG); $first = false;
  6431. }
  6432. break;
  6433. }
  6434. }
  6435. }
  6436. else
  6437. {
  6438. if (($counter % 2) == 1) {
  6439. $content .= aux::first_comma($id, "</td></tr>");
  6440. $content .= "<tr><td>";
  6441. } else {
  6442. $content .= "</td><td>";
  6443. }
  6444. $name = "{$v['name']}_".aux::encode_name($value['value']);
  6445. $content .= "<input class=\"clear\" type=\"checkbox\" name=\"{$name}\" value=\"{$value['value']}\"> {$value['text']}\n";
  6446. }
  6447. }
  6448. }
  6449. $content .= "</tr></table>";
  6450. $content .= "</fieldset>\n";
  6451. }
  6452. $content .= "</td>\n";
  6453. break;
  6454. case RELATION_MANAGER: // RELATION MANAGER
  6455. $content .= " <td valign=\"TOP\"></td>\n";
  6456. switch ($v['orientation']) {
  6457. case RIGHT:
  6458. $mainEntity = $this->entity->entity_1;
  6459. $secondaryEntity = $this->entity->entity_2;
  6460. break;
  6461. case LEFT:
  6462. $mainEntity = &$this->entity->entity_2;
  6463. $secondaryEntity = &$this->entity->entity_1;
  6464. break;
  6465. }
  6466. // RSS
  6467. if ($this->mainFormEntity->rss) {
  6468. $query1="SELECT bc_channel.title
  6469. FROM bc_channel
  6470. LEFT JOIN channel_entity
  6471. ON bc_channel.id=channel_entity.id_bc_channel
  6472. WHERE entity=\"{$this->mainFormEntity->name}\"";
  6473. $listChannel=aux::getResultArray($query1,'title');
  6474. if (!is_array($listChannel)) {
  6475. $listChannel=array();
  6476. }
  6477. $cont=count($listChannel);
  6478. $query1="SELECT modality
  6479. FROM bc_rss_mod
  6480. WHERE entity=\"{$this->mainFormEntity->name}\"";
  6481. $rssMod=aux::getResultArray($query1,'modality');
  6482. }
  6483. /* this fetches all the item which should be put into checkboxes */
  6484. $data = $secondaryEntity->getReferenceWithCondition($v['condition']);
  6485. $content .= "<td>\n";
  6486. if ((($this->entity->entity_2->owner) and ($v['orientation'] == RIGHT)) or
  6487. (($this->entity->entity_1->owner) and ($v['orientation'] == LEFT))) {
  6488. $your = $GLOBALS['message']->getMessage(FIELDSET);
  6489. } else {
  6490. $your = "";
  6491. }
  6492. if ($preload) {
  6493. $content .= "<fieldset><legend>{$your} {$v["label"]}</legend>\n";
  6494. if ($this->description != "") {
  6495. $content .= "{$this->description}<br/><br/>\n";
  6496. }
  6497. if ((count($data) > 0) and ($data != "")) {
  6498. $first=true;
  6499. $c=0;
  6500. foreach($data as $key => $value) {
  6501. #if (isset($_REQUEST["{$v['name']}_{$value['value']}"])) {
  6502. if (isset($_REQUEST["{$v['name']}_".aux::encode_name($value['value'])])) {
  6503. if($this->mainFormEntity->rss) {
  6504. if (in_array($value['text'],$listChannel)) {
  6505. switch ($rssMod[0]) {
  6506. case MOD3:
  6507. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED> {$value['text']}<br>\n";
  6508. break;
  6509. case MOD2:
  6510. $c++;
  6511. if($first) {
  6512. $first=false;
  6513. $content .= " <input id=\"0\"class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\" CHECKED> ".$GLOBALS['message']->getMessage(RSS_MODALITY2_MSG)."\n";
  6514. }
  6515. $content .= " <input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED>\n";
  6516. break;
  6517. case MOD1:
  6518. $content .= " <input style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED>\n";
  6519. if ($first) {
  6520. $content .= $GLOBALS['message']->getMessage(RSS_MODALITY1_MSG); $first = false;
  6521. }
  6522. break;
  6523. }
  6524. }
  6525. } else {
  6526. $name = "{$v['name']}_".aux::encode_name($value['value']);
  6527. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$name}\" value=\"{$value['value']}\" CHECKED> {$value['text']}<br>\n";
  6528. }
  6529. } else {
  6530. if($this->mainFormEntity->rss)
  6531. {
  6532. if (in_array($value['text'],$listChannel))
  6533. {
  6534. switch ($rssMod[0])
  6535. {
  6536. case MOD3:
  6537. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"> {$value['text']}<br>\n";
  6538. break;
  6539. case MOD2:
  6540. $c++;
  6541. if($first)
  6542. {
  6543. $first=false;
  6544. $content .= " <input id=\"0\"class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\" CHECKED> ".$GLOBALS['message']->getMessage(RSS_MODALITY2_MSG)."\n";
  6545. }
  6546. $content .= " <input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\">\n";
  6547. break;
  6548. case MOD1:
  6549. $content .= " <input style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED>\n";
  6550. if ($first) {
  6551. $content .= $GLOBALS['message']->getMessage(RSS_MODALITY1_MSG); $first = false;
  6552. }
  6553. break;
  6554. }
  6555. }
  6556. }else{
  6557. $name = "{$v['name']}_".aux::encode_name($value['value']);
  6558. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$name}\" value=\"{$value['value']}\"> {$value['text']}<br>\n";
  6559. }
  6560. }
  6561. }
  6562. }
  6563. $content .= "</fieldset>\n";
  6564. } else {
  6565. $content .= "<fieldset><legend>{$your}{$v["label"]}</legend>\n";
  6566. if ($this->description != "") {
  6567. $content .= "{$this->description}<br/><br/>\n";
  6568. }
  6569. if ((count($data)>0) && ($data != "")) {
  6570. $first=true;
  6571. $c=0;
  6572. foreach($data as $key => $value) {
  6573. if ($this->mainFormEntity->rss) {
  6574. if (in_array($value['text'],$listChannel)) {
  6575. switch ($rssMod[0]) {
  6576. case MOD3:
  6577. $content .= " <input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"> {$value['text']}<br>\n";
  6578. break;
  6579. case MOD2:
  6580. if ($first) {
  6581. $first=false;
  6582. $content .= " <input id=\"0\"class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\" CHECKED> ".$GLOBALS['message']->getMessage(RSS_MODALITY2_MSG)."\n";
  6583. }
  6584. $c++;
  6585. $content .= " <input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\">\n";
  6586. break;
  6587. case MOD1:
  6588. $content .= " <input style=\"display : none;\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED>\n";
  6589. if ($first) {
  6590. $content .= $GLOBALS['message']->getMessage(RSS_MODALITY1_MSG);
  6591. $first = false;
  6592. }
  6593. break;
  6594. }
  6595. }
  6596. } else {
  6597. $name = "{$v['name']}_".aux::encode_name($value['value']);
  6598. $content .= "<input class=\"clear\" type=\"checkbox\" name=\"{$name}\" value=\"{$value['value']}\"> {$value['text']}<br>\n";
  6599. }
  6600. }
  6601. }
  6602. $content .= "</fieldset>\n";
  6603. }
  6604. $content .= "</td>\n";
  6605. break;
  6606. case "relation manager2": // RELATION MANAGER
  6607. #$content .= " <td valign=\"top\">{$v["label"]}</td>\n";
  6608. if (isset($this->helpers[$v['name']])) {
  6609. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6610. } else {
  6611. $content .= " <td style=\"padding-top: 10px;\" valign=\"TOP\">{$v["label"]}</td>\n";
  6612. }
  6613. switch ($v['orientation']) {
  6614. case RIGHT:
  6615. $mainEntity = $this->entity->entity_1;
  6616. $secondaryEntity = $this->entity->entity_2;
  6617. break;
  6618. case LEFT:
  6619. $mainEntity = &$this->entity->entity_2;
  6620. $secondaryEntity = &$this->entity->entity_1;
  6621. break;
  6622. }
  6623. /* this fetches all the item which should be put into checkboxes */
  6624. $data = $secondaryEntity->getReference();
  6625. if($this->mainFormEntity->rss)
  6626. {
  6627. $query1="SELECT bc_channel.title FROM bc_channel
  6628. LEFT JOIN channel_entity
  6629. ON bc_channel.id=channel_entity.id_bc_channel
  6630. WHERE entity=\"{$this->mainFormEntity->name}\"";
  6631. $listChannel=aux::getResultArray($query1,'title');
  6632. if(!is_array($listChannel))$listChannel=array();
  6633. $cont=count($listChannel);
  6634. $query1="SELECT modality FROM bc_rss_mod WHERE entity=\"{$this->mainFormEntity->name}\"";
  6635. $rssMod=aux::getResultArray($query1,'modality');
  6636. }
  6637. $content .= "<td style=\"padding-top: 10px;\">\n";
  6638. #print_r($_REQUEST);
  6639. #echo "<hr>";
  6640. if ($preload) {
  6641. $content .= "<table>\n";
  6642. if ((count($data) > 0) and ($data != "")) {
  6643. $first=true;
  6644. $c=0;
  6645. foreach($data as $key => $value) {
  6646. $content .= "<tr>\n";
  6647. if (isset($_REQUEST['rss_mod2'])||(isset($_REQUEST["{$v['name']}_{$value['value']}"])))
  6648. {
  6649. if($this->mainFormEntity->rss)
  6650. {
  6651. if (in_array($value['text'],$listChannel))
  6652. {
  6653. switch ($rssMod[0])
  6654. {
  6655. case MOD3:
  6656. $content .= "<td><input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED></td><td>{$value['text']}</td>\n";
  6657. break;
  6658. case MOD2:
  6659. $c++;
  6660. if($first)
  6661. {
  6662. $first=false;
  6663. $content .= "<td><input id=\"0\"class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\" CHECKED></td><td>Rss</td>\n</tr>\n<tr>";
  6664. }
  6665. $content .= "<td><input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED></td><td></td>\n";
  6666. break;
  6667. case MOD1:
  6668. $content .= "<td><input style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED></td><td></td>\n";
  6669. break;
  6670. }
  6671. }
  6672. }
  6673. else
  6674. {
  6675. $content .= "<td><input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED></td><td>{$value['text']}</td>\n";
  6676. }
  6677. } else
  6678. {
  6679. if($this->mainFormEntity->rss)
  6680. {
  6681. if (in_array($value['text'],$listChannel))
  6682. {
  6683. switch ($rssMod[0])
  6684. {
  6685. case MOD3:
  6686. $content .= "<td><input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"></td><td>{$value['text']}</td>\n";
  6687. break;
  6688. case MOD2:
  6689. $c++;
  6690. if($first)
  6691. {
  6692. $first=false;
  6693. $content .= "<td><input id=\"0\"class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\"></td><td>Rss</td>\n";
  6694. }
  6695. $content .= "<td><input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"></td><td></td>\n";
  6696. break;
  6697. case MOD1:
  6698. $content .= "<td><input style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED></td><td></td>\n";
  6699. break;
  6700. }
  6701. }
  6702. }
  6703. else
  6704. {
  6705. $content .= "<td><input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"></td><td>{$value['text']}</td>\n";
  6706. }
  6707. }
  6708. $content .= "</tr>\n";
  6709. }
  6710. }
  6711. $content .= "</table>\n";
  6712. } else {
  6713. $content .= "<table>\n";
  6714. if ((count($data)>0) && ($data != "")) {
  6715. $first=true;
  6716. $c=0;
  6717. foreach($data as $key => $value) {
  6718. if($this->mainFormEntity->rss)
  6719. {
  6720. if (in_array($value['text'],$listChannel))
  6721. {
  6722. switch ($rssMod[0])
  6723. {
  6724. case MOD3: $content .= "<tr>\n";
  6725. $content .= "<td><input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"></td><td>{$value['text']}</td>\n";
  6726. $content .= "</tr>\n";
  6727. break;
  6728. case MOD2: if($first)
  6729. {
  6730. $first=false;
  6731. $content .= "<tr>\n";
  6732. $content .= "<td><input id=\"0\" class=\"clear\" type=\"checkbox\" name=\"rss_mod2\" value=\"0\" onClick=\"reload({$cont});\"></td><td>Rss</td>\n";
  6733. $content .= "</tr>\n";
  6734. }
  6735. $c++;
  6736. $content .= "<tr>\n";
  6737. $content .= "<td><input id=\"{$c}\" style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"></td><td></td>\n";
  6738. $content .= "</tr>\n";
  6739. break;
  6740. case MOD1: $content .= "<tr>\n";
  6741. $content .= "<td><input style=\"display : none\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\" CHECKED></td><td></td>\n";
  6742. $content .= "</tr>\n";
  6743. break;
  6744. }
  6745. }
  6746. }
  6747. else
  6748. {
  6749. $content .= "<tr>\n";
  6750. $content .= "<td><input class=\"clear\" type=\"checkbox\" name=\"{$v['name']}_{$value['value']}\" value=\"{$value['value']}\"></td><td>{$value['text']}</td>\n";
  6751. $content .= "</tr>\n";
  6752. }
  6753. }
  6754. }
  6755. $content .= "</table>\n";
  6756. }
  6757. $content .= "</td>\n";
  6758. break;
  6759. case "selectFromReference":// SELECTFROMREFERENCE
  6760. /* Warning: it should be adapted for the preload option ! */
  6761. if ($v['entity_name'] == $this->entity->name) {
  6762. $selfreference = true;
  6763. } else {
  6764. $selfreference = false;
  6765. }
  6766. $trovato = false;
  6767. foreach($this->elements as $index => $value) {
  6768. if ($value['referenceField'] == $v['name']) {
  6769. $trovato = true;
  6770. $position_index = $index;
  6771. }
  6772. }
  6773. if (($trovato) and ($selfreference)) {
  6774. /* There is a self-reference foreign key */
  6775. $v["entity"]->setReferenceOrder($this->elements[$position_index]['name']);
  6776. }
  6777. if (isset($v['condition'])) {
  6778. $data = $v["entity"]->getReferenceWithCondition($v['condition']);
  6779. } else {
  6780. if ($GLOBALS['becontent']->entities[$v['entity']->name]->referenceOrder != "") {
  6781. $data = $v["entity"]->getReference(BY_POSITION, $GLOBALS['becontent']->entities[$v['entity']->name]->referenceOrder);
  6782. } else {
  6783. $data = $v['entity']->getReference();
  6784. }
  6785. }
  6786. if (isset($this->helpers[$v['name']])) {
  6787. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6788. } else {
  6789. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6790. }
  6791. $content .= " <td>\n";
  6792. /* OK */
  6793. if ($trovato) {
  6794. $content .= " <select class=\"becontent\" name=\"{$v['name']}\" id=\"{$v['name']}\" onChange=\"makeRequest('{$v['name']}','{$this->elements[$position_index]['name']}','{$this->elements[$position_index]['controlledField']}','{$this->entity->name}','{$operation}','onChange')\">\n";
  6795. } else {
  6796. $content .= " <select class=\"becontent\" name=\"{$v['name']}\">\n";
  6797. }
  6798. $content .= " <option></option>\n";
  6799. if ($selfreference) {
  6800. $GLOBALS['data'] = $data;
  6801. aux::FindChildren(0,0);
  6802. for($i=0;$i<count($GLOBALS['tree_text']); $i++) {
  6803. $GLOBALS['data'][$i]['value'] = $GLOBALS['tree_value'][$i];
  6804. $GLOBALS['data'][$i]['text'] = $GLOBALS['tree_text'][$i];
  6805. }
  6806. #print_r($data);exit;
  6807. $data = $GLOBALS['data'];
  6808. }
  6809. for($i=0;$i<count($data);$i++) {
  6810. if ($preload) {
  6811. if ($_REQUEST[$v['name']] == $data[$i]['value']) {
  6812. $content .= " <option value=\"{$data[$i]["value"]}\" SELECTED> {$data[$i]["text"]} </option>\n";
  6813. } else {
  6814. $content .= " <option value=\"{$data[$i]["value"]}\" > {$data[$i]["text"]} </option>\n";
  6815. }
  6816. } else {
  6817. $content .= " <option value=\"{$data[$i]["value"]}\" > {$data[$i]["text"]} </option>\n";
  6818. }
  6819. }
  6820. $content .= " </select>\n";
  6821. $content .= " </td>\n";
  6822. break;
  6823. case RADIO_FROM_REFERENCE:
  6824. /* Warning: it should be adapted for the preload option ! */
  6825. unset($data);
  6826. if (isset($v['condition'])) {
  6827. $data = $v["entity"]->getReferenceWithCondition($v['condition']);
  6828. } else {
  6829. $data = $v["entity"]->getReference();
  6830. }
  6831. $content .= "<td valign=\"top\">{$v["label"]} ";
  6832. if (isset($this->helpers[$v['name']])) {
  6833. $content .= "<a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> ";
  6834. }
  6835. $content .= "</td>\n";
  6836. $content .= "<td>\n";
  6837. for($i=0;$i<count($data);$i++) {
  6838. if ($preload) {
  6839. if ($_REQUEST[$v['name']] == $data[$i]['value']) {
  6840. $content .= " <input type=\"radio\" name=\"{$v['name']}\" value=\"{$data[$i]["value"]}\" CHECKED> {$data[$i]["text"]} &nbsp;&nbsp;\n";
  6841. } else {
  6842. $content .= " <input type=\"radio\" name=\"{$v['name']}\" value=\"{$data[$i]["value"]}\"> {$data[$i]["text"]} &nbsp;&nbsp;\n";
  6843. }
  6844. } else {
  6845. if (($v['mandatory'] == "yes") and ($i == 0)) {
  6846. $content .= " <input type=\"radio\" name=\"{$v['name']}\" value=\"{$data[$i]["value"]}\" CHECKED> {$data[$i]["text"]} &nbsp;&nbsp;\n";
  6847. } else {
  6848. $content .= " <input type=\"radio\" name=\"{$v['name']}\" value=\"{$data[$i]["value"]}\" > {$data[$i]["text"]} &nbsp;&nbsp;\n";
  6849. }
  6850. }
  6851. }
  6852. $content .= " </td>\n";
  6853. break;
  6854. case "position": // POSITION
  6855. $data = $this->entity->getReference(BY_POSITION,$v['name']);
  6856. if (isset($this->helpers[$v['name']])) {
  6857. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6858. } else {
  6859. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6860. }
  6861. $content .= " <td>";
  6862. $content .= "<input type=\"hidden\" name=\"{$v['name']}_all\" value=\"\">\n";
  6863. #$content .= "<div><select id=\"{$v['name']}\" name=\"{$v['name']}\" size=\"{$v['size']}\" style=\"min-width: 300px;\">\n";
  6864. $content .= "<div><select class=\"becontent position\" id=\"{$v['name']}\" name=\"{$v['name']}\" size=\"8\">\n";
  6865. #echo count($data);
  6866. for($i=0;$i<count($data);$i++) {
  6867. if ($preload) {
  6868. /* the EDIT operation is always with RELOAD */
  6869. #echo $_REQUEST[$this->entity->fields[0]['name']];
  6870. if ($_REQUEST[$this->entity->fields[0]['name']] == $data[$i]['value']) {
  6871. $content .= "<option value=\"{$data[$i]["value"]}\" SELECTED> {$data[$i]["text"]} </option>\n";
  6872. } else {
  6873. $content .= "<option value=\"{$data[$i]["value"]}\" > {$data[$i]["text"]} </option>\n";
  6874. }
  6875. } else {
  6876. $content .= "<option value=\"{$data[$i]["value"]}\" > {$data[$i]["text"]} </option>\n";
  6877. }
  6878. }
  6879. if ($operation == ADD) {
  6880. /* In the ADD operation one slot more is required
  6881. for the element being added. */
  6882. $content .= "<option value=\"0\">&nbsp;</option>\n";
  6883. }
  6884. $content .= "</select><br />\n";
  6885. $content .= "<img vspace=5 src=\"img/position/button_up-new.jpg\" onClick=\"my_up('{$this->name}','{$v['name']}')\";>";
  6886. $content .= "<img vspace=5 src=\"img/position/button_down-new.jpg\" onClick=\"my_down('{$this->name}','{$v['name']}')\";>";
  6887. $content .= "</div>\n";
  6888. $content .= " </td>\n";
  6889. break;
  6890. case "hierarchicalPosition": // HIERARCHICALPOSITION
  6891. $data = $this->entity->getReference(BY_POSITION, $v['name']);
  6892. if (isset($this->helpers[$v['name']])) {
  6893. $content .= " <td valign=\"TOP\">{$v["label"]} <a href=# title=\"{$this->helpers[$v['name']]}\"><img src=\"img/form/help.gif\" class=\"helper\"></a> </td>\n";
  6894. } else {
  6895. $content .= " <td valign=\"TOP\">{$v["label"]}</td>\n";
  6896. }
  6897. $content .= " <td>";
  6898. $content .= "<input type=\"hidden\" name=\"{$v['name']}_all\" value=\"\">\n";
  6899. $content .= "<div><select class=\"becontent\" id=\"{$v['name']}\" name=\"{$v['name']}\" size=\"{$v['size']}\" class=\"position\">\n";
  6900. if ($operation == ADD) {
  6901. /* In the ADD operation one slot more is required
  6902. for the element being added. */
  6903. $content .= "<option value=\"0\">&nbsp;</option>\n";
  6904. }
  6905. $content .= "</select><br />\n";
  6906. $content .= "<script>makeRequest('{$this->elements[$v['reference_index']]['name']}', '{$v['name']}', '{$v['controlledField']}','{$this->entity->name}', '{$operation}','onLoad')</script>\n";
  6907. $content .= "<div class=\"position-button-up\" onClick=\"my_up('{$this->name}','{$v['name']}');\" ></div>";
  6908. $content .= "<div class=\"position-button-down\" onClick=\"my_down('{$this->name}','{$v['name']}');\" ></div>";
  6909. $content .= "</div>\n";
  6910. $content .= " </td>\n";
  6911. break;
  6912. case "section": // SECTION
  6913. $section = $v['name'];
  6914. $content .= "<td colspan=2 style=\"padding-top: 20px;\"><b>{$section}</b></td>\n";
  6915. break;
  6916. }
  6917. $content .= " </tr>\n";
  6918. }
  6919. /* here goes the code for the triggered form */
  6920. if ((count($this->triggeredForms)>0) and ($this->triggeredForms != "")) {
  6921. foreach($this->triggeredForms as $k => $form) {
  6922. if($form->mainFormEntity->rss)
  6923. {
  6924. $rssVar=$form;
  6925. }
  6926. else{
  6927. $content .= $form->emitHTML($operation, $page, $preload);
  6928. }
  6929. }
  6930. if(isset($rssVar)){
  6931. $content .= $rssVar->emitHTML($operation, $page, $preload);
  6932. }
  6933. }
  6934. /* Closing the Form */
  6935. if (!$this->triggered) { // if it is the main form
  6936. switch ($operation) {
  6937. case "add":
  6938. $subcontent=$this->emitHTML_post();
  6939. if(isset($subcontent))
  6940. {
  6941. $content .= $subcontent;
  6942. $content .= "<tr><td></td><td><input type=\"button\" value=\"".$GLOBALS['message']->getMessage(BUTTON_EDIT)."\" onClick=\"submit_{$this->name}();\">";
  6943. }
  6944. else
  6945. $content .= "<tr><td></td><td><input type=\"button\" value=\"".$GLOBALS['message']->getMessage(BUTTON_ADD)."\" onClick=\"submit_{$this->name}();\"></td></tr>\n";
  6946. break;
  6947. case "edit":
  6948. if (!$this->moderationMode) {
  6949. $content .= $this->emitHTML_post();
  6950. $content .= "<tr><td></td><td><input type=\"button\" value=\"".$GLOBALS['message']->getMessage(BUTTON_EDIT)."\" onClick=\"submit_{$this->name}();\">";
  6951. if (!$this->noDelete) {
  6952. /*
  6953. In case it does not have to show the "delete" button, it is determinate
  6954. by the NO_DELETE directive in the editItem() method.
  6955. */
  6956. $this->noDelete = false;
  6957. $content .= "<input type=\"button\" value=\"".$GLOBALS['message']->getMessage(BUTTON_DELETE)."\" onClick=\"delete_{$this->name}();\">";
  6958. }
  6959. $content .= "</td></tr>\n";
  6960. } else {
  6961. $content .= "<tr><td></td><td>";
  6962. $content .= "<input type=\"hidden\" name=\"moderationResult\" value=\"\">";
  6963. $content .= "<input type=\"button\" value=\"".$GLOBALS['message']->getMessage(BUTTON_ACCEPT)."\" onClick=\"accept_{$this->name}();\">";
  6964. $content .= "<input type=\"button\" value=\"".$GLOBALS['message']->getMessage(BUTTON_REFUSE)."\" onClick=\"refuse_{$this->name}();\">";
  6965. $content .= "</td></tr>\n";
  6966. }
  6967. break;
  6968. }
  6969. $content .= " </table>\n";
  6970. $content .= "</form>\n";
  6971. $content .= "</div>\n";
  6972. $content .= "<!-- MAIN FORM END -->\n";
  6973. }
  6974. return $content;
  6975. }
  6976. function display($operation,$page,$preload = "") {
  6977. $content = "";
  6978. $content .= $this->emitJavaScript($operation, $page, $preload);
  6979. $content .= $this->emitHTML($operation, $page, $preload);
  6980. return $content;
  6981. }
  6982. /* ADD ITEM CONNECTORS */
  6983. /**
  6984. * These functions are invoked as pre and post actions of the stage EMIT FORM
  6985. * of addItem().
  6986. *
  6987. * They must be implemented in a subclass.
  6988. *
  6989. * @abstract
  6990. */
  6991. function addItem_preEmitForm() {
  6992. #echo "addItem_preEmitForm<br>";
  6993. }
  6994. function addItem_postEmitForm() {
  6995. #echo "addItem_postEmitForm<br>";
  6996. }
  6997. /**
  6998. * These functions are invoked as pre and post actions of the stage INSERTION
  6999. * of addItem().
  7000. *
  7001. * They must be implemented in a subclass.
  7002. *
  7003. * @abstract
  7004. */
  7005. function addItem_sub(){
  7006. #echo "addItem_sub<br>";
  7007. #must return true if is implemented
  7008. }
  7009. function addItem_preInsertion() {
  7010. #echo "addItem_preInsertion<br>";
  7011. }
  7012. function addItem_postInsertion() {
  7013. #echo "addItem_postInsertion<br>";
  7014. }
  7015. /* EDIT ITEM CONNECTORS */
  7016. /**
  7017. * These function are invoked as pre and post actions of the SELECTION Stage
  7018. * of editItem().
  7019. *
  7020. * They must be eventually implemented in a subclass.
  7021. *
  7022. * @abstract
  7023. */
  7024. function editItem_preSelection() {
  7025. #echo "editItem_preSelection<br>";
  7026. }
  7027. function editItem_postSelection() {
  7028. #echo "editItem_postSelection<br>";
  7029. }
  7030. /**
  7031. * These function are invoked as pre and post actions of the FORM FEED Stage
  7032. * of editItem().
  7033. *
  7034. * They must be eventually implemented in a subclass.
  7035. *
  7036. * @abstract
  7037. */
  7038. function editItem_preFormFeed() {
  7039. #echo "editItem_preFormFeed<br>";
  7040. }
  7041. function editItem_postFormFeed() {
  7042. #echo "editItem_postFormFeed<br>";
  7043. }
  7044. /**
  7045. * These function are invoked as pre and post actions of the UPDATE Stage
  7046. * of editItem().
  7047. *
  7048. * They must be eventually implemented in a subclass.
  7049. *
  7050. * @abstract
  7051. */
  7052. function editItem_preUpdate() {
  7053. #echo "editItem_preUpdate<br>";
  7054. }
  7055. function editItem_postUpdate() {
  7056. #echo "editItem_postUpdate<br>";
  7057. }
  7058. /**
  7059. * These function are invoked as pre and post actions of the DELETION Stage
  7060. * of editItem().
  7061. *
  7062. * They must be eventually implemented in a subclass.
  7063. *
  7064. * @abstract
  7065. */
  7066. function editItem_preDeletion() {
  7067. #echo "editItem_preDeletion<br>";
  7068. }
  7069. function editItem_postDeletion() {
  7070. #echo "editItem_postDeletion<br>";
  7071. }
  7072. /**
  7073. * These function are invoked before the button end must return HTML code
  7074. *
  7075. *
  7076. * They must be eventually implemented in a subclass.
  7077. *
  7078. * @abstract
  7079. */
  7080. function emitHTML_post(){
  7081. #echo "emitHtml_post";
  7082. }
  7083. }
  7084. /**
  7085. * Class - FeedRss
  7086. *
  7087. */
  7088. Class FeedRss{
  7089. /**
  7090. * Entity associated to Feed
  7091. *
  7092. * @var Entity
  7093. */
  7094. var $entity;
  7095. var $channel;
  7096. var $result;
  7097. var $nameChannel;
  7098. //inizializza le variabili: result incui andr� il codice xml
  7099. //channel che contiene l'entit� canale passatagli come parametro
  7100. //inoltra effettua la chiamata addEntity()
  7101. function FeedRss($channel){
  7102. $this->channel = $channel;
  7103. $this->result = "";
  7104. $this->addEntity();
  7105. }
  7106. /**
  7107. * Sets channel name to add.
  7108. * @param string $name
  7109. * @return void
  7110. */
  7111. function addChannel($name){
  7112. $this->nameChannel = $name;
  7113. }
  7114. /**
  7115. * Ricava l'array entity effettuando il
  7116. * controllo sui nomi delle varie tabelle utilizzando
  7117. * l'array globale beContent.
  7118. * @return void
  7119. */
  7120. function addEntity(){
  7121. foreach ($GLOBALS['becontent']->entities as $i=>$value)
  7122. {
  7123. if(substr_count($value->name,$this->channel->name)!=0)
  7124. {
  7125. if($value->name != $this->channel->name)
  7126. $entity[] = substr($value->name,0,strlen($value->name)-11);
  7127. }
  7128. }
  7129. foreach ($GLOBALS['becontent']->entities as $i=>$value)
  7130. {
  7131. if (in_array($value->name, $entity))
  7132. $this->entity[] = $value;
  7133. }
  7134. }
  7135. /**
  7136. * Genera il codice XML degli item.
  7137. *
  7138. * @param array $data
  7139. * @param Entity $entity
  7140. */
  7141. function intermediateCode($data,$entity)
  7142. {
  7143. $ret = '';
  7144. if(isset($data))
  7145. {
  7146. $x=0;
  7147. while($x<count($data))
  7148. {
  7149. $ret .= '<item>'."\n";
  7150. foreach ($entity->rssPresentation as $c_rss=>$c_tab)
  7151. {
  7152. switch ($c_rss){
  7153. case 'title':$ret.='<title>'.aux::xmlchars($data[$x][$c_tab]).'</title>'."\n"; break;
  7154. case 'link':$ret.='<link>'.aux::xmlchars($data[$x][$c_tab]).'</link>'."\n"; break;
  7155. case 'description':$ret.='<description>'.aux::xmlchars($data[$x][$c_tab]).'</description>'."\n"; break;
  7156. case 'author':$ret.='<author>'.aux::xmlchars($data[$x][$c_tab]).'</author>'."\n"; break;
  7157. case 'category':$ret.='<category>'.aux::xmlchars($data[$x][$c_tab]).'</category>'."\n"; break;
  7158. case 'comments':$ret.='<comments>'.aux::xmlchars($data[$x][$c_tab]).'</comments>'."\n"; break;
  7159. case 'guid':$ret.='<guid>'.aux::xmlchars($data[$x][$c_tab]).'</guid>'."\n"; break;
  7160. case 'pubDate':$ret.='<pubDate>'.aux::xmlchars(aux::formatDate($data[$x][$c_tab]),LETTERS).'</pubDate>'."\n";
  7161. }
  7162. }
  7163. $ret .= '</item>'."\n";
  7164. $x++;
  7165. }
  7166. $this->result .= $ret;
  7167. }
  7168. }
  7169. /**
  7170. * Innesca intermediate code passandogli i dati relativi per ogni tabella.
  7171. *
  7172. * @return void
  7173. */
  7174. function emitItem()
  7175. {
  7176. if(isset($this->nameChannel))
  7177. {
  7178. $oid = mysql_query("SELECT id
  7179. FROM {$this->channel->name}
  7180. WHERE title=\"{$this->nameChannel}\"");
  7181. if (!$oid)
  7182. {
  7183. echo mysql_error();
  7184. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC);
  7185. exit;
  7186. }
  7187. $data = mysql_fetch_assoc($oid);
  7188. }
  7189. if(isset($data))
  7190. {
  7191. foreach ($this->entity as $i=>$entity)
  7192. {
  7193. $query="SELECT * FROM {$entity->name}
  7194. LEFT JOIN {$entity->name}_{$this->channel->name}
  7195. ON {$entity->name}_{$this->channel->name}.id_{$entity->name}={$entity->name}.id
  7196. WHERE {$entity->name}_{$this->channel->name}.id_{$this->channel->name}={$data['id']}";
  7197. $buffer = aux::getResult($query);
  7198. $this->intermediateCode($buffer,$entity);
  7199. }
  7200. }
  7201. //print($this->result);
  7202. }
  7203. /**
  7204. * Stampa il codice relativo all'intero file rss generando i dati
  7205. * per il canale e appoggiandosi al codice intermedio memorizzato
  7206. * precedentemente in result da intermediatecode in piu richiama
  7207. * la funzione printRss() per la stampa effettiva della stringa generata.
  7208. *
  7209. * @return void
  7210. *
  7211. */
  7212. function emitXML2(){
  7213. $ret ='';
  7214. $ret .='<?xml version="1.0"?>'."\n";
  7215. $ret .='<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">'."\n";
  7216. $ret .='<channel>'."\n";
  7217. $data = aux::getResult("SELECT * FROM {$this->channel->name} WHERE title=\"{$this->nameChannel}\"");
  7218. $data = $data[0];
  7219. $ret .= '<title>'.aux::xmlchars($data['title']).'</title>'."\n";
  7220. $ret .= '<link>'.aux::xmlchars($data['link']).'</link>'."\n";
  7221. $ret .='<description>'.aux::xmlchars($data['description']).'</description>'."\n";
  7222. if(isset($data['language']))
  7223. $ret .= '<language>'.aux::xmlchars($data['language']).'</language>'."\n";
  7224. if(isset($data['copyright']))
  7225. $ret .= '<copyright>'.aux::xmlchars($data['copyright']).'</copyright>'."\n";
  7226. if(isset($data['managingEditor']))
  7227. $ret .= '<managingEditor>'.aux::xmlchars($data['managingEditor']).'</managingEditor>'."\n";
  7228. if(isset($data['webMaster']))
  7229. $ret .= '<webMaster>'.aux::xmlchars($data['webMaster']).'</webMaster>'."\n";
  7230. if(isset($data['pubDate']))
  7231. $ret .= '<pubDate>'.aux::xmlchars($data['pubDate']).'</pubDate>'."\n";
  7232. if(isset($data['lastBuildDate']))
  7233. $ret .= '<lastBuildDate>'.aux::xmlchars($data['lastBuildDate']).'</lastBuildDate>'."\n";
  7234. if(isset($data['category']))
  7235. $ret .= '<category>'.aux::xmlchars($data['category']).'</category>'."\n";
  7236. if(isset($data['docs']))
  7237. $ret .= '<docs>'.aux::xmlchars($data['docs']).'</docs>'."\n";
  7238. if(isset($data['cloud']))
  7239. $ret .= '<cloud>'.aux::xmlchars($data['cloud']).'</cloud>'."\n";
  7240. if(isset($data['ttl']))
  7241. $ret .= '<ttl>'.aux::xmlchars($data['ttl']).'</ttl>'."\n";
  7242. if(isset($data['image_title']) and isset($data['image_link']) and ($data['image_size'] > 0)) {
  7243. $ret .= '<image>'."\n";
  7244. $ret .= '<title>'.aux::xmlchars($data['image_title']).'</title>'."\n";
  7245. $ret .= '<url>'.aux::xmlchars("show.php?token=ed3f638bfd40c089629d21d7a502f5bd&id={$data['id']}").'</url>'."\n";
  7246. $ret .= '<link>'.aux::xmlchars($data['image_link']).'</link>'."\n";
  7247. if (isset($data['image_width'])) {
  7248. $ret .= '<width>'.aux::xmlchars($data['image_width']).'</width>'."\n";
  7249. }
  7250. if (isset($data['image_height'])) {
  7251. $ret .= '<height>'.aux::xmlchars($data['image_height']).'</height>'."\n";
  7252. }
  7253. $ret .= '</image>'."\n";
  7254. }
  7255. if (isset($this->nameChannel)) {
  7256. $oid = mysql_query("SELECT id FROM {$this->channel->name} WHERE title=\"{$this->nameChannel}\"");
  7257. if (!$oid) {
  7258. echo mysql_error();
  7259. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC);
  7260. exit;
  7261. }
  7262. $data = mysql_fetch_assoc($oid);
  7263. }
  7264. if(isset($data)) {
  7265. foreach ($this->entity as $i=>$entity) {
  7266. $query = "SELECT * FROM {$entity->name}
  7267. LEFT JOIN {$entity->name}_{$this->channel->name}
  7268. ON {$entity->name}_{$this->channel->name}.id_{$entity->name}={$entity->name}.id
  7269. WHERE {$entity->name}_{$this->channel->name}.id_{$this->channel->name}={$data['id']}";
  7270. $buffer = aux::getResult($query);
  7271. $this->intermediateCode($buffer,$entity);
  7272. }
  7273. }
  7274. $ret = '';
  7275. $ret .= '</channel>'."\n";
  7276. $ret .='</rss>'."\n";
  7277. $this->result .= $ret;
  7278. $this->printRss();
  7279. }
  7280. /**
  7281. * Stampa il codice relativo all'intero file rss generando i dati
  7282. * per il canale e appoggiandosi al codice intermedio memorizzato
  7283. * precedentemente in result da intermediatecode in piu richiama
  7284. * la funzione printRss() per la stampa effettiva della stringa generata.
  7285. *
  7286. * @return void
  7287. */
  7288. function emitXML(){
  7289. $rss = new Template("dtml/rss.xml");
  7290. $data = aux::getResult("SELECT * FROM {$this->channel->name} WHERE id=\"{$_REQUEST['id']}\"");
  7291. $data = $data[0];
  7292. $channel = $data;
  7293. $rss->setContent("title", $data['title']);
  7294. $rss->setContent("link", aux::xmlchars($data['link']));
  7295. $rss->setContent("description", $data['description']);
  7296. if (isset($data['language'])) {
  7297. $rss->setContent("language", $data['language']);
  7298. } else {
  7299. $rss->setContent("language", "");
  7300. }
  7301. if (isset($data['lastBuildDate'])) {
  7302. $rss->setContent("lastBuildDate", aux::xmlchars($data['lastBuildDate']));
  7303. } else {
  7304. $rss->setContent("lastBuildDate", "");
  7305. }
  7306. if (isset($data['copyright'])) {
  7307. $rss->setContent("copyright", aux::xmlchars($data['copyright']));
  7308. } else {
  7309. $rss->setContent("copyright", "");
  7310. }
  7311. if (isset($data['pubDate'])) {
  7312. $rss->setContent("pubDate", aux::xmlchars($data['pubDate']));
  7313. } else {
  7314. $rss->setContent("pubDate", "");
  7315. }
  7316. if (isset($data['category'])) {
  7317. $rss->setContent("category", aux::xmlchars($data['category']));
  7318. } else {
  7319. $rss->setContent("category", "");
  7320. }
  7321. if (isset($data['docs'])) {
  7322. $rss->setContent("docs", aux::xmlchars($data['docs']));
  7323. } else {
  7324. $rss->setContent("docs", "");
  7325. }
  7326. if (isset($data['cloud'])) {
  7327. $rss->setContent("cloud", aux::xmlchars($data['cloud']));
  7328. } else {
  7329. $rss->setContent("cloud", "");
  7330. }
  7331. if (isset($data['ttl'])) {
  7332. $rss->setContent("ttl", aux::xmlchars($data['ttl']));
  7333. } else {
  7334. $rss->setContent("ttl", "");
  7335. }
  7336. if (isset($data['image_title']) and isset($data['image_link']) and ($data['image_size'] > 0)) {
  7337. $rss->setContent("image_title", $data['image_title']);
  7338. $rss->setContent("image_url", aux::xmlchars("show.php?token=ed3f638bfd40c089629d21d7a502f5bd&id={$data['id']}"));
  7339. $rss->setContent("image_link", aux::xmlchars($data['image_link']));
  7340. if (isset($data['image_width'])) {
  7341. $rss->setContent("image_width", aux::xmlchars($data['image_width']));
  7342. } else {
  7343. $rss->setContent("image_width", "");
  7344. }
  7345. if (isset($data['image_height'])) {
  7346. $rss->setContent("image_height", aux::xmlchars($data['image_height']));
  7347. } else {
  7348. $rss->setContent("image_height", "");
  7349. }
  7350. }
  7351. $rss->setContent("managingEditor", aux::xmlchars("{$GLOBALS['config']['defaultuser']['email']} ({$GLOBALS['config']['defaultuser']['name']} {$GLOBALS['config']['defaultuser']['surname']})"));
  7352. $rss->setContent("webMaster", aux::xmlchars("{$GLOBALS['config']['defaultuser']['email']} ({$GLOBALS['config']['defaultuser']['name']} {$GLOBALS['config']['defaultuser']['surname']})"));
  7353. if (isset($this->nameChannel)) {
  7354. $oid = mysql_query("SELECT id FROM {$this->channel->name} WHERE title=\"{$this->nameChannel}\"");
  7355. if (!$oid) {
  7356. echo mysql_error();
  7357. echo $GLOBALS['message']->getMessage(MSG_ERROR_DATABASE_GENERIC);
  7358. exit;
  7359. }
  7360. $data = mysql_fetch_assoc($oid);
  7361. }
  7362. if (isset($data)) {
  7363. foreach ($this->entity as $i=>$entity) {
  7364. if (isset($entity->rssPresentation['pubDate'])) {
  7365. if ($entity->rssFilter != "") {
  7366. $filter = " AND {$entity->rssFilter} ";
  7367. } else {
  7368. $filter = "";
  7369. }
  7370. $query = "SELECT DISTINCT
  7371. {$entity->name}.*
  7372. FROM {$entity->name}
  7373. LEFT JOIN {$entity->name}_{$this->channel->name}
  7374. ON {$entity->name}_{$this->channel->name}.id_{$entity->name}={$entity->name}.id
  7375. WHERE {$entity->name}_{$this->channel->name}.id_{$this->channel->name}={$data['id']}
  7376. {$filter}
  7377. ORDER BY {$entity->name}.{$entity->rssPresentation['pubDate']} DESC";
  7378. } else {
  7379. $query = "SELECT DISTINCT
  7380. {$entity->name}.*
  7381. FROM {$entity->name}
  7382. LEFT JOIN {$entity->name}_{$this->channel->name}
  7383. ON {$entity->name}_{$this->channel->name}.id_{$entity->name}={$entity->name}.id
  7384. WHERE {$entity->name}_{$this->channel->name}.id_{$this->channel->name}={$data['id']}
  7385. {$filter}";
  7386. }
  7387. $buffer = aux::getResult($query);
  7388. if (count($buffer) > 0) {
  7389. foreach ($buffer as $item) {
  7390. if (is_array($entity->rssPresentation)) {
  7391. foreach ($entity->rssPresentation as $c_rss=>$c_tab) {
  7392. switch($c_rss) {
  7393. case "pubDate":
  7394. $rss->setContent("item_{$c_rss}", aux::formatDate($item[$c_tab], RSS));
  7395. break;
  7396. default:
  7397. $rss->setContent("item_{$c_rss}", $item[$c_tab]);
  7398. break;
  7399. }
  7400. }
  7401. $rss->setContent("item_link", $channel['link']."?id={$item['id']}");
  7402. if ($entity->owner) {
  7403. $rss->setContent("item_author", aux::xmlchars(aux::formatDate($item[$entity->fields[0]['name']])));
  7404. }
  7405. }
  7406. }
  7407. }
  7408. }
  7409. }
  7410. Header('Content-type: text/xml; charset=utf-8;');
  7411. $rss->close();
  7412. }
  7413. /**
  7414. * Setta il content-type del hearder per l'xml e procede con la stampa di result.
  7415. *
  7416. * @return print
  7417. */
  7418. function printRss(){
  7419. header('Content-type: text/xml; charset=utf-8;');
  7420. print $this->result;
  7421. }
  7422. } // Class - FeedRss
  7423. /**
  7424. * Class - Comments
  7425. *
  7426. */
  7427. Class Comments {
  7428. /**
  7429. * Entity associated with the comments.
  7430. *
  7431. * @var Entity
  7432. */
  7433. var $entity;
  7434. var $entitykey;
  7435. /**
  7436. * Is a moderate Entity
  7437. *
  7438. * @var bool
  7439. */
  7440. var $moderated = false;
  7441. /**
  7442. * Constructor.
  7443. *
  7444. * @param Entity $entity
  7445. * @return Comments
  7446. */
  7447. function Comments(&$entity) {
  7448. $this->entity = $entity;
  7449. $GLOBALS['becontent']->comments[$entity->name] = &$this;
  7450. $entity->comments = &$this;
  7451. }
  7452. /**
  7453. * Adds a comment.
  7454. * Really only Sends email to moderators
  7455. *
  7456. * @param integer $id
  7457. * @param bool $add
  7458. * @return string html content
  7459. */
  7460. function addComment($id, $add = false) {
  7461. if (isset($_SESSION['user'])) { // logged in
  7462. $addcomment = new Template("dtml/addcomment.html");
  7463. $addcomment->setContent("id", $id);
  7464. $addcomment->setContent("button", aux::lingual("Aggiungi Commento", "Add Comment", "Aggiungi Commento"));
  7465. $addcomment->setContent("message", aux::lingual("Attenzione: inserisci un commento!", "Warning: please enter a comment!", "Attenzione: inserisci un commento!"));
  7466. if ($add) { //send mail to moderators
  7467. $insertid = mysql_insert_id();
  7468. $data = aux::getResult("
  7469. SELECT {$GLOBALS['usersEntity']->name}.email,
  7470. {$GLOBALS['usersEntity']->name}.name,
  7471. {$GLOBALS['usersEntity']->name}.surname
  7472. FROM {$GLOBALS['commentEntity']->name}
  7473. LEFT JOIN {$GLOBALS['entitiesEntity']->name}
  7474. ON {$GLOBALS['entitiesEntity']->name}.name = {$GLOBALS['commentEntity']->name}.entityname
  7475. LEFT JOIN {$GLOBALS['usersGroupsRelation']->name}
  7476. ON {$GLOBALS['usersGroupsRelation']->name}.id_groups = entities.forum_moderator
  7477. LEFT JOIN {$GLOBALS['usersEntity']->name}
  7478. ON {$GLOBALS['usersEntity']->name}.username = {$GLOBALS['usersGroupsRelation']->name}.username
  7479. WHERE id = {$insertid}
  7480. AND {$GLOBALS['entitiesEntity']->name}.forum_moderator > 0");
  7481. if (count($data) > 0) {
  7482. foreach ($data as $user) { // moderators
  7483. $mail = new Template("dtml/moderazione-commenti.mail");
  7484. $mail->setContent("name", $user['name']);
  7485. $mail->setContent("surname", $user['surname']);
  7486. mail($user['email'],"[{$GLOBALS['config']['website']['name']}] nuovo commento",$mail->get(), "From: {$_SESSION['user']['email']}");
  7487. }
  7488. $addcomment->setContent("notify", aux::lingual("Il suo commento � stato inoltrato.", "Your comment has been recived.", "Il suo commento � stato inoltrato."));
  7489. }
  7490. } // if (add)
  7491. } else { // not logged in
  7492. $addcomment = new Template("dtml/addcomment-notlogged.html");
  7493. $addcomment->setContent("notify", aux::lingual("Per aggiungere un commento devi loggarti nel tuo account!", "PLease log to add a comment", "Per aggiungere un commento devi loggarti nel tuo account!"));
  7494. }
  7495. return $addcomment->get();
  7496. }
  7497. /**
  7498. * Gets a comment.
  7499. *
  7500. * @param integer $id comment
  7501. * @return string html content
  7502. */
  7503. function getComments($id) {
  7504. $comments = new Template("dtml/comments.html");
  7505. $data = aux::getResult("
  7506. SELECT *
  7507. FROM comments
  7508. LEFT JOIN users
  7509. ON users.username = comments.username
  7510. WHERE entityname = '{$this->entity->name}'
  7511. AND itemid = '{$id}'
  7512. AND comments.active = '*'
  7513. AND users.active = '*'
  7514. ORDER BY creation DESC");
  7515. if (count($data) > 0) {
  7516. foreach($data as $item) {
  7517. foreach($item as $k => $v) {
  7518. switch($k) {
  7519. case "creation":
  7520. $comments->setContent($k,aux::formatDate($v, EXTENDED));
  7521. break;
  7522. default:
  7523. $comments->setContent($k,$v);
  7524. break;
  7525. }
  7526. }
  7527. }
  7528. } else {
  7529. $comments->setContent("username","");
  7530. $comments->setContent("creation", "");
  7531. $comments->setContent("body", aux::lingual("Non ci sono commenti", "No comments", "Nemo para commentares"));
  7532. }
  7533. return $comments->get();
  7534. }
  7535. } // Class - Comments
  7536. /*
  7537. The following codeis to avoid Remote SQL Injections.
  7538. 08-07-2008: there is a problem, with selectFromReference and primary key different than INT AUTO_INCREMENT.
  7539. ** Solution: in order to detect Remote SQL injections accordig to the expected datatypes the check must be
  7540. included in the transation addItem and editItem because it is possible to check the datatypes
  7541. of the involved entity;
  7542. ** Workaround: all the non numeric potential keys are escaped;
  7543. */
  7544. if (basename($_SERVER['SCRIPT_FILENAME']) != "error.php") {
  7545. foreach ($_REQUEST as $k => $v) {
  7546. if ($k == "id") {
  7547. if (!ereg("^[[:digit:]]*$", $v)) {
  7548. $_REQUEST[$k] = mysql_escape_string($v);
  7549. }
  7550. } elseif (ereg("\_id$", $k)) {
  7551. if (!ereg("^[[:digit:]]*$", $v)) {
  7552. $_REQUEST[$k] = aux::escape_string($v);; // $_REQUEST[$k] = -1;
  7553. }
  7554. } elseif (ereg("^id\_", $k)) {
  7555. if (!ereg("^[[:digit:]]*$", $v)) {
  7556. $_REQUEST[$k] = aux::escape_string($v); // $_REQUEST[$k] = -1;
  7557. }
  7558. } elseif ($k == "username") {
  7559. $_REQUEST['username'] = mysql_escape_string($v);
  7560. } elseif ($k == "name") {
  7561. $_REQUEST['name'] = mysql_escape_string($v);
  7562. } elseif ($k == "surname") {
  7563. $_REQUEST['surname'] = mysql_escape_string($v);
  7564. } elseif ($k == "email") {
  7565. $_REQUEST['email'] = mysql_escape_string($v);
  7566. }
  7567. }
  7568. }
  7569. /**
  7570. * Configuration Inclusion - adds configuration from config.inc.php
  7571. */
  7572. if (file_exists("include/config.inc.php")) {
  7573. require "include/config.inc.php";
  7574. } else {
  7575. require "../include/config.inc.php";
  7576. }
  7577. $database = new DB(
  7578. $config['database'][$_SERVER['SERVER_NAME']]['host'],
  7579. $config['database'][$_SERVER['SERVER_NAME']]['database'],
  7580. $config['database'][$_SERVER['SERVER_NAME']]['username'],
  7581. $config['database'][$_SERVER['SERVER_NAME']]['password']
  7582. );
  7583. $message = new Message($config['language']);
  7584. /**
  7585. * Metamodel Inclusion -
  7586. */
  7587. if (file_exists("include/entities.inc.php")) {
  7588. require "include/entities.inc.php";
  7589. } else {
  7590. require "../include/entities.inc.php";
  7591. }
  7592. $database->init();
  7593. if (isset($_REQUEST['action'])) {
  7594. switch($_REQUEST['action']) {
  7595. case "password":
  7596. $skin = new Skin("dipartimento");
  7597. $mail = new Skinlet("password.mail");
  7598. #echo "QUI";
  7599. $data = aux::getResult("SELECT * FROM {$usersEntity->name} WHERE email = '{$_REQUEST['email']}'");
  7600. if (mysql_affected_rows() == 0) {
  7601. $_REQUEST['id'] = NOTIFICATION_ERROR;
  7602. } else {
  7603. $password = substr(md5(time()),0,8);
  7604. $oid = mysql_query("UPDATE {$usersEntity->name}
  7605. SET password = MD5('{$password}')
  7606. WHERE username='{$data[0]['username']}'");
  7607. $data[0]['password'] = $password;
  7608. foreach ($data[0] as $k => $v) {
  7609. $mail->setContent($k,$v);
  7610. }
  7611. mail($data[0]['email'], "Login data", $mail->get(),
  7612. "From: {$GLOBALS['config']['website']['email']}");
  7613. $_REQUEST['id'] = NOTIFICATION;
  7614. }
  7615. break;
  7616. }
  7617. }
  7618. /*
  7619. alphaMask class v.0.1
  7620. author: Fabio Righi
  7621. constructor parameters :
  7622. $thumb : imagecreatetruecolor image,
  7623. $params: masklabel[|hexbgcolor]
  7624. output :
  7625. a mask-blended png image if hexbgcolor is not defined,
  7626. a mask-blended jpg image with bgcolor background if not.
  7627. example of use:
  7628. if (isset($_GET['mask']))
  7629. {
  7630. $maskedImage = new alphaMask($thumb,$_GET['mask']);
  7631. $maskedImage->render();
  7632. }
  7633. */
  7634. /* MASK LABEL-PATHS */
  7635. define("MASK_CORNERS_THUMB", "img/beContent/maskcornersthumb.png");
  7636. /**
  7637. * Class - alphaMask
  7638. *
  7639. */
  7640. class alphaMask
  7641. {
  7642. var $thumb, $thumbW, $thumbH, $bgColor, $alphamode;
  7643. function alphaMask(&$thumb, $params) {
  7644. $this->thumb = $thumb;
  7645. $this->width = imagesx($thumb);
  7646. $this->height = imagesy($thumb);
  7647. $this->renderMode = 'jpeg';
  7648. list($maskType, $bgColor) = explode("|", $params);
  7649. if (defined($maskType))
  7650. $this->maskFile = constant($maskType);
  7651. else
  7652. $this->maskFile = null;
  7653. if (empty($bgColor) || !preg_match("/^([a-f]|[A-F]|[0-9]){6}$/", $bgColor))
  7654. {
  7655. $this->renderMode = 'png';
  7656. $this->bgColor = 'FFFFFF';
  7657. }
  7658. else
  7659. $this->bgColor = $bgColor;
  7660. }
  7661. function render() {
  7662. if (!is_null($this->maskFile) && file_exists($this->maskFile))
  7663. {
  7664. $mask = imagecreatefrompng($this->maskFile);
  7665. // Get new sizes
  7666. $maskW = imagesx($mask);
  7667. $maskH = imagesy($mask);
  7668. $newwidth = $maskW * ($this->width / $maskW);
  7669. $newheight = $maskH * ($this->height / $maskH);
  7670. $resizedMask = imagecreatetruecolor($newwidth, $newheight);
  7671. $bg = imagecolorallocate($resizedMask, 0, 0, 0);
  7672. imagecolortransparent($resizedMask, $bg);
  7673. imagealphablending($resizedMask, false);
  7674. // Mask Resize
  7675. imagecopyresized($resizedMask, $mask, 0, 0, 0, 0, $newwidth, $newheight, $maskW, $maskH);
  7676. $resizedMaskBlendTemp = imagecreatetruecolor($this->width, $this->height);
  7677. //Mask filled with bgColor
  7678. $colorBackground = imagecolorallocate($resizedMaskBlendTemp, hexdec(substr($this->bgColor, 0, 2)), hexdec(substr($this->bgColor, 2, 2)), hexdec(substr($this->bgColor, 4, 2)));
  7679. imagefilledrectangle($resizedMaskBlendTemp, 0, 0, imagesx($resizedMaskBlendTemp), imagesy($resizedMaskBlendTemp), $colorBackground);
  7680. //Blended mode
  7681. if (strcmp($this->renderMode, 'png'))
  7682. imagealphablending($resizedMaskBlendTemp, true);
  7683. else
  7684. imagealphablending($resizedMaskBlendTemp, false);
  7685. imagesavealpha($resizedMaskBlendTemp, true);
  7686. //Main loop
  7687. for ($x = 0; $x < $this->width; $x++)
  7688. {
  7689. for ($y = 0; $y < $this->height; $y++)
  7690. {
  7691. $realPixel = $this->getPixelColor($this->thumb, $x, $y);
  7692. $maskPixel = $this->grayscalePixel($this->getPixelColor($resizedMask, $x, $y));
  7693. //Get opacity value
  7694. $maskAlpha = 127 - (floor($maskPixel['red'] / 2) * (1 - ($realPixel['alpha'] / 127)));
  7695. //Blend!!
  7696. $newPixelColor = $this->imageColorAllocateWithAlpha($resizedMaskBlendTemp, $realPixel['red'], $realPixel['green'], $realPixel['blue'], $maskAlpha);
  7697. imagesetpixel($resizedMaskBlendTemp, $x, $y, $newPixelColor);
  7698. }
  7699. }
  7700. //Blended mode off on thumb image
  7701. imagealphablending($this->thumb, false);
  7702. imagesavealpha($this->thumb, true);
  7703. imagecopy($this->thumb, $resizedMaskBlendTemp, 0, 0, 0, 0, imagesx($resizedMaskBlendTemp), imagesy($resizedMaskBlendTemp));
  7704. }
  7705. //Overwrite header type
  7706. header("Content-type: image/$this->renderMode");
  7707. //Call appropriate imagecreation function
  7708. call_user_func('image' . $this->renderMode, $this->thumb);
  7709. }
  7710. function imageColorAllocateWithAlpha(&$oImg, $rComponent, $gComponent, $bComponent, $alpha = false)
  7711. {
  7712. if ($alpha !== false)
  7713. return imagecolorallocatealpha($oImg, $rComponent, $gComponent, $bComponent, intval($alpha));
  7714. else
  7715. return imagecolorallocate($oImg, $rComponent, $gComponent, $bComponent);
  7716. }
  7717. function grayscaleValue($rComponent, $gComponent, $bComponent)
  7718. {
  7719. return round(($rComponent * 0.30) + ($gComponent * 0.59) + ($bComponent * 0.11));
  7720. }
  7721. function grayscalePixel($origPixel)
  7722. {
  7723. $grayValue = $this->grayscaleValue($origPixel['red'], $origPixel['green'], $origPixel['blue']);
  7724. return array('red' => $grayValue, 'green' => $grayValue, 'blue' => $grayValue);
  7725. }
  7726. function getPixelColor(&$oImg, $x, $y)
  7727. {
  7728. if (!is_resource($oImg))
  7729. return false;
  7730. return imagecolorsforindex($oImg, imagecolorat($oImg, $x, $y));
  7731. }
  7732. }
  7733. ?>