....................................../////.===Shadow-Here===./////................................................ > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < > < ------------------------------------------------------------------------------------------------------------------- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RIFF¤ WEBPVP8 ˜ ðÑ *ôô>‘HŸK¥¤"§£±¨àð enü¹%½_F‘åè¿2ºQú³íªú`N¿­3ÿƒügµJžaÿ¯ÿ°~¼ÎùnúîÞÖô•òíôÁÉß®Sm¥Ü/ ‡ó˜f£Ùà<˜„xëJ¢Ù€SO3x<ªÔ©4¿+ç¶A`q@Ì“Úñè™ÍÿJÌ´ª-˜ÆtÊÛL]Ïq*‘Ý”ì#ŸÌÏãY]@ê`¿ /ªfkØB4·®£ó z—Üw¥Pxù–ÞLШKÇN¾AkÙTf½è'‰g gÆv›Øuh~ a˜Z— ïj*á¥t d£“uÒ ¨`K˜¹ßþ]b>˜]_ÏÔ6W—è2r4x•íÖ…"ƒÖNîä!¦å Ú}ýxGøÌ —@ ;ÆÚŠ=ɾ1ý8lªË¥ô ^yf®Œ¢u&2©nÙÇ›ñÂñŒ³ aPo['½»øFùà­+4ê“$!lövlüÞ=;N®3ð‚õ›DÉKòÞ>ÄÍ ¥ˆuߤ#ˆ$6ù™¥îЇy’ÍB¼ çxÛ;X"WL£R÷͝*ó-¶Zu}º.s¸sšXqù–DþÿvªhüïwyŸ ¯é³lÀ:KCûÄ£Ëá\…­ ~—ýóî ¼ûûÜTÓüÇy…ŽÆvc»¾×U ñ¸žþоP÷¦ó:Ò¨¨5;Ð#&#ÖúñläÿÁœ GxÉ­/ñ‡áQðìYÉtÒw޼GÔ´zàÒò ð*ëzƒ•4~H]Ø‹f ñÓÈñ`NåWçs'ÆÏW^ø¹!XžµmQ5ÃËoLœÎ: ÞËÍ¥J ù…î èo£ßPÎñ¶ž8.Œ]ʵ~5›ÙË-ù*8ÙÖß±~ ©¹rÓê‚j¶d¸{^Q'˜±Crß ÚH—#¥¥QlÀ×ëã‡DÜ«èî þ&Çæžî;ŽÏºò6ÒLÃXy&ZŒ'j‚¢Ù€IßÚù+–MGi‰*jE€‘JcÜ ÓÌ EÏÚj]o˜ Þr <¾U ûŪæÍ/šÝH¥˜b”¼ ÁñßX GP›ï2›4WŠÏà×£…íÓk†¦H·ÅíMh–*nó÷à]ÁjCº€b7<ب‹¨5車bp2:Á[UªM„QŒçiNMa#<5›áËó¸HýÊ"…×Éw¹¦ì2º–x<›»a±¸3Weü®FÝ⑱ö–î–³|LPÈ~çð~Çå‡|º kD¢µÏàÆAI %1À% ¹Ò – ”ϝS¦‰4&¶£°à Öý”û_Ò Áw°A«Å€?mÇÛgHÉ/8)á¾ÛìáöŽP í¨PŸNÙµº¦‡§Ùš"ÿ«>+ªÕ`Ê÷‡‚ß Õû˜þãÇ-PÍ.¾XV‘€ dÜ"þ4¹ ±Oú‘©t¥¦FªÄÃÄ•b‚znýu½—#cDs˜ÃiÑOˆñ×QO=*IAÊ,¶ŽZƒ;‡wøXè%EÐk:F±Ú” .Ѽ+Áu&Ç`."pÈÉw o&¿dE6‘’EqTuK@Ì¥ã™À(Êk(h‰,H}RÀIXÛš3µ1©_OqÚÒJAñ$ÊÙÜ;D3çŒ[þùœh¬Ã³™ö6ç†NY".Ú‰ï[ªŸŒ '²Ð öø_¨ÂÉ9ué¶³ÒŠõTàîMØ#û¯gN‡bÙ놚X„ö …ÉeüÌ^J ‹€.œ$Æ)βÄeæW#óüßĺŸ€ ÀzwV 9oä»f4V*uB «Ë†¹ì¯žR霓æHXa=&“I4K;¯ç‹h×·"UŠ~<•╪Vêª&ÍSÃÆÅ?ÔqÎ*mTM ˜›µwêd#[C¡©§‘D<©àb†–ÁœøvH/,í:¯( ²£|4-„Æövv„Yͼ™^Á$ˆ„¢Û[6yB.åH*V¨æ?$=˜Ñ€•ñ·­(VlŸ‘ nÀt8W÷´Bûba?q9ú¶Xƒl«ÿ\ù¶’þòUÐj/õ¢Ìµ³g$ƒÎR!¸»|Oߍë’BhîÚÑ¢ñåŒJ„®„£2Ð3•ô02Nt…!£Í]Ïc½Qÿ?ˆ<&ÃA¾Ú,JˆijÌ#5yz„‰Î|ÊŽ5QÏ:‹ÐaóVÔxW—CpeÏzÐïíçôÿÅ_[hãsÐ_/ŽTÝ?BîˆííV$<¿i>²F¬_Eß¿ †bÊŒº­ÿ®Z H“C}”¬,Mp ý/Bá£w>˜YV°aƒúh+cŠ- r/[%|üUMHäQ°X»|û/@|°¥Ð !BÔ Ç¢Ä©š+Õì D«7ìN¶ŽðÔ " ƶ’ÖçtA‰Û×}{tþz­¾GÍ›k¹OEJR$ Â׃ «ëÁ"oÉôž$oUK(Ä)Ãz³Ê-‹êN[Ò3Œñbï8P 4ƒ×q¢bo|?<ÛX¬òÄͰL–±›(™ûG?ýË©ÚÄ–ÂDØÐ_Ç¡ô ¾–ÄÏø ×e8Ë©$ÄF¹Å‹ì[©óìl:F¾f´‹‹Xì²ï®\¬ôùƒ ÿat¥óèÒùHß0äe‚;ü×h:ÆWðHž=Ã8骣"kœ'Y?³}Tûè€>?0l›e1Lòñ„aæKÆw…hÖŠùW…ÈÆÄ0ši·›[pcwËþñiêíY/~-Á5˜!¿†A›™Mÿþ(±“t@â“ö2­´TG5yé]çå僳 .·ÍïçÝ7UÚ±Ð/Nè»,_Ï ùdj7\ï Wì4›„»c¸àešg#ÒÊ⥭áØo5‘?ÌdÝô¯ ¹kzsƒ=´#ëÉK›Ø´±-¥eW?‡çßtòTã…$Ý+qÿ±ƒ÷_3Ô¥í÷:æ–ž<·Ö‡‰Å¢ š‡%Ô—utÌÈìðžgÖÀz²À—ï÷Óîäõ{K'´È÷³yaÏÁjƒô}ž§®æÊydÕÈë5¯èˆõvÕ©ã*çD„ “z„Ó‡^^xÂ3M§A´JG‚öï 3W'ˆ.OvXè¡ÊÕª?5º7†˜(˜Ç¶#çê’¶!ÌdZK§æ 0fãaN]òY³RV ™î$®K2R¨`W!1Ôó\;Ý ýB%qæK•&ÓÈe9È0êI±žeŸß -ú@žQr¦ ö4»M¼Áè¹µmw 9 EÆE_°2ó„ŸXKWÁ×Hóì^´²GѝF©óäR†¦‰ç"V»eØ<3ùd3ÿÚ¤Žú“Gi" —‘_ÙËÎ~Üö¯¥½Î»üŸEÚŽåmÞþí ;ÞólËΦMzA"Âf(´òá;Éï(/7½ûñÌ­cïÕçлþÝz¾-ÍvÑ“pH­–ðÓj$¸Äû¤‚‘ãUBË-n“2åPkS5&‹Â|+g^œ®Ì͆d!OïäîU«c;{Û!ÅŽ«ëZ9Ókóˆ]¯ƒ›né `ÇÒ+tÆš (ØKá¾—=3œ®•vuMñg²\ï Ec€ 05±d™‡×iÇ×›UúvÌ¢£Èþ¡ÕØô¶ßÎA"ß±#Ö²ˆÊŸ¦*Ä~ij|àø.-¼'»Ú¥£h ofº¦‡VsR=N½„Î v˜Z*SÌ{=jÑB‹tê…;’HžH¯8–îDù8ñ¢|Q•bÛçš–‹m³“ê¨ åÏ^m¬Žãþ©ïêO‡½6] µÆ„Ooòü ²x}N¦Ë3ïé¿»€›HA˜m%çÞ/¿í7Fø“‹léUk)É°Œµ8Q8›:ÀŠeT*šõ~ôڝG6 ¢}`ùH­–”¡k ‰P1>š†®9z11!X wKfmÁ¦xÑ,N1Q”–æB¶M…ÒÃv6SMˆhU¬ÊPŽï‘öj=·CŒ¯u¹ƒVIЃsx4’ömÛýcå¡¶7ßŠß 57^\wÒÐÆ k§h,Œý î«q^R½3]J¸ÇðN ‚çU¬ôº^Áì} ³f©Õœ§ˆã:FÄÈ‚é(€™?àýÓüè1Gô£¼éj‚OÅñ  #>×—ßtà 0G¥Åa뀐kßhc™À_ÉñÞ#±)GD" YîäË-ÿÙ̪ ¹™a¯´¢E\ÝÒö‚;™„ë]_ p8‰o¡ñ+^÷ 3‘'dT4œŽ ðVë½° :¬víÑ«£tßÚS-3¶“þ2 †üüʨòrš¹M{É_¤`Û¨0ìjœøJ‡:÷ÃáZ˜†@GP&œÑDGÏs¡þ¦þDGú‘1Yá9Ôþ¼ ûø…§÷8&–ÜÑnÄ_m®^üÆ`;ÉVÁJ£?â€-ßê}suÍ2sõA NÌúA磸‘îÿÚ»ƒìö·á¿±tÑÐ"Tÿü˜[@/äj¬€uüªìù¥Ý˜á8Ý´sõj 8@rˆð äþZÇD®ÿUÏ2ùôõrBzÆÏÞž>Ì™xœ“ wiÎ×7_… ¸ \#€MɁV¶¥üÕÿPÔ9Z‡ø§É8#H:ƒ5ÀÝå9ÍIŒ5åKÙŠ÷qÄ>1AÈøžj"µÂд/ªnÀ qªã}"iŸBå˜ÓÛŽ¦…&ݧ;G@—³b¯“•"´4í¨ôM¨åñC‹ïùÉó¯ÓsSH2Ý@ßáM‡ˆKÀªÛUeø/4\gnm¥‹ŸŒ qÄ b9ÞwÒNÏ_4Ég³ú=܆‚´ •â¥õeíþkjz>éÚyU«Íӝ݃6"8/ø{=Ô¢»G¥ äUw°W«,ô—¿ãㆅү¢³xŠUû™yŒ (øSópÐ 9\åTâ»—*oG$/×ÍT†Y¿1¤Þ¢_‡ ¼ „±ÍçèSaÓ 3ÛMÁBkxs‰’R/¡¤ˆÙçª(*õ„üXÌ´ƒ E§´¬EF"Ù”R/ÐNyÆÂ^°?™6¡œïJ·±$§?º>ÖüœcNÌù¯G ‹ñ2ЁBB„^·úìaz¨k:#¨Æ¨8LÎõލ£^§S&cŒÐU€ü(‡F±Š¼&P>8ÙÁ ‰ p5?0ÊÆƒZl¸aô š¼¡}gÿ¶zÆC²¹¬ÎÖG*HB¡O<º2#ñŒAƒ–¡B˜´É$¥›É:FÀÔx¾u?XÜÏÓvN©RS{2ʈãk9rmP¼Qq̳ è¼ÐFׄ^¡Öì fE“F4A…!ì/…¦Lƒ… … $%´¾yã@CI¬ á—3PþBÏNÿ<ý°4Ü ËÃ#ØÍ~âW«rEñw‹eùMMHß²`¬Öó½íf³:‹k˜¯÷}Z!ã¿<¥,\#öµÀ¯aÒNÆIé,Ћ–lŽ#Àæ9ÀÒS·I’½-Ïp Äz¤Š Â* ­íÄ9­< h>׍3ZkËU¹§˜ŒŠ±f­’¤º³Q ÏB?‹#µíÃ¥®@(Gs«†vI¥Mµ‹Á©e~2ú³ÁP4ìÕi‚²Ê^ö@-DþÓàlÜOÍ]n"µã:žpsŽ¢:! Aõ.ç~ÓBûH÷JCÌ]õVƒd «ú´QÙEA–¯¯Œ!.ˆˆëQ±ù œ·Ì!Õâ )ùL„ÅÀlÚè5@B…o´Æ¸XÓ&Û…O«˜”_#‡ƒ„ûÈt!¤ÁÏ›ÎÝŠ?c9 â\>lÓÁVÄÑ™£eØY]:fÝ–—ù+p{™ðè û³”g±OƒÚSù£áÁÊ„ä,ï7š²G ÕÌBk)~ÑiCµ|h#u¤¶îK¨² #²vݯGãeÖ϶ú…¾múÀ¶þÔñ‚Š9'^($¤§ò “š½{éúp÷J›ušS¹áªCÂubÃH9™D™/ZöØÁ‡¦ÝÙŸ·kð*_”.C‹{áXó€‡c¡c€§/šò/&éš÷,àéJþ‰X›fµ“C¨œ®r¬"kL‰Â_q…Z–.ÉL~O µ›zn‚¹À¦Öª7\àHµšÖ %»ÇníV[¥*Õ;ƒ#½¾HK-ÖIÊdÏEÚ#=o÷Óò³´Š: Ç?{¾+9›–‘OEáU·S€˜j"ÄaÜ ŒÛWt› á–c#a»pÔZÞdŽtWê=9éöÊ¢µ~ ë ;Öe‡Œ®:bî3±ýê¢wà¼îpêñ¹¾4 zc¾ðÖÿzdêŒÑÒŝÀ‰s6¤í³ÎÙB¿OZ”+F¤á‡3@Ñëäg©·Ž ˆèª<ù@É{&S„œÕúÀA)‰h:YÀ5^ÂÓŒ°õäU\ ùËÍû#²?Xe¬tu‰^zÒÔãë¼ÛWtEtû …‚g¶Úüâî*moGè¨7%u!]PhÏd™Ý%Îx: VÒ¦ôÊD3ÀŽKÛËãvÆî…N¯ä>Eró–ð`5 Œ%u5XkñÌ*NU%¶áœÊ:Qÿú»“úzyÏ6å-၇¾ ´ ÒÊ]y žO‘w2Äøæ…H’²f±ÎÇ.ª|¥'gîV•Ü .̘¯€šòü¤U~Ù†*¢!?ò wý,}´°ÔÞnïoKq5µb!áÓ3"vAßH¡³¡·G(ÐÎ0Îò¼MG!/ài®@—¬04*`…«é8ªøøló“ˆÊ”èù¤…ßÊoÿé'ËuÌÖ5×È¡§ˆˆfŽë9}hìâ_!!¯  B&Ëö¶‰ÀAÙNVŸ Wh›¸®XÑJì¨ú“¿÷3uj²˜¨ÍÎìë±aúŠÝå¯ð*Ó¨ôJ“yºØ)m°WýOè68†ŸÏ2—‰Ïüꪫٚ¥‹l1 ø ÏÄFjêµvÌbü¦èÝx:X±¢H=MÐß—,ˆÉÇ´(9ú¾^ÅÚ4¿m‡$âX‘å%(AlZo@½¨UOÌÕ”1ø¸jÎÀÃÃ_ µ‘Ü.œº¦Ut: Æï’!=¯uwû#,“pþÇúŒø(é@?³ü¥‘Mo §—s@Œ#)§ŒùkL}NOÆêA›¸~r½¼ÙA—HJ«eˆÖ´*¡ÓpÌŸö.m<-"³ûÈ$¬_6­åf£ïÚâj1y§ÕJ½@dÞÁr&Í\Z%D£Íñ·AZ Û³øüd/ªAi†/Й~  ‡âĮҮÏh§°b—›Û«mJžòG'[ÈYýŒ¦9psl ýÁ ®±f¦x,‰½tN ‚Xª9 ÙÖH.«Lo0×?͹m¡å†Ѽ+›2ƒF ±Ê8 7Hցϓ²Æ–m9…òŸï]Â1äN†VLâCˆU .ÿ‰Ts +ÅÎx(%¦u]6AF Š ØF鈄‘ |¢¶c±soŒ/t[a¾–û:s·`i햍ê›ËchÈ…8ßÀUÜewŒðNOƒõD%q#éû\9¤x¹&UE×G¥ Í—™$ð E6-‡¼!ýpãÔM˜ Âsìe¯ñµK¢Ç¡ùôléœ4Ö£”À Š®Ðc ^¨À}ÙËŸ§›ºê{ÊuÉC ×Sr€¤’fÉ*j!úÓ’Gsùìoîßîn%ò· àc Wp÷$¨˜)û»H ×8ŽÒ€Zj¤3ÀÙºY'Ql¦py{-6íÔCeiØp‘‡XÊîÆUߢ܂ž£Xé¼Y8þ©ëgñß}é.ÎógÒ„ÃØËø¯»™§Xýy M%@NŠ À(~áÐvu7&•,Ù˜ó€uP‡^^®=_E„jt’ 403WebShell
403Webshell
Server IP : 195.3.193.33  /  Your IP : 216.73.216.125
Web Server : Apache
System : Linux server3 5.10.0-35-amd64 #1 SMP Debian 5.10.237-1 (2025-05-19) x86_64
User : web032 ( 1035)
PHP Version : 7.3.33
Disable Function : show_source, highlight_file, apache_child_terminate, apache_get_modules, apache_note, apache_setenv, virtual, dl, disk_total_space, posix_getpwnam, posix_getpwuid, posix_mkfifo, posix_mknod, posix_setpgid, posix_setsid, posix_setuid, posix_uname, proc_nice, openlog, syslog, pfsockopen
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/web032/htdocs/cms/components/com_rialto/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/web032/htdocs/cms/components/com_rialto/models/entry.php
<?php
/**
 *
 * Rialto - Classified Ads for Joomla!
 *
 * @Version       $Id: entry.php 2306 2016-06-13 13:24:56Z geoffc $
 * @Package       Rialto
 * @Subpackage    com_rialto
 * @Release       1.3.0
 * @Copyright     Copyright (C) 2015-2016 Macrotone Consulting Ltd. All rights reserved.
 * @License       GNU General Public License version 3 or later; see LICENSE.txt
 * @Contact       support@macrotoneconsulting.co.uk
 * @Lastrevision  $Date: 2016-06-13 14:24:56 +0100 (Mon, 13 Jun 2016) $
 *
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );

jimport('joomla.application.component.model');

require_once(JPATH_COMPONENT.DS.'classes/user.php');

if (! class_exists('RialtoHelperLog')) {
   require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_rialto'.DS.'classes'.DS.'log.php');
}

if (! class_exists('RialtoFrontendHelper')) {
   require_once( JPATH_COMPONENT.DS.'classes'.DS.'helper.php');
}

if (! class_exists('Akismet')) {
   require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_rialto'.DS.'classes'.DS.'Akismet.php');
}
/**
 * Rialto Entry Model
 */
class RialtoModelEntry extends JModelLegacy
{
   var $_item           = "";
   var $_task           = "";
   var $_id             = 0;
   var $_user_id        = 0;
   var $_catid          = 0;
   var $_header         = null;
   var $_firstname      = null;
   var $_lastname       = null;
   var $_company        = null;
   var $_street         = null;
   var $_zip            = null;
   var $_city           = null;
   var $_entryState     = null;
   var $_country        = null;
   var $_phone          = null;
   var $_mobile         = null;
   var $_email          = null;
   var $_web            = null;
   var $_title          = null;
   var $_description    = null;
   var $_entryCondition = null;
   var $_price          = null;
   var $_categoryId     = 0;
   var $_categoryName   = null;
   var $_categorySlug   = null;
   var $_categoryImage  = null;
   var $_image1         = null;
   var $_image2         = null;
   var $_image3         = null;
   var $_image4         = null;
   var $_image5         = null;
   var $_image6         = null;
   var $_image7         = null;
   var $_image8         = null;
   var $_image9         = null;
   var $_image10        = null;
   var $_video1         = null;
   var $_video2         = null;
   var $_video3         = null;
   var $_state          = 0;
   var $_flag_commercial = 0;
   var $_expired        = 0;
   var $_date_created   = null;
   var $_vtype1         = null;
   var $_vtype2         = null;
   var $_vtype3         = null;

   /**
    * Constructor
    *
    * @since 1.5
    */
   function __construct()
   {
      parent::__construct();

      $app = JFactory::getApplication();
      $this->_header = "Entry";

      $user = JFactory::getUser();
      $logUser = new RialtoUser( $user->id);
/*
      if ( $user->guest) { // user is not logged in
      } else { // user is logged in
      }
*/
      $input = JFactory::getApplication()->input;

      $this->_task   = $input->getString( 'task', '');
      $this->_id     = $input->getInt( 'entry', 0);

      $this->_title = $input->getString( 'title', '', 'POST');
      $this->_title = substr( strip_tags( $this->_title), 0, 255);

      $this->_description = $input->getString( 'description', '', 'POST');
      $this->_description = strip_tags( $this->_description);

      // get parameters
      $params = JComponentHelper::getParams('com_rialto');
      $logging = $params->get('enablelogging', '0');

      $_backendMode = $params->get('backendMode', '0'); // 0 no, 1 yes

      // if ( $logging )
 //         RialtoHelperLog::dblog('Model construct: '.$this->_task, JLog::INFO);
      switch ( $this->_task) {
         case "delete": {
            // check if backend mode is active
            if ( $_backendMode == 1) {
               $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");
               $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_BACKEND_MODE_ONLY' ), "message");
            }
            $this->deleteEntry();
            break;
         }
/*
         case "sendmessage": {
            // check if backend mode is active
            if ( $_backendMode == 1) {
               $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");
               $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_BACKEND_MODE_ONLY' ), "message");
            }
            $this->sendmessage();
            break;
         }
*/
         case "reactivate": {
            // check if backend mode is active
            if ( $_backendMode == 1) {
               $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");
               $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_BACKEND_MODE_ONLY' ), "message");
            }
            $this->reactivateEntry();
            break;
         }
         case "new":
         case "create":
         case "create1":
         case "create2":
         case "create3": {
            // check if user is blocked
            if ( $logUser->isBlocked()) {
               $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");
               $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_YOUR_ACCOUNT_HAS_BEEN_BLOCKED' ), "message");
            }

            // check if backend mode is active
            if ( $_backendMode == 1) {
               $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");
               $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_BACKEND_MODE_ONLY' ), "message");
            }
            break;
         }
         default: {
            break;
         }
      }

      // echo "<pre>";var_dump($input);echo "</pre>";
      switch ( $input->getString( 'submit', '')) {
         case JText::_( 'JSAVE' ):
            // check if backend mode is active
            if ( $_backendMode == 1) {
               $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");
               $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_BACKEND_MODE_ONLY' ), "message");
            }
            if ( $logging )
               RialtoHelperLog::dblog('Model calling saveEntry ', JLog::DEBUG);
            $this->saveEntry();
            break;
         case JText::_( 'COM_RIALTO_UPDATE' ):
            // check if backend mode is active
            if ( $_backendMode == 1) {
               $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");
               $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_BACKEND_MODE_ONLY' ), "message");
            }
            if ( $logging )
               RialtoHelperLog::dblog('Model calling updateEntry ', JLog::DEBUG);
            $this->updateEntry();
            break;
         case JText::_('COM_RIALTO_CONTACT_SEND_EMAIL'):
            if ( $logging )
               RialtoHelperLog::dblog('Model (submit) calling send message ', JLog::DEBUG);
            $this->sendmessage();
            break;
         default:
            if ( $logging )
               RialtoHelperLog::dblog('Model calling default ', JLog::DEBUG);
            $this->_header = "Entry";
            break;
      }
   }


   /**
    * Method to get the entry form.
    * The base form is loaded from XML and then an event is fired
    *
    * @param   array    $data      An optional array of data for the form to interrogate.
    * @param   boolean  $loadData  True if the form is to load its own data (default case), false if not.
    *
    * @return  JForm  A JForm object on success, false on failure
    * @since   1.6
    */
   public function getForm($data = array(), $loadData = true)
   {
      // Get the form.
      $form = $this->loadForm('com_rialto.entry', 'entry', array('control' => 'jform', 'load_data' => true));

      if (empty($form)) {
         return false;
      }

      $id = $this->getState('entry.id');
      $params = $this->getState('params');

      $contact = $this->_item[$id];
      $params->merge($contact->params);

      if (!$params->get('show_email_copy', 0)) {
         $form->removeField('contact_email_copy');
      }
      return $form;
   }

   /**
    * @return array
    */
   protected function loadFormData()
   {
      $data = (array) JFactory::getApplication()->getUserState('com_rialto.entry.data', array());

      $this->preprocessData('com_rialto.entry', $data);

      return $data;
   }

   /**
    * delete entry
    *
    * @return int
    */
   function deleteEntry()
   {
      $app = JFactory::getApplication();

      $user = JFactory::getUser();
      $logUser = new RialtoUser( $user->id);

      $this->_header = JText::_( 'COM_RIALTO_ENTRY_DELETED' );

      // redirect link
      $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");

      // check if user is logged in - maybe session has timed out
      if ($user->guest) {
         // if user is not logged in, kick him back to index page
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_DELETED_SESSION' ), "message");
      }

      $input = JFactory::getApplication()->input;
      $id         = $input->getInt( 'entry', 0);

      $user_id    = $user->id;

      $db = $this->getDBO();

      $sql = "SELECT user_id FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($id);

      $db->setQuery( $sql);
      $entry_user_id = $db->loadResult();

      if ( ($entry_user_id == $user_id) || $logUser->isModerator()) {
         // this is the owner or a moderator
      }  else {
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_DELETED_OWNER' ), "message");
      }

      // remove images and images folders
      // $this->rm_imagefolder( $id, $db);
      RialtoFrontendHelper::rm_imagefolder( $id );

      // Remove any associations that may exist.
      $assoc = JLanguageAssociations::isEnabled();
      if ($assoc) {
         $item = $this->getItem($id);
         $associations = $item->associations;

         foreach ($associations as $tag => $ii) {
            if (empty($ii)) {
               unset($associations[$tag]);
            }
         }

         // Detecting all item menus
         $all_language = $item->language == '*';

         if ($all_language && !empty($associations)) {
            JError::raiseNotice(403, JText::_('COM_RIALTO_ERROR_ALL_LANGUAGE_ASSOCIATED'));
         }

         $associations[$item->language] = $item->id;

         if ( count($associations) > 2 ) {
            // Only delete associations for this item. $cnt $pk
            $query = $db->getQuery(true)
               ->delete('#__associations')
               ->where('context=' . $db->quote('com_rialto.entry'))
               ->where('id = '.$db->Quote($id) );
         } else {
            // Delete all associations for these items
            $query = $db->getQuery(true)
               ->delete('#__associations')
               ->where('context=' . $db->quote('com_rialto.entry'))
               ->where('id IN (' . implode(',', $associations) . ')');
         }

         $db->setQuery($query);
         $db->execute();

         if ($error = $db->getErrorMsg()) {
            $this->setError($error);
            return false;
         }
      }

      // Changed so that table delete will also remove any tags.
      $this->addTablePath(JPATH_COMPONENT_ADMINISTRATOR.'/tables');
      $table = JTable::getInstance('RialtoEntry', 'Table', array());
      if ($table->delete($id) === true) {
         // Need to also remove ucm_content entry, present if tags were in use.
         // $ucmContentTable = JTable::getInstance('Corecontent');
         // $ucmContentTable->deleteByContentId($id, 'com_rialto.entry');

         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_BEEN_DELETED' ), "notice");
      } else {
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_DELETED_ERROR' ), "message");
      }

/*
      // Now remove entry itself.
      $sql = "DELETE FROM " . $db->quoteName( '#__rialto_entries') . " WHERE id = " . $db->Quote($id);
      $db->setQuery( $sql);
      $result = $db->execute();

      if ( $result) { // delete went fine
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_BEEN_DELETED' ), "notice");
      } else {
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_DELETED_ERROR' ), "message");
      }
*/
      return 0; // delete OK
   }


   /**
    * reactivate entry
    *
    * @return int
   */
   function reactivateEntry()
   {
      $app  = JFactory::getApplication();
      $user = JFactory::getUser();
      $logUser = new RialtoUser( $user->id);

      //$this->_header = JText::_( 'COM_RIALTO_ENTRY_DELETED' );

      // redirect link
      $redirectLink = JRoute::_( "index.php?option=com_rialto&view=category");

      // check if user is logged in - maybe session has timed out
      if ($user->guest) {
         // if user is not logged in, kick him back to index page
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_REACTIVATED_SESSION' ), "message");
      }

      $input   = JFactory::getApplication()->input;
      $id      = $input->getInt( 'entry', 0);

      $user_id = $user->id;

      $db   = $this->getDBO();
      $sql  = "SELECT user_id, category_id, expired, ";
      $sql .= ' CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as eslug,';
      $sql .= ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as cslug';
      $sql .= ' FROM #__rialto_entries i,  #__rialto_categories c';
      $sql .= ' WHERE i.id='.$id;
      $sql .= ' AND i.category_id=c.id ';
      $db->setQuery( $sql );
      $res  = $db->loadObject();

      $entry_user_id = $res->user_id;

      if ( ($entry_user_id == $user_id) || $logUser->isModerator()) {
         // this is the owner or a moderator
      } else {
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_REACTIVATED_OWNER' ), "message");
      }

      $expired = $res->expired;
      if ( ($expired == 0)) { // this is not an expired entry
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_REACTIVATED_EXPIRED' ), "message");
      }

      // 1. set state=1
      // 2. set expired=0
      // 3. set date_created = today
      // 4. set date_lastmodified = today

      $date_today = gmdate('Y-m-d H:i:s');

      $sql = "UPDATE " . $db->quoteName( '#__rialto_entries') .
               " SET" .
                  " `state` = '1'," .
                  " `expired` = '0'," .
                  " `date_created` = " . $db->Quote( $date_today) . ", " .
                  " `date_lastmodified` = " . $db->Quote( $date_today) .
               " WHERE id = " . $db->Quote($id);

      $db->setQuery( $sql);
      $result = $db->execute();

      if ( $result) { // reactivate went fine
         $redirectLink = JRoute::_("index.php?option=com_rialto&catid=".$res->cslug."&view=entry&entry=".$res->eslug);
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_BEEN_REACTIVATED' ), "notice");
      } else {
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_REACTIVATED_ERROR' ), "message");
      }

      return 0; // reactivate OK
   }

   /**
    * save entry
    *
    * @return int
   */
   function saveEntry()
   {
      $app = JFactory::getApplication();
      $user = JFactory::getUser();
      $this->_header = JText::_( 'COM_RIALTO_ENTRY_SAVED' );

      // redirect link
      $redirectLink = JRoute::_( "index.php?option=com_rialto&view=index");

      // check if user is logged in - maybe session has timed out
      if ($user->guest) {
         // if user is not logged in, kick him back to index page
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_SAVED_SESSION' ), "message");
      }

      $user_id        = $user->id;
      $input = JFactory::getApplication()->input;

      $flag_commercial = $input->getInt( 'flag_commercial', 0);

      $category_id    = $input->getInt( 'categoryselectbox', 0);
      $label_id       = $input->getInt( 'labelselectbox', 0);

      $firstname      = $input->getString( 'firstname', '', 'POST');
      $lastname       = $input->getString( 'lastname', '', 'POST');
      $company        = $input->getString( 'company', '', 'POST');

      $street         = $input->getString( 'street', '', 'POST');
      $zip            = $input->getString( 'zip', '', 'POST');
      $city           = $input->getString( 'city', '', 'POST');
      $statename      = $input->getString( 'state', '', 'POST');
      $country        = $input->getString( 'country', '', 'POST');

      $phone          = $input->getString( 'phone', '', 'POST');
      $mobile         = $input->getString( 'mobile', '', 'POST');
      $email          = $input->getString( 'email', '', 'POST');
      $web            = $input->getString( 'web', '', 'POST');

      $title          = $input->getString( 'entryTitle', '', 'POST', 'RAW');
      $title          = substr( strip_tags( $title), 0, 255);

      // create alias for SEF URL
      jimport( 'joomla.filter.output' );

      $alias          = $title;
      $alias          = JFilterOutput::stringURLSafe( $alias);

      $description    = $input->getString( 'entryText', '', 'POST', 'RAW');
      $description    = strip_tags( $description);

      $condition      = $input->getString( 'condition', '', 'POST');
      $price          = $input->getString( 'price', '', 'POST');

      // get parameters
      $params = JComponentHelper::getParams('com_rialto');
      $state = $params->get('def_published', '0');
      // $state = 1;

      $video1         = $input->getString( 'video1', '', 'POST');
      $video2         = $input->getString( 'video2', '', 'POST');
      $video3         = $input->getString( 'video3', '', 'POST');

      $vtype1         = $input->getString( 'vtype1', '1', 'POST');
      $vtype2         = $input->getString( 'vtype2', '1', 'POST');
      $vtype3         = $input->getString( 'vtype3', '1', 'POST');

      // Handle language
      $lang           = $input->get('languageselectbox');
      $dlang          = JFactory::getLanguage()->getTag();
      if ( empty ($lang) )
          $lang = $dlang;

      // Check each of the video entries to see that they are valid. Let the user know if not.
      if ( $video1 != "" ) {
         $check = RialtoFrontendHelper::checkRemoteFile($video1, $vtype1);
         if ( ! $check ) {
            $app->enqueueMessage(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG2',$video1), 'error');  // Log an error.
            $video1 = null;
            $vtype1 = 1;
         }
      }

      if ( $video2 != "" ) {
         $check = RialtoFrontendHelper::checkRemoteFile($video2, $vtype2);
         if ( ! $check ) {
            $app->enqueueMessage(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG2',$video2), 'error');  // Log an error.
            $video2 = null;
            $vtype2 = 1;
         }
      }

      if ( $video3 != "" ) {
         $check = RialtoFrontendHelper::checkRemoteFile($video3, $vtype3);
         if ( ! $check ) {
            $app->enqueueMessage(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG2',$video3), 'error');  // Log an error.
            $video3 = null;
            $vtype3 = 1;
         }
      }

      $db = $this->getDBO();
      $sql = "INSERT INTO ".$db->quoteName( '#__rialto_entries') .
               " ( `category_id`, `label_id`, `user_id`, `firstname`, `lastname`, `company`, `street`, `zip`, `city`, `statename`, `country`, " .
               " `phone`, `mobile`, `email`, `web`, `title`, `alias`, `description`, `condition`, `price`, `flag_commercial`, `state`, " .
               " `language`, `video1`, `vtype1`, `video2`, `vtype2`, `video3`, `vtype3` ) " .
               " VALUES ( " .
               $db->Quote( $category_id) . "," .
               $db->Quote( $label_id) . "," .
               $db->Quote( $user_id) . "," .
               $db->Quote( $firstname) . "," .
               $db->Quote( $lastname) . "," .
               $db->Quote( $company) . "," .
               $db->Quote( $street) . "," .
               $db->Quote( $zip) . "," .
               $db->Quote( $city) . "," .
               $db->Quote( $statename) . "," .
               $db->Quote( $country) . "," .
               $db->Quote( $phone) . "," .
               $db->Quote( $mobile) . "," .
               $db->Quote( $email) . "," .
               $db->Quote( $web) . "," .
               $db->Quote( $title) . "," .
               $db->Quote( $alias) . "," .
               $db->Quote( $description) . "," .
               $db->Quote( $condition) . "," .
               $db->Quote( $price) . "," .
               $db->Quote( $flag_commercial) . "," .
               $db->Quote( $state) . "," .
               $db->Quote( $lang) . "," .
               $db->Quote( $video1) . "," .
               $db->Quote( $vtype1) . "," .
               $db->Quote( $video2) . "," .
               $db->Quote( $vtype2) . "," .
               $db->Quote( $video3) . "," .
               $db->Quote( $vtype3) . ")";
      $db->setQuery( $sql);
      $result = $db->execute();

      if ( $result) { // insert went fine
         // 1. get last_insert_id
         $db->setQuery( "SELECT LAST_INSERT_ID() FROM ".$db->quoteName( '#__rialto_entries'));
         $entry_id = $db->loadResult();

         // 2. Add any tags that may have been specified.
         // This is a kludge until such time as we change the new entry to use the form.
         $jtags = $input->get('jform', null, null);
         $tags = $jtags['tags'];

         if ( ! empty($tags) ) {
            // Easier to use Observer to load table object and let it do the heavy work.
            $table = JTable::getInstance('RialtoEntry', 'Table', array());
            $table->load($entry_id);
            $tagsObserver = $table->getObserverOfClass('JTableObserverTags');
            $tagsObserver->onBeforeStore(true, false);  //arguments does not matter here
            $tagsObserver->setNewTags($tags, true); //array of tag IDs
         }

         // 3. upload images to id folder
         // get folder name
         $rootDir = JPATH_ROOT;

         if (isset( $_FILES['image1']) and !$_FILES['image1']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image1", $rootDir, $db, 1);
         }

         if (isset( $_FILES['image2']) and !$_FILES['image2']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image2", $rootDir, $db, 2);
         }

         if (isset( $_FILES['image3']) and !$_FILES['image3']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image3", $rootDir, $db, 3);
         }

         if (isset( $_FILES['image4']) and !$_FILES['image4']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image4", $rootDir, $db, 4);
         }

         if (isset( $_FILES['image5']) and !$_FILES['image5']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image5", $rootDir, $db, 5);
         }

         if (isset( $_FILES['image6']) and !$_FILES['image6']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image6", $rootDir, $db, 6);
         }

         if (isset( $_FILES['image7']) and !$_FILES['image7']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image7", $rootDir, $db, 7);
         }

         if (isset( $_FILES['image8']) and !$_FILES['image8']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image8", $rootDir, $db, 8);
         }

         if (isset( $_FILES['image9']) and !$_FILES['image9']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image9", $rootDir, $db, 9);
         }

         if (isset( $_FILES['image10']) and !$_FILES['image10']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image10", $rootDir, $db, 10);
         }

         $query  = "SELECT CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END ";
         $query .= ' FROM #__rialto_categories ';
         $query .= ' WHERE id='.$category_id;
         $db->setQuery( $query);
         $cslug = $db->loadResult();

         $sql =  "SELECT alias FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($entry_id);
         $db->setQuery( $sql );
         $alias = $db->loadResult();
         $eslug = $entry_id.':'.$alias;
         $redirectLink = JRoute::_('index.php?option=com_rialto&view=entry&catid='.$cslug.'&entry='.$eslug);

         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_BEEN_SAVED' ), "notice");
      } else {
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_SAVED_ERROR' ), "message");
      }

       return 0; // save OK
   }

   /**
    * update entry
    *
    * This is not used in 1.2.0 since we replaced it with the JForm alternative which is easier to maintain and use.
    * Retained until we have fully moved to using JForm.
    *
    * @return int
   */
   function updateEntry()
   {
      $app = JFactory::getApplication();
      $user = JFactory::getUser();
      $this->_header = JText::_( 'COM_RIALTO_ENTRY_UPDATED' );

      // redirect link
      $redirectLink = JRoute::_( "index.php?option=com_rialto&view=index");

      // check if user is logged in - maybe session has timed out
      if ($user->guest) {
         // if user is not logged in, kick him back to index page
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_UPDATED_SESSION' ), "message");
      }

      $input          = JFactory::getApplication()->input;
      $id             = $input->getInt( 'entry', 0);

      $category_id    = $input->getInt( 'categoryselectbox', 0);
      $label_id       = $input->getInt( 'labelselectbox', 0);

      $firstname      = $input->getString( 'firstname', '', 'POST');
      $lastname       = $input->getString( 'lastname', '', 'POST');
      $company        = $input->getString( 'company', '', 'POST');

      $street         = $input->getString( 'street', '', 'POST');
      $zip            = $input->getString( 'zip', '', 'POST');
      $city           = $input->getString( 'city', '', 'POST');
      $statename      = $input->getString( 'state', '', 'POST');
      $country        = $input->getString( 'country', '', 'POST');

      $phone          = $input->getString( 'phone', '', 'POST');
      $mobile         = $input->getString( 'mobile', '', 'POST');
      $email          = $input->getString( 'email', '', 'POST');
      $web            = $input->getString( 'web', '', 'POST');

      $video1         = $input->getString( 'video1', '', 'POST');
      $video2         = $input->getString( 'video2', '', 'POST');
      $video3         = $input->getString( 'video3', '', 'POST');

      $title          = $input->getString( 'entryTitle', '', 'POST', 'RAW');
      $title          = substr( strip_tags( $title), 0, 255);

      // create alias for SEF URL
      jimport( 'joomla.filter.output' );

      $alias          = $title;
      $alias          = JFilterOutput::stringURLSafe( $alias);

      $date_lastmodified = gmdate('Y-m-d H:i:s');

      $description           = $input->getString( 'entryText', '', 'POST', 'RAW');
      $description           = strip_tags( $description);

      $condition      = $input->getString( 'condition', '', 'POST');
      $price          = $input->getString( 'price', '', 'POST');

      $cb_image1      = $input->getString( 'cb_image1', '', 'POST');
      $cb_image2      = $input->getString( 'cb_image2', '', 'POST');
      $cb_image3      = $input->getString( 'cb_image3', '', 'POST');
      $cb_image4      = $input->getString( 'cb_image4', '', 'POST');
      $cb_image5      = $input->getString( 'cb_image5', '', 'POST');
      $cb_image6      = $input->getString( 'cb_image6', '', 'POST');
      $cb_image7      = $input->getString( 'cb_image7', '', 'POST');
      $cb_image8      = $input->getString( 'cb_image8', '', 'POST');
      $cb_image9      = $input->getString( 'cb_image9', '', 'POST');
      $cb_image10     = $input->getString( 'cb_image10', '', 'POST');

      $vtype1         = $input->getString( 'vtype1', '1', 'POST');
      $vtype2         = $input->getString( 'vtype2', '1', 'POST');
      $vtype3         = $input->getString( 'vtype3', '1', 'POST');

      // If we are to allow a language change we need to also modify the category if it changes.
      // Handle language
      $lang           = $input->get('languageselectbox');
      $dlang          = JFactory::getLanguage()->getTag();
      if ( empty ($lang) )
         $lang = $dlang;

      // Check each of the video entries to see that they are valid.
      if ( $video1 != "" ) {
         $check = RialtoFrontendHelper::checkRemoteFile($video1, $vtype1, $id);
         if ( ! $check ) {
            // Let the user know about it.
            $app->enqueueMessage(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG2',$video1), 'error');  // Log an error.
            $video1 = null;
            $vtype1 = 1;
         }
      }

      if ( $video2 != "" ) {
         $check = RialtoFrontendHelper::checkRemoteFile($video2, $vtype2, $id);
         if ( ! $check ) {
            // Let the user know about it.
            $app->enqueueMessage(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG2',$video2), 'error');  // Log an error.
            $video2 = null;
            $vtype2 = 1;
         }
      }

      if ( $video3 != "" ) {
         $check = RialtoFrontendHelper::checkRemoteFile($video3, $vtype3, $id);
         if ( ! $check ) {
            // Let the user know about it.
            $app->enqueueMessage(JText::sprintf('COM_RIALTO_VIDEO_ERROR_MSG2',$video3), 'error');  // Log an error.
            $video3 = null;
            $vtype3 = 1;
         }
      }

      // get folder name
      $rootDir = JPATH_ROOT;

      $db = $this->getDBO();
      // update db
      $sql = "UPDATE ".$db->quoteName( '#__rialto_entries') .
               " SET" .
               " `category_id` = " . $db->Quote( $category_id) . "," .
               " `label_id` = " . $db->Quote( $label_id) . "," .
//               " `language` = " . $db->Quote( $lang) . "," .
               " `firstname` = " . $db->Quote( $firstname) . "," .
               " `lastname` = " . $db->Quote( $lastname) . "," .
               " `company` = " . $db->Quote( $company) . "," .
               " `street` = " . $db->Quote( $street) . "," .
               " `zip` = " . $db->Quote( $zip) . "," .
               " `city` = " . $db->Quote( $city) . "," .
               " `statename` = " . $db->Quote( $statename) . "," .
               " `country` = " . $db->Quote( $country) . "," .
               " `phone` = " . $db->Quote( $phone) . "," .
               " `mobile` = " . $db->Quote( $mobile) . "," .
               " `email` = " . $db->Quote( $email) . "," .
               " `web` = " . $db->Quote( $web) . "," .
               " `title` = " . $db->Quote( $title) . "," .
               " `alias` = " . $db->Quote( $alias) . "," .
               " `description` = " . $db->Quote( $description) . "," .
               " `condition` = " . $db->Quote( $condition) . "," .
               " `price` = " . $db->Quote( $price) . "," .
               " `video1` = " . $db->Quote( $video1) . "," .
               " `vtype1` = " . $db->Quote( $vtype1) . "," .
               " `video2` = " . $db->Quote( $video2) . "," .
               " `vtype2` = " . $db->Quote( $vtype2) . "," .
               " `video3` = " . $db->Quote( $video3) . "," .
               " `vtype3` = " . $db->Quote( $vtype3) . "," .
               " `date_lastmodified` = " . $db->Quote( $date_lastmodified) .
               " WHERE id = " . $db->Quote($id);

      $db->setQuery( $sql);
      $result = $db->execute();

      // check if there are images to delete
      if ( $cb_image1  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image1", $rootDir, $db, 1);
      }

      if ( $cb_image2  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image2", $rootDir, $db, 2);
      }

      if ( $cb_image3  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image3", $rootDir, $db, 4);
      }

      if ( $cb_image4  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image4", $rootDir, $db, 4);
      }

      if ( $cb_image5  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image5", $rootDir, $db, 5);
      }

      if ( $cb_image6  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image6", $rootDir, $db, 6);
      }

      if ( $cb_image7  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image7", $rootDir, $db, 7);
      }

      if ( $cb_image8  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image8", $rootDir, $db, 8);
      }

      if ( $cb_image9  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image9", $rootDir, $db, 9);
      }

      if ( $cb_image10  == "delete") {
         RialtoFrontendHelper::del_image( $id, "image10", $rootDir, $db, 10);
      }

      if ( $result) { // update went fine
         $entry_id = $id;

         // upload images to id folder
         if (isset( $_FILES['image1']) and !$_FILES['image1']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image1", $rootDir, $db, 1);
         }

         if (isset( $_FILES['image2']) and !$_FILES['image2']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image2", $rootDir, $db, 2);
         }

         if (isset( $_FILES['image3']) and !$_FILES['image3']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image3", $rootDir, $db, 3);
         }

         if (isset( $_FILES['image4']) and !$_FILES['image4']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image4", $rootDir, $db, 4);
         }

         if (isset( $_FILES['image5']) and !$_FILES['image5']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image5", $rootDir, $db, 5);
         }

         if (isset( $_FILES['image6']) and !$_FILES['image6']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image6", $rootDir, $db, 6);
         }

         if (isset( $_FILES['image7']) and !$_FILES['image7']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image7", $rootDir, $db, 7);
         }

         if (isset( $_FILES['image8']) and !$_FILES['image8']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image8", $rootDir, $db, 8);
         }

         if (isset( $_FILES['image9']) and !$_FILES['image9']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image9", $rootDir, $db, 9);
         }

         if (isset( $_FILES['image10']) and !$_FILES['image10']['error'] ) {
            RialtoFrontendHelper::add_image( $entry_id, "image10", $rootDir, $db, 10);
         }

         $query  = "SELECT CASE WHEN CHAR_LENGTH(alias) THEN CONCAT_WS(':', id, alias) ELSE id END ";
         $query .= ' FROM #__rialto_categories ';
         $query .= ' WHERE id='.$category_id;
         $db->setQuery( $query);
         $cslug = $db->loadResult();
         $eslug = $id.':'.$alias;
         $redirectLink = JRoute::_('index.php?option=com_rialto&view=entry&catid='.$cslug.'&entry='.$eslug);

         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_BEEN_UPDATED' ), "notice");
      }  else {
         $app->redirect( $redirectLink, JText::_( 'COM_RIALTO_ENTRY_HAS_NOT_BEEN_UPDATED_ERROR' ), "message");
      }

      return 0; // update OK
   }

   /**
    * Method to build the query.
    *
    * Returns the query
    * @param $id
    * @return string The query to be used to retrieve the rows from the database
    */
   private function _buildQuery($id)
   {
      // Create a new query object.
      $db      = $this->getDbo();
      $query   = $db->getQuery(true);
      $query->select(
         $this->getState(
            'list.select',
            't1.*'
         )
      );

      $query->from('#__rialto_entries AS t1');

      // Join over the categories table.
      $query->select('t2.title AS cat_name, t2.id AS cat_id, t2.description AS cat_description, t2.image AS cat_image, t2.path AS cat_path, t2.level AS cat_level');
      $query->select('CASE WHEN CHAR_LENGTH(t2.alias) THEN CONCAT_WS(\':\', t2.id, t2.alias) ELSE t2.id END as cat_slug');
      $query->join('LEFT', '#__rialto_categories AS t2 ON t2.id = t1.category_id');
      $query->select('t3.image AS label_image, t3.name AS label_name');
      $query->join('LEFT', '#__rialto_labels AS t3 ON t3.id = t1.label_id');
      $query->select('t4.username AS user_name');
      $query->join('LEFT', '#__users AS t4 ON t4.id = t1.user_id');

      $query->where('t1.id = ' . $db->Quote($id));
      return $query;
   }

   /**
    * Retrieves the data
    * @return array Array of objects containing the data from the database
    *
    * @param null $pk
    * @return object
    * @throws Exception
    */
   public function getItem ($pk = null)
   {
      // Initialise variables.
//      $pk = (!empty($pk)) ? $pk : (int) $this->getState('itissues.id');
      // $pk = (!empty($pk)) ? $pk : (int) JFactory::getApplication()->input->get('id');
      // $pk = (!empty($pk)) ? $pk : (int) JFactory::getApplication()->input->get('entry');
      $pk = (!empty($pk)) ? $pk : (int) $this->_id;

      $pk = (!empty($pk)) ? $pk : (int) JFactory::getApplication()->input->get('id');

      if ($this->_item === null) {
         $this->_item = array();
      }

      if (!isset($this->_item[$pk])) {
         try {
            $db      = $this->getDbo();
            $query   = $this->_buildQuery($pk);
            $db->setQuery($query);

            $data = $db->loadObject();

            if ($error = $db->getErrorMsg()) {
               throw new Exception($error);
            }

            if (empty($data)) {
               //Let view handle entry not found.
               return null;
            }

            $this->_item[$pk] = $data;
         }

         catch (JException $e)
         {
            if ($e->getCode() == 404) {
               // Need to go through the error handler to allow Redirect to work.
               JError::raiseError(404, $e->getMessage());
               // Let Joomla catches this exception and displays 404 page.
               // throw new Exception($e->getMessage(), 404);
            } else {
               $this->setError($e);
               // JFactory::getApplication()->enqueueMessage($e->getMessage(), 'warning');
               // return false;
               $this->_item[$pk] = false;
            }
         }
      }

      $this->_item[$pk]->tags = new JHelperTags;
      $this->_item[$pk]->tags->getTagIds($this->_item[$pk]->id, 'com_rialto.entry');

      $assoc = JLanguageAssociations::isEnabled();
      if ($assoc) {
         $this->_item[$pk]->associations = array();
         if ($this->_item[$pk] != null) {
            // Our table has an alias and a category id but we are not using them currently so we must specify null
            $associations = JLanguageAssociations::getAssociations('com_rialto', '#__rialto_entries', 'com_rialto.entry', $this->_item[$pk]->id, 'id', null, null);

            foreach ($associations as $tag => $association) {
               $this->_item[$pk]->associations[$tag] = $association->id;
            }
         }
      }
      return $this->_item[$pk];
   }

   /**
    * Method to get the id of this entry
    *
    * @access public
    * @return integer
    */
   function getId()
   {
      return $this->_id;
   }


   /**
    * Method to get the user id of this entry
    *
    * @access public
    * @return integer
    */
   function getUserid()
   {
      if (empty($this->_user_id)) {
         $db = $this->getDBO();
         $sql = "SELECT user_id FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($this->_id);
         $db->setQuery( $sql);
         $this->_user_id = $db->loadResult();
      }

      return $this->_user_id;
   }

   /**
    * Method to get the category id of this entry
    *
    * @access public
    * @return integer
    */
   function getCatid()
   {
      if (empty($this->_cat_id)) {
         $db = $this->getDBO();
         $sql = "SELECT category_id FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($this->_id);
         $db->setQuery( $sql);
         $this->_cat_id = $db->loadResult();
      }
      return $this->_cat_id;
   }


   /**
    * Method to get the label id of this entry
    *
    * @access public
    * @return integer
    */
   function getLabelid()
   {
      if (empty($this->_label_id)) {
         $db = $this->getDBO();
         $sql = "SELECT label_id FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($this->_id);
         $db->setQuery( $sql);
         $this->_label_id = $db->loadResult();
      }
      return $this->_label_id;
   }

   /**
    * Method to get the label image with the given id
    *
    * @access public
    * @param $label_id
    * @return int
    */
   function getLabelimage($label_id)
   {
      if (!empty($label_id)) {
         $db = $this->getDBO();
         // $db         = JFactory::getDBO();
         $sql = "SELECT image FROM ".$db->quoteName('#__rialto_labels')." WHERE id=" . $db->Quote($label_id);
         $db->setQuery( $sql);
         $this->_label_image = $db->loadResult();
      }
      return $this->_label_image;
   }

   /**
    * Method to get the firstname of this entry
    *
    * @access public
    * @return String
    */
   function getFirstname()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_firstname)) {
            $db = $this->getDBO();
            $sql = "SELECT firstname FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_firstname = $db->loadResult();
         }
      }
      return $this->_firstname;
   }


   /**
    * Method to get the lastname of this entry
    *
    * @access public
    * @return String
    */
   function getLastname()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_lastname)) {
            $db = $this->getDBO();
            $sql = "SELECT lastname FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_lastname = $db->loadResult();
         }
      }

      return $this->_lastname;
   }


   /**
    * Method to get the company of this entry
    *
    * @access public
    * @return String
    */
   function getCompany()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_company)) {
            $db = $this->getDBO();
            $sql = "SELECT company FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_company = $db->loadResult();
         }
      }
      return $this->_company;
   }

   /**
    * Method to get the street of this entry
    *
    * @access public
    * @return String
    */
   function getStreet()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_street)) {
            $db = $this->getDBO();
            $sql = "SELECT street FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_street = $db->loadResult();
         }
      }
      return $this->_street;
   }


   /**
    * Method to get the zip of this entry
    *
    * @access public
    * @return String
    */
   function getZip()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_zip)) {
            $db = $this->getDBO();
            $sql = "SELECT zip FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $_id;
            $db->setQuery( $sql);
            $this->_zip = $db->loadResult();
         }
      }

      return $this->_zip;
   }


   /**
    * Method to get the city of this entry
    *
    * @access public
    * @return String
    */
   function getCity()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_city)) {
            $db = $this->getDBO();
            $sql = "SELECT city FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_city = $db->loadResult();
         }
      }

      return $this->_city;
   }


   /**
    * Method to get the state of this entry
    *
    * @access public
    * @return String
    */
   function getEntryState()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_entryState)) {
            $db = $this->getDBO();
            $sql = "SELECT statename FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_entryState = $db->loadResult();
         }
      }

      return $this->_entryState;
   }


   /**
    * Method to get the country of this entry
    *
    * @access public
    * @return String
    */
   function getCountry()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_country)) {
            $db = $this->getDBO();
            $sql = "SELECT country FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $_id;
            $db->setQuery( $sql);
            $this->_country = $db->loadResult();
         }
      }

      return $this->_country;
   }


   /**
    * Method to get the phone of this entry
    *
    * @access public
    * @return String
    */
   function getPhone()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_phone)) {
            $db = $this->getDBO();
            $sql = "SELECT phone FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_phone = $db->loadResult();
         }
      }

      return $this->_phone;
   }


   /**
    * Method to get the mobile of this entry
    *
    * @access public
    * @return String
    */
   function getMobile()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_mobile)) {
            $db = $this->getDBO();
            $sql = "SELECT mobile FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_mobile = $db->loadResult();
         }
      }
      return $this->_mobile;
   }


   /**
    * Method to get the email of this entry
    *
    * @access public
    * @return String
    */
   function getEmail()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_email)) {
            $db = $this->getDBO();
            $sql = "SELECT email FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_email = $db->loadResult();
         }
      }
      return $this->_email;
   }


   /**
    * Method to get the web of this entry
    *
    * @access public
    * @return String
    */
   function getWeb()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_web)) {
            $db = $this->getDBO();
            $sql = "SELECT web FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_web = $db->loadResult();
         }
      }
      return $this->_web;
   }


   /**
    * Method to get the title of this entry
    *
    * @access public
    * @return String
    */
   function getTitle()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_title)) {
            $db = $this->getDBO();
            $sql = "SELECT title FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_title = $db->loadResult();
         }
      }
      return $this->_title;
   }


   /**
    * Method to get the text of this entry
    *
    * @access public
    * @return String
    */
   function getDescription()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_description)) {
            $db = $this->getDBO();
            $sql = "SELECT description FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_description = $db->loadResult();
         }
      }
      return $this->_description;
   }

   /**
    * Method to get the text of this entry
    *
    * @access public
    * @return String
    */
/*
   function getText()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_description)) {
            $db = $this->getDBO();
            $sql = "SELECT description FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_description = $db->loadResult();
         }
      }
      return $this->_description;
   }
*/

   /**
    * Method to get the condition of this entry
    *
    * @access public
    * @return String
    */
   function getEntryCondition()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_entryCondition)) {
            $db = $this->getDBO();
            $sql = "SELECT " . $db->quoteName('condition');
            $sql .= " FROM " . $db->quoteName('#__rialto_entries');
            $sql .= " WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_entryCondition = $db->loadResult();
         }
      }
      return $this->_entryCondition;
   }


   /**
    * Method to get the price of this entry
    *
    * @access public
    * @return String
    */
   function getPrice()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_price)) {
            $db = $this->getDBO();
            $sql = "SELECT price FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_price = $db->loadResult();
         }
      }
      return $this->_price;
   }


   /**
    * Method to get image 1 of this entry
    *
    * @access public
    * @return String
    */
   function getImage1()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image1)) {
            $db = $this->getDBO();
            $sql = "SELECT image1 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image1 = $db->loadResult();
         }
      }
      return $this->_image1;
   }

   /**
    * Method to get image 2 of this entry
    *
    * @access public
    * @return String
    */
   function getImage2()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image2)) {
            $db = $this->getDBO();
            $sql = "SELECT image2 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image2 = $db->loadResult();
         }
      }
      return $this->_image2;
   }

   /**
    * Method to get image 3 of this entry
    *
    * @access public
    * @return String
    */
   function getImage3()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image3)) {
            $db = $this->getDBO();
            $sql = "SELECT image3 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image3 = $db->loadResult();
         }
      }
      return $this->_image3;
   }

   /**
    * Method to get image 4 of this entry
    *
    * @access public
    * @return String
    */
   function getImage4()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image4)) {
            $db = $this->getDBO();
            $sql = "SELECT image4 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image4 = $db->loadResult();
         }
      }
      return $this->_image4;
   }

   /**
    * Method to get image 5 of this entry
    *
    * @access public
    * @return String
    */
   function getImage5()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image5)) {
            $db = $this->getDBO();
            $sql = "SELECT image5 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image5 = $db->loadResult();
         }
      }
      return $this->_image5;
   }

   /**
    * Method to get image 6 of this entry
    *
    * @access public
    * @return String
    */
   function getImage6()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image6)) {
            $db = $this->getDBO();
            $sql = "SELECT image6 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $_id;
            $db->setQuery( $sql);
            $this->_image6 = $db->loadResult();
         }
      }
      return $this->_image6;
   }

   /**
    * Method to get image 7 of this entry
    *
    * @access public
    * @return String
    */
   function getImage7()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image7)) {
            $db = $this->getDBO();
            $sql = "SELECT image7 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image7 = $db->loadResult();
         }
      }
      return $this->_image7;
   }

   /**
    * Method to get image 8 of this entry
    *
    * @access public
    * @return String
    */
   function getImage8()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image8)) {
            $db = $this->getDBO();
            $sql = "SELECT image8 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image8 = $db->loadResult();
         }
      }
      return $this->_image8;
   }

   /**
    * Method to get image 9 of this entry
    *
    * @access public
    * @return String
    */
   function getImage9()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image9)) {
            $db = $this->getDBO();
            $sql = "SELECT image9 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image9 = $db->loadResult();
         }
      }
      return $this->_image9;
   }

   /**
    * Method to get image 10 of this entry
    *
    * @access public
    * @return String
    */
   function getImage10()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_image10)) {
            $db = $this->getDBO();
            $sql = "SELECT image10 FROM ".$db->quoteName('#__rialto_entries')." WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_image10 = $db->loadResult();
         }
      }
      return $this->_image10;
   }


   /**
    * Method to get video 1 of this entry
    *
    * @access public
    * @return String
    */
   function getVideo1()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_video1)) {
            $db = $this->getDBO();
            $sql = "SELECT video1 FROM ".$db->quoteName('#__rialto_entries');
            $sql .= " WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_video1 = $db->loadResult();
         }
      }
      return $this->_video1;
   }

   /**
    * Method to get video 2 of this entry
    *
    * @access public
    * @return String
    */
   function getVideo2()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_video2)) {
            $db = $this->getDBO();
            $sql = "SELECT video1 FROM ".$db->quoteName('#__rialto_entries');
            $sql .= " WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_video2 = $db->loadResult();
         }
      }
      return $this->_video2;
   }

   /**
    * Method to get video 3 of this entry
    *
    * @access public
    * @return String
    */
   function getVideo3()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_video3)) {
            $db = $this->getDBO();
            $sql = "SELECT video3 FROM ".$db->quoteName('#__rialto_entries');
            $sql .= " WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_video3 = $db->loadResult();
         }
      }
      return $this->_video3;
   }

   /**
    * Method to get video 1 type  of this entry
    *
    * @access public
    * @return String
    */
   function getVtype1()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_vtype1)) {
            $db = $this->getDBO();
            $sql = "SELECT vtype1 FROM ".$db->quoteName('#__rialto_entries');
            $sql .= " WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_vtype1 = $db->loadResult();
         }
      }
      return $this->_vtype1;
   }

   /**
    * Method to get video 2 type  of this entry
    *
    * @access public
    * @return String
    */
   function getVtype2()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_vtype2)) {
            $db = $this->getDBO();
            $sql = "SELECT vtype1 FROM ".$db->quoteName('#__rialto_entries');
            $sql .= " WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_vtype2 = $db->loadResult();
         }
      }
      return $this->_vtype2;
   }

   /**
    * Method to get video 3 type  of this entry
    *
    * @access public
    * @return String
    */
   function getVtype3()
   {
      $_id = JFactory::getApplication()->input->getInt('entry', 0);

      if ( $_id <> 0) {
         if (empty($this->_vtype3)) {
            $db = $this->getDBO();
            $sql = "SELECT vtype3 FROM ".$db->quoteName('#__rialto_entries');
            $sql .= " WHERE id=" . $db->Quote($_id);
            $db->setQuery( $sql);
            $this->_vtype3 = $db->loadResult();
         }
      }
      return $this->_vtype3;
   }

    /**
     * Method to get the published state of this entry
     *
     * @access public
     * @return integer
     */
    function getPublished()
    {
        if (empty($this->_published)) {
           $db = $this->getDBO();
           $sql = "SELECT state FROM ".$db->quoteName('#__rialto_entries');
           $sql .= " WHERE id=" . $db->Quote($this->_id);
           $db->setQuery( $sql);
           $this->_published = $db->loadResult();
        }
        return $this->_published;
    }


    /**
     * Method to get the private/commercial state of this entry
     *
     * @access public
     * @return integer
     */
    function getFlagCommercial()
    {
        if (empty($this->_flag_commercial)) {
           $db = $this->getDBO();
           $sql = "SELECT flag_commercial FROM ".$db->quoteName('#__rialto_entries');
           $sql .= " WHERE id=" . $db->Quote($this->_id);
           $db->setQuery( $sql);
           $this->_flag_commercial = $db->loadResult();
        }
        return $this->_flag_commercial;
    }


    /**
     * Method to get the expired state of this entry
     *
     * @access public
     * @return integer
     */
    function getExpired()
    {
        if (empty($this->_expired)) {
            $db = $this->getDBO();
            $sql = "SELECT expired FROM ".$db->quoteName('#__rialto_entries');
            $sql .= " WHERE id=" . $db->Quote($this->_id);
            $db->setQuery( $sql);
            $this->_expired = $db->loadResult();
        }
        return $this->_expired;
    }


   /**
    * Method to get the id of this category
    *
    * @access public
    * @return integer
    */
   function getCategoryId()
   {
      $this->_categoryId = JFactory::getApplication()->input->getInt('catid', 0);
      return $this->_categoryId;
   }


   /**
    * Method to get the slug of this category
    *
    * @access public
    * @return string
    */
   function getCategorySlug()
   {
      $this->_categoryId = JFactory::getApplication()->input->getInt('catid', 0);
      return $this->_categoryId;
   }


   /**
    * Method to get the name of this category
    *
    * @access public
    * @return String
    */
   function getCategoryName()
   {
      if ( empty( $this->_categoryName)) {
         $_catid = JFactory::getApplication()->input->getInt('catid', 0);
         $db = $this->getDBO();

         $categoryNameQuery = "SELECT title FROM ".$db->quoteName( '#__rialto_categories');
         $categoryNameQuery .= " WHERE id=" . $db->Quote($_catid);
         $db->setQuery( $categoryNameQuery);
         $this->_categoryName = $db->loadResult();
      }
      return $this->_categoryName;
   }


    /**
     * Method to get the description of this category
     *
     * @access public
     * @return String
     */
    function getCategoryDescription()
    {
        if ( empty( $this->_categoryDescription)) {
            $_catid = JFactory::getApplication()->input->getInt('catid', 0);
            $db = $this->getDBO();
            $categoryDescriptionQuery = "SELECT description FROM ".$db->quoteName( '#__rialto_categories');
            $categoryDescriptionQuery .= " WHERE id=" . $db->Quote($_catid);
            $db->setQuery( $categoryDescriptionQuery);
            $this->_categoryDescription = $db->loadResult();
        }
        return $this->_categoryDescription;
    }


   /**
    * Method to get the image of this category
    *
    * @access public
    * @return String
    */
   function getCategoryImage()
   {
      if ( empty( $this->_categoryImage)) {
            $_catid = JFactory::getApplication()->input->getInt('catid', 0);

            $db = $this->getDBO();
            $categoryImageQuery = "SELECT image FROM ".$db->quoteName( '#__rialto_categories');
            $categoryImageQuery .= " WHERE id=" . $db->Quote($_catid);
            $db->setQuery( $categoryImageQuery);
            $this->_categoryImage = $db->loadResult();
      }
      return $this->_categoryImage;

   }

   /**
    * Method to get the page header
    *
    * @access public
    * @return String
    */
   function getHeader()
   {
      return $this->_header;
   }

   /**
    * Method to get the task
    *
    * @access public
    * @return String
    */
   function getTask()
   {
      if ( empty( $this->_task)) {
         $this->_task   = JFactory::getApplication()->input->getString( 'task', '');
      }
      return $this->_task;
   }

   /**
    * Method to get the creation date of this entry
    *
    * @access public
    * @return string
    */
   function getDateCreated()
   {
      if (empty($this->_date_created)) {
         $db = $this->getDBO();
         $sql = "SELECT DATE_FORMAT( date_created, '%d.%m.%Y') FROM ".$db->quoteName('#__rialto_entries');
         $sql .= " WHERE id=" . $db->Quote($this->_id);

         $db->setQuery( $sql);
         $this->_date_created = $db->loadResult();
      }
      return $this->_date_created;
   }

   /**
    * Method to send a message to the vendor
    *
    * @access public
    * @return String
    */
   function sendmessage()
   {
      $app = JFactory::getApplication();
      $input = $app->input;

      // get parameters
      $params = JComponentHelper::getParams('com_rialto');
      $logging = $params->get('enablelogging', '0');

      if ( $logging )
         RialtoHelperLog::dblog('Model in sendmessage', JLog::INFO);

      $id         = $input->getInt('entry', 0);
      if ( $id === 0 )
         $id         = $input->getInt('id', 0);
//      $cid        = $input->getInt('cid', 0);
      $db         = JFactory::getDBO();
      // $user       = JFactory::getUser();
      // $itemid     = $input->getInt('Itemid');

      $msg        = strip_tags($input->getString( 'contact_message', ''));
      if (empty($msg) ) {
         if ($logging)
            RialtoHelperLog::dblog(JText::_('COM_RIALTO_EMPTY_MESSAGE_MSG'), JLog::WARNING);
         $app->enqueueMessage( JText::_('COM_RIALTO_NO_MESSAGE_BODY_PROVIDED_MSG'), 'error');
         return false;
      }

      // Run spam checker on the contact message.  Mainly a check for guest users.
      $isSpam  = intval($this->_isSpam());
      if ($isSpam) {
         if ($logging)
            RialtoHelperLog::dblog(JText::_('COM_RIALTO_SPAM_DETECTED_IN_MESSAGE_MSG'), JLog::WARNING);
         return false;
      }

      // Run check against Akismet if configured unless we are an issue administrator or staff.
      $use_akismet   = $params->get('akismet_api_key','');
      if ( ! empty($use_akismet) ) {
         if ( $this->_check_akismet($input) ) {
            $app->enqueueMessage( JText::_('COM_RIALTO_AKISMET_DETECTED_SPAM'), 'error' );
         if ($logging)
            RialtoHelperLog::dblog(JText::_('COM_RIALTO_AKISMET_SPAM_DETECTED_IN_MESSAGE_MSG'), JLog::ERROR);
            return false;
         }
      }

      $query  = 'SELECT i.title, u.email, ';
      $query .= ' CASE WHEN CHAR_LENGTH(i.alias) THEN CONCAT_WS(\':\', i.id, i.alias) ELSE i.id END as eslug,';
      $query .= ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(\':\', c.id, c.alias) ELSE c.id END as cslug';
      $query .= ' FROM #__rialto_entries i , #__users u,  #__rialto_categories c';
      $query .= ' WHERE i.user_id = u.id AND i.id='.$id;
      $query .= ' AND i.category_id=c.id ';

      $db->setQuery($query);

      $ob            = $db->loadObject();
      $mailto        = $ob->email;
      if (empty($mailto)) {
         if ($logging)
            RialtoHelperLog::dblog(JText::_('COM_RIALTO_NO_RECIPIENT_EMAIL_ADDRESS_PROVIDED_MSG'), JLog::ERROR);
         return false;
      }

//      $mailfrom      = $app->getCfg( 'mailfrom' );
      $replyto       = $input->getString( 'contact_email', '');
      if (empty($replyto)) {
         if ($logging)
            RialtoHelperLog::dblog(JText::_('COM_RIALTO_NO_SENDER_EMAIL_ADDRESS_PROVIDED_MSG'), JLog::ERROR);
         return false;
      }
      if (!JMailHelper::isEmailAddress($replyto)) {
         if ($logging)
            RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_INVALID_FROM_ADDR_MSG', $replyto), JLog::ERROR);
         return false;
      }

      $replytoname   = $input->getString( 'contact_name', '');
      if (empty($replytoname)) {
         if ($logging)
            RialtoHelperLog::dblog(JText::_('COM_RIALTO_NO_SENDER_CONTACT_NAME_PROVIDED_MSG'), JLog::ERROR);
         return false;
      }
      if ($logging)
         RialtoHelperLog::dblog('Sender name: '.$replytoname, JLog::INFO);


      $replytophone   = $input->getString( 'contact_phone', '');
      if (empty($replytophone)) {
         if ($logging)
            RialtoHelperLog::dblog(JText::_('COM_RIALTO_NO_SENDER_CONTACT_PHONE_PROVIDED_MSG'), JLog::INFO);
      }
      if ($logging)
         RialtoHelperLog::dblog('Sender phone: '.$replytophone, JLog::INFO);

      // $config     = JFactory::getConfig();
      $msgprefix  = $params->get('emailMSGMessagePrefix', '');
      $msgpostfix = $params->get('emailMSGMessagePostfix', '');
      $msgsubjectprefix = $params->get('emailMSGSubject', '');

      // $fromname = $config->get('config.sitename').' - '.JURI::base();
      // $subject  = sprintf ( JText::_( 'COM_RIALTO_CONTACT_SELLER_TITLE' ), $config->get('config.sitename'));

      if (!empty($msgprefix) ) {
         $message = $msgprefix;
      } else {
         $message = "";
      }

      $subs_hdr = JText::_('COM_RIALTO_MESSAGE_CONTACT_HDR_TXT');
      if ( !empty($subs_hdr) ) $message .= $subs_hdr;

      $message .= JText::sprintf('COM_RIALTO_CONTACT_FROM_USER', $replytoname);
      $message .= JText::sprintf('COM_RIALTO_CONTACT_USER_EMAIL', $replyto);

      $message .= JText::sprintf('COM_RIALTO_CONTACT_TITLE_MSG', $ob->title);
      if (! empty($replytophone) )
         $message .= JText::sprintf('COM_RIALTO_CONTACT_PHONE_NO', $replytophone);
      $message .= JText::sprintf( 'COM_RIALTO_CONTACT_SELLER_MESSAGE', $msg);

      if (!empty($msgpostfix) )
         $message .= $msgpostfix;

      $subs_ftr = JText::_('COM_RIALTO_MESSAGE_CONTACT_FTR_TXT');
      if ( !empty($subs_ftr) ) $message .= $subs_ftr;

      if ($logging)
         RialtoHelperLog::dblog('Sender message: '.$msg, JLog::INFO);

      // JUtility::sendMail($mailfrom, $fromname, $mailto, $subject, $message, $mode=0, $cc=null, $bcc=null, $attachment=null, $replyto, $replytoname);
      // Clean the email data
      $subject = JMailHelper::cleanSubject($ob->title);
      if (! empty($msgsubjectprefix) )
         $subject = $msgsubjectprefix . $subject;
      $body    = JMailHelper::cleanBody($message);
      $fromadr = JMailHelper::cleanAddress($replyto);

      $sender = "Rialto";

      //setup the mailer & create message
      $mail = JFactory::getMailer();
      $mail->isHTML(true);
      $mail->Encoding = 'base64';
      $mail->addRecipient($mailto);
      //$mail->setSender($sender);
      $mail->setSender(array($fromadr, $sender));
      // $mail->setFrom($fromadr,$sender,false);

      // if (!empty($replyto)) $mail->addReplyTo(array($replyto, $replytoname));
      if (!empty($replyto)) $mail->addReplyTo($replyto, $replytoname);
      $mail->setSubject($subject);
      $mail->setBody($body);

      try {
         $mail->Send();
         if ($logging)
            RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_MESSAGE_SENT', $mailto), JLog::INFO);
         $app->enqueueMessage( JText::_('COM_RIALTO_MESSAGE_SENT'));
      }
      catch (Exception $e) {
         RialtoHelperLog::dblog(JText::sprintf('COM_RIALTO_MESSAGE_SENDING_PROBLEM', $mailto), JLog::ERROR);
         RialtoHelperLog::dblog(__METHOD__.' -> '.$e->getTrace()[1]['function'].': '.$e->getMessage(), JLog::ERROR);
         return false;
      }
      unset($mail);

      // $link = JRoute::_('index.php?option=com_rialto&view=entry&catid=' . $ob->cslug . '&entry=' . $ob->eslug . '&Itemid=' . $itemid);

      return true;
   }
   /**
    * Method to perform internal check for configured spam
    *
    */
   private function _isSpam()
   {
      $this->_params = JComponentHelper::getParams( 'com_rialto' );
      $user = JFactory::getUser();
      //filter out logged in users
      if (! $user->guest) { return 0; }
      $input = JFactory::getApplication()->input;

      //filters first
      $ipList = explode("\r\n",$this->_params->get('ip_list',''));
      $emailList = explode("\r\n",$this->_params->get('email_list',''));

      if (in_array($_SERVER['REMOTE_ADDR'], $ipList)) { return 1; }

      if ($input->getString('contact_email') && in_array($input->getString('contact_email'), $emailList)) { return 1; }

      //OK, filters have passed. Now check link count & words
      $wordList = explode("\r\n",$this->_params->get('word_list',''));
      if (count($wordList) > 1) {
         foreach ($wordList as $word) {
            if (stristr($input->getString('contact_message'), $word)) { return 1; }
          }
      }

      //how many urls - This is a basic form of caching.
      if (substr_count($input->getString('contact_message'), 'http://')   >= $this->_params->get('link_count',3))   { return 1; }

      return 0;
   }

   /**
    *
    * Method to check whether the included text is spam using Akismet
    * Details from akismet.com
    *
    * Input is an array with the text in the comment_content element.  Other fields should get populated in the _getAkismet method.
    *
    * $data = array('blog' => 'http://yourblogdomainname.com',
    *   'user_ip' => '127.0.0.1',
    *   'user_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko/20100115 Firefox/3.6',
    *   'referrer' => 'http://www.google.com',
    *   'permalink' => 'http://yourblogdomainname.com/blog/post=1',
    *   'comment_type' => 'comment',
    *   'comment_author' => 'admin',
    *   'comment_author_email' => 'test@test.com',
    *   'comment_author_url' => 'http://www.CheckOutMyCoolSite.com',
    *   'comment_content' => 'It means a lot that you would take the time to review our software.  Thanks again.');
    *
    * @param $data
    * @return bool
    */
   public function _check_akismet($data)
   {
      try {
         if ($this->_getAkismet($data)->isCommentSpam()) {
            // Its defined as spam just return true
            return true;
         }
      } catch (Exception $e) {
         if (JDEBUG) JError::raiseWarning(500, $e->getMessage());
         return false;
      }

      return false;
   }

    /**
     * Method to get Akismet
     *
     * @param $input
     * @throws Exception
     * @return object with data
     */
   private function _getAkismet($input)
   {
      // $data = $input['jform'];
      $data    = $input->get('contact_message','');

      $akismet = new Akismet($this->_params->get('site_url'), $this->_params->get('akismet_api_key'));
      if (!$akismet->isKeyValid()){
         throw new Exception(JText::_('COM_RIALTO_AKISMET_INVALID_API_KEY'));
      }
      $text = null;
      if ( ! empty ($data['contact_message']) )
         $text .= $data['contact_message'];

      $user = JFactory::getUser();    // Assumes registered user
      if ( $user->guest ) {
         $akismet->setCommentAuthor($data['user_details']['name']);
         // Use author set to 'viagra-test-123' to get a positive test back.
         $akismet->setCommentAuthorEmail($data['user_details']['email']);
      } else {
         // $akismet->setCommentAuthor($user->user_id ? $user->name : $user->name);
         // $akismet->setCommentAuthorEmail($user->user_id ? $user->email : $user->email);
         $akismet->setCommentAuthor($user->id ? $user->name : $user->name);
         $akismet->setCommentAuthorEmail($user->id ? $user->email : $user->email);
      }

      $akismet->setCommentContent($text);
      $akismet->setCommentType('comment');
      return $akismet;
   }
}

Youez - 2016 - github.com/yon3zu
LinuXploit