1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659 |
- <?php
- use ChamiloSession as Session;
- use Doctrine\Common\Collections\Criteria;
- define('FORUM_NEW_POST', 0);
- get_notifications_of_user();
- $htmlHeadXtra[] = api_get_jquery_libraries_js(array('jquery-ui', 'jquery-upload'));
- $htmlHeadXtra[] = '<script>
- function check_unzip() {
- if (document.upload.unzip.checked){
- document.upload.if_exists[0].disabled=true;
- document.upload.if_exists[1].checked=true;
- document.upload.if_exists[2].disabled=true;
- } else {
- document.upload.if_exists[0].checked=true;
- document.upload.if_exists[0].disabled=false;
- document.upload.if_exists[2].disabled=false;
- }
- }
- function setFocus() {
- $("#title_file").focus();
- }
- </script>';
- $htmlHeadXtra[] = "
- <script>
- $(function () {
- setFocus();
- $('#file_upload').fileUploadUI({
- uploadTable: $('.files'),
- downloadTable: $('.files'),
- buildUploadRow: function (files, index) {
- $('.files').closest('.control-group').show();
- return $('<tr><td>' + files[index].name + '<\/td>' +
- '<td class=\"file_upload_progress\"><div><\/div><\/td>' +
- '<td class=\"file_upload_cancel\">' +
- '<button class=\"ui-state-default ui-corner-all\" title=\"".get_lang('Cancel')."\">' + '<span class=\"ui-icon ui-icon-cancel\">".get_lang('Cancel')."<\/span>' +'<\/button>'+
- '<\/td><\/tr>');
- },
- buildDownloadRow: function (file) {
- if (!file.error) {
- return $('<tr id=' + file.id + ' ><td>' + file.name + '<\/td><td>' + file.size + '<\/td><td> ' + file.result +
- ' <\/td><td> <input style=\"width:90%;\" type=\"text\" value=\"' + file.comment + '\" name=\"file_comments[]\"> <\/td><td>' +
- file.delete + '<\/td>' +
- '<input type=\"hidden\" value=\"' + file.id +'\" name=\"file_ids[]\">' + '<\/tr>');
- } else {
- alert('" . get_lang('ErrorUploadAttachment') . "');
- }
- }
- });
- });
- </script>";
- $threadId = isset($_REQUEST['thread']) ? intval($_REQUEST['thread']) : 0;
- $forumId = isset($_REQUEST['forum']) ? intval($_REQUEST['forum']) : 0;
- $htmlHeadXtra[] = '<script>
- $(function () {
- $(document).on("click", ".deleteLink", function(e) {
- e.preventDefault();
- e.stopPropagation();
- var l = $(this);
- var id = l.closest("tr").attr("id");
- var filename = l.closest("tr").find(".attachFilename").html();
- if (confirm("' . get_lang('AreYouSureToDeleteFileX') . '".replace("%s", filename))) {
- $.ajax({
- type: "POST",
- url: "'.api_get_path(WEB_AJAX_PATH) . 'forum.ajax.php?'.api_get_cidreq().'&a=delete_file&attachId=" + id +"&thread='.$threadId .'&forum='.$forumId .'",
- dataType: "json",
- success: function(data) {
- if (data.error == false) {
- l.closest("tr").remove();
- if ($(".files td").length < 1) {
- $(".files").closest(".control-group").hide();
- }
- }
- }
- })
- }
- });
- });
- </script>';
- function handle_forum_and_forumcategories($lp_id = null)
- {
- $action_forum_cat = isset($_GET['action']) ? $_GET['action'] : '';
- $get_content = isset($_GET['content']) ? $_GET['content'] : '';
- $post_submit_cat = isset($_POST['SubmitForumCategory']) ? true : false;
- $post_submit_forum = isset($_POST['SubmitForum']) ? true : false;
- $get_id = isset($_GET['id']) ? intval($_GET['id']) : '';
- $forum_categories_list = get_forum_categories();
-
- if (empty($forum_categories_list)) {
- $get_content = 'forumcategory';
- }
-
- if (($action_forum_cat == 'add' && $get_content == 'forumcategory') || $post_submit_cat) {
- show_add_forumcategory_form(array(), $lp_id);
- }
-
- if ((($action_forum_cat == 'add' || $action_forum_cat == 'edit') && $get_content == 'forum') || $post_submit_forum) {
- if ($action_forum_cat == 'edit' && $get_id || $post_submit_forum) {
- $inputvalues = get_forums($get_id);
- } else {
- $inputvalues = array();
- }
- show_add_forum_form($inputvalues, $lp_id);
- }
-
- if (($action_forum_cat == 'edit' && $get_content == 'forumcategory') || (isset($_POST['SubmitEditForumCategory'])) ? true : false) {
- $forum_category = get_forum_categories($get_id);
- show_edit_forumcategory_form($forum_category);
- }
-
- if ($action_forum_cat == 'delete') {
- $id_forum = intval($get_id);
- $list_threads = get_threads($id_forum);
- for ($i = 0; $i < count($list_threads); $i++) {
- deleteForumCategoryThread('thread', $list_threads[$i]['thread_id']);
- $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 5, intval($list_threads[$i]['thread_id']), api_get_session_id());
- if ($link_info !== false) {
- GradebookUtils::remove_resource_from_course_gradebook($link_info['id']);
- }
- }
- $return_message = deleteForumCategoryThread($get_content, $get_id);
- Display::display_confirmation_message($return_message, false);
- }
-
- if ($action_forum_cat == 'invisible' || $action_forum_cat == 'visible') {
- $return_message = change_visibility($get_content, $get_id, $action_forum_cat);
- Display::display_confirmation_message($return_message, false);
- }
-
- if ($action_forum_cat == 'lock' || $action_forum_cat == 'unlock') {
- $return_message = change_lock_status($get_content, $get_id, $action_forum_cat);
- Display::display_confirmation_message($return_message, false);
- }
-
- if ($action_forum_cat == 'move' && isset($_GET['direction'])) {
- $return_message = move_up_down($get_content, $_GET['direction'], $get_id);
- Display::display_confirmation_message($return_message, false);
- }
- }
- function show_add_forumcategory_form($inputvalues = array(), $lp_id)
- {
- $gradebook = Security::remove_XSS($_GET['gradebook']);
-
- $form = new FormValidator('forumcategory', 'post', 'index.php?gradebook='.$gradebook.'&'.api_get_cidreq());
-
- $form->addElement('hidden', 'lp_id', $lp_id);
-
- $form->addElement('header', '', get_lang('AddForumCategory'));
- $form->addElement('text', 'forum_category_title', get_lang('Title'), array('autofocus'));
- $form->addElement(
- 'html_editor',
- 'forum_category_comment',
- get_lang('Description'),
- null,
- array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')
- );
- $form->addButtonCreate(get_lang('CreateCategory'), 'SubmitForumCategory');
-
- $form->addRule('forum_category_title', get_lang('ThisFieldIsRequired'), 'required');
-
- if ($form->validate()) {
- $check = Security::check_token('post');
- if ($check) {
- $values = $form->exportValues();
- store_forumcategory($values);
- }
- Security::clear_token();
- } else {
- $token = Security::get_token();
- $form->addElement('hidden', 'sec_token');
- $form->setConstants(array('sec_token' => $token));
- $form->display();
- }
- }
- function show_add_forum_form($inputvalues = array(), $lp_id)
- {
- $_course = api_get_course_info();
- $gradebook = Security::remove_XSS($_GET['gradebook']);
-
- $form = new FormValidator('forumcategory', 'post', 'index.php?gradebook='.$gradebook.'&'.api_get_cidreq());
-
- if (!empty($inputvalues)) {
- $form_title = get_lang('EditForum');
- } else {
- $form_title = get_lang('AddForum');
- }
- $session_header = isset($_SESSION['session_name']) ? ' ('.$_SESSION['session_name'].') ' : '';
- $form->addElement('header', $form_title.$session_header);
-
- if (!empty($inputvalues) && is_array($inputvalues)) {
- $my_forum_id = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
- $form->addElement('hidden', 'forum_id', $my_forum_id);
- }
- $lp_id = intval($lp_id);
-
- $form->addElement('hidden', 'lp_id', $lp_id);
-
- $form->addElement('text', 'forum_title', get_lang('Title'), array('autofocus'));
-
- $form->addElement(
- 'html_editor',
- 'forum_comment',
- get_lang('Description'),
- null,
- array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')
- );
-
- $forum_categories = get_forum_categories();
- foreach ($forum_categories as $key => $value) {
- $forum_categories_titles[$value['cat_id']] = $value['cat_title'];
- }
- $form->addElement('select', 'forum_category', get_lang('InForumCategory'), $forum_categories_titles);
- $form->applyFilter('forum_category', 'html_filter');
- if ($_course['visibility'] == COURSE_VISIBILITY_OPEN_WORLD) {
-
- $group = array();
- $group[] = $form->createElement('radio', 'allow_anonymous', null, get_lang('Yes'), 1);
- $group[] = $form->createElement('radio', 'allow_anonymous', null, get_lang('No'), 0);
- $form->addGroup($group, 'allow_anonymous_group', get_lang('AllowAnonymousPosts'), ' ');
- }
- $form->addButtonAdvancedSettings('advanced_params');
- $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
- $group = array();
- $group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('Yes'), 1);
- $group[] = $form->createElement('radio', 'students_can_edit', null, get_lang('No'), 0);
- $form->addGroup($group, 'students_can_edit_group', get_lang('StudentsCanEdit'), ' ');
- $group = array();
- $group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Approval'), 1);
- $group[] = $form->createElement('radio', 'approval_direct', null, get_lang('Direct'), 0);
- $group = array();
- $group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('Yes'), 1);
- $group[] = $form->createElement('radio', 'allow_attachments', null, get_lang('No'), 0);
- $group = array();
- $group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('Yes'), 1);
- $group[] = $form->createElement('radio', 'allow_new_threads', null, get_lang('No'), 0);
- $form->addGroup($group, 'allow_new_threads_group', get_lang('AllowNewThreads'), ' ');
- $group = array();
- $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Flat'), 'flat');
- $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Threaded'), 'threaded');
- $group[] = $form->createElement('radio', 'default_view_type', null, get_lang('Nested'), 'nested');
- $form->addGroup($group, 'default_view_type_group', get_lang('DefaultViewType'), ' ');
-
- $groups = GroupManager::get_group_list();
- $groups_titles[0] = get_lang('NotAGroupForum');
- foreach ($groups as $key => $value) {
- $groups_titles[$value['id']] = $value['name'];
- }
- $form->addElement('select', 'group_forum', get_lang('ForGroup'), $groups_titles);
-
- $group = array();
- $group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Public'), 'public');
- $group[] = $form->createElement('radio', 'public_private_group_forum', null, get_lang('Private'), 'private');
- $form->addGroup($group, 'public_private_group_forum_group', get_lang('PublicPrivateGroupForum'), '');
-
- $form->add_progress_bar();
- if (isset($inputvalues['forum_image']) && strlen($inputvalues['forum_image']) > 0) {
- $image_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$inputvalues['forum_image'];
- $image_size = api_getimagesize($image_path);
- $img_attributes = '';
- if (!empty($image_size)) {
- if ($image_size['width'] > 100 || $image_size['height'] > 100) {
-
- $img_attributes = 'width="100" height="100"';
- }
- $show_preview_image = '<img src="'.$image_path.'" '.$img_attributes.'>';
- $form->addElement('label', get_lang('PreviewImage'), $show_preview_image);
- $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
- }
- }
- $forum_image = isset($inputvalues['forum_image']) ? $inputvalues['forum_image'] : '';
- $form->addElement('file', 'picture', ($forum_image != '' ? get_lang('UpdateImage') : get_lang('AddImage')));
- $form->addRule('picture', get_lang('OnlyImagesAllowed'), 'filetype', array('jpg', 'jpeg', 'png', 'gif'));
- $form->addElement('html', '</div>');
-
- if (isset($_GET['id']) && $_GET['action'] == 'edit') {
- $form->addButtonUpdate(get_lang('ModifyForum'), 'SubmitForum');
- } else {
- $form->addButtonCreate(get_lang('CreateForum'), 'SubmitForum');
- }
-
- $form->addRule('forum_title', get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('forum_category', get_lang('ThisFieldIsRequired'), 'required');
- $defaultSettingAllowNewThreads = api_get_default_tool_setting('forum', 'allow_new_threads', 0);
-
- if (empty($inputvalues) || !is_array($inputvalues)) {
- $defaults['allow_anonymous_group']['allow_anonymous'] = 0;
- $defaults['students_can_edit_group']['students_can_edit'] = 0;
- $defaults['approval_direct_group']['approval_direct'] = 0;
- $defaults['allow_attachments_group']['allow_attachments'] = 1;
- $defaults['allow_new_threads_group']['allow_new_threads'] = $defaultSettingAllowNewThreads;
- $defaults['default_view_type_group']['default_view_type'] = api_get_setting('default_forum_view');
- $defaults['public_private_group_forum_group']['public_private_group_forum'] = 'public';
- if (isset($_GET['forumcategory'])) {
- $defaults['forum_category'] = Security::remove_XSS($_GET['forumcategory']);
- }
- } else {
- $defaults['forum_id'] = isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
- $defaults['forum_title'] = prepare4display(isset($inputvalues['forum_title']) ? $inputvalues['forum_title'] : null);
- $defaults['forum_comment'] = prepare4display(isset($inputvalues['forum_comment']) ? $inputvalues['forum_comment'] : null);
- $defaults['forum_category'] = isset($inputvalues['forum_category']) ? $inputvalues['forum_category'] : null;
- $defaults['allow_anonymous_group']['allow_anonymous'] = isset($inputvalues['allow_anonymous']) ? $inputvalues['allow_anonymous'] : null;
- $defaults['students_can_edit_group']['students_can_edit'] = isset($inputvalues['allow_edit']) ? $inputvalues['allow_edit'] : null;
- $defaults['approval_direct_group']['approval_direct'] = isset($inputvalues['approval_direct_post']) ? $inputvalues['approval_direct_post'] : null;
- $defaults['allow_attachments_group']['allow_attachments'] = isset($inputvalues['allow_attachments']) ? $inputvalues['allow_attachments'] : null;
- $defaults['allow_new_threads_group']['allow_new_threads'] = isset($inputvalues['allow_new_threads']) ? $inputvalues['allow_new_threads'] : $defaultSettingAllowNewThreads;
- $defaults['default_view_type_group']['default_view_type'] = isset($inputvalues['default_view']) ? $inputvalues['default_view'] : null;
- $defaults['public_private_group_forum_group']['public_private_group_forum'] = isset($inputvalues['forum_group_public_private']) ? $inputvalues['forum_group_public_private'] : null;
- $defaults['group_forum'] = isset($inputvalues['forum_of_group']) ? $inputvalues['forum_of_group'] : null;
- }
- $form->setDefaults($defaults);
-
- if ($form->validate()) {
- $check = Security::check_token('post');
- if ($check) {
- $values = $form->exportValues();
- $return_message = store_forum($values);
- Display :: display_confirmation_message($return_message);
- }
- Security::clear_token();
- } else {
- $token = Security::get_token();
- $form->addElement('hidden', 'sec_token');
- $form->setConstants(array('sec_token' => $token));
- $form->display();
- }
- }
- function delete_forum_image($forum_id)
- {
- $table_forums = Database::get_course_table(TABLE_FORUM);
- $course_id = api_get_course_int_id();
- $forum_id = intval($forum_id);
- $sql = "SELECT forum_image FROM $table_forums
- WHERE forum_id = '".$forum_id."' AND c_id = $course_id";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- if ($row['forum_image'] != '') {
- $del_file = api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/forum/images/'.$row['forum_image'];
- return @unlink($del_file);
- } else {
- return false;
- }
- }
- function show_edit_forumcategory_form($inputvalues = array())
- {
- $categoryId = $inputvalues['cat_id'];
- $form = new FormValidator('forumcategory', 'post', 'index.php?'.api_get_cidreq().'&id='.$categoryId);
-
- $form->addElement('header', '', get_lang('EditForumCategory'));
- $form->addElement('hidden', 'forum_category_id');
- $form->addElement('text', 'forum_category_title', get_lang('Title'));
- $form->addElement(
- 'html_editor',
- 'forum_category_comment',
- get_lang('Comment'),
- null,
- array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')
- );
- $form->addButtonUpdate(get_lang('ModifyCategory'), 'SubmitEditForumCategory');
-
- $defaultvalues['forum_category_id'] = $inputvalues['cat_id'];
- $defaultvalues['forum_category_title'] = $inputvalues['cat_title'];
- $defaultvalues['forum_category_comment'] = $inputvalues['cat_comment'];
- $form->setDefaults($defaultvalues);
-
- $form->addRule('forum_category_title', get_lang('ThisFieldIsRequired'), 'required');
-
- if ($form->validate()) {
- $check = Security::check_token('post');
- if ($check) {
- $values = $form->exportValues();
- store_forumcategory($values);
- }
- Security::clear_token();
- } else {
- $token = Security::get_token();
- $form->addElement('hidden', 'sec_token');
- $form->setConstants(array('sec_token' => $token));
- $form->display();
- }
- }
- function store_forumcategory($values, $courseInfo = array(), $showMessage = true)
- {
- $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
- $course_id = $courseInfo['real_id'];
- $table_categories = Database::get_course_table(TABLE_FORUM_CATEGORY);
-
- $sql = "SELECT MAX(cat_order) as sort_max
- FROM $table_categories
- WHERE c_id = $course_id";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $new_max = $row['sort_max'] + 1;
- $session_id = api_get_session_id();
- $clean_cat_title = $values['forum_category_title'];
- if (isset($values['forum_category_id'])) {
-
- $params = [
- 'cat_title' => $clean_cat_title,
- 'cat_comment' => $values['forum_category_comment'],
- ];
- Database::update(
- $table_categories,
- $params,
- [
- 'c_id = ? AND cat_id = ?' => [
- $course_id,
- $values['forum_category_id'],
- ],
- ]
- );
- api_item_property_update(
- $courseInfo,
- TOOL_FORUM_CATEGORY,
- $values['forum_category_id'],
- 'ForumCategoryUpdated',
- api_get_user_id()
- );
- $return_message = get_lang('ForumCategoryEdited');
- } else {
- $params = [
- 'c_id' => $course_id,
- 'cat_title' => $clean_cat_title,
- 'cat_comment' => $values['forum_category_comment'],
- 'cat_order' => $new_max,
- 'session_id' => $session_id
- ];
- $last_id = Database::insert($table_categories, $params);
- if ($last_id > 0) {
- $sql = "UPDATE $table_categories SET cat_id = $last_id WHERE iid = $last_id";
- Database::query($sql);
- api_item_property_update(
- $courseInfo,
- TOOL_FORUM_CATEGORY,
- $last_id,
- 'ForumCategoryAdded',
- api_get_user_id()
- );
- api_set_default_visibility(
- $last_id,
- TOOL_FORUM_CATEGORY,
- 0,
- $courseInfo
- );
- }
- $return_message = get_lang('ForumCategoryAdded');
- }
- if ($showMessage) {
- Display:: display_confirmation_message($return_message);
- }
- return $last_id;
- }
- function store_forum($values, $courseInfo = array(), $returnId = false)
- {
- $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo;
- $course_id = $courseInfo['real_id'];
- $session_id = api_get_session_id();
- if (isset($values['group_id']) && !empty($values['group_id'])) {
- $group_id = $values['group_id'];
- } else {
- $group_id = api_get_group_id();
- }
- $table_forums = Database::get_course_table(TABLE_FORUM);
-
- if (is_null($values['forum_category'])) {
- $new_max = null;
- } else {
- $sql = "SELECT MAX(forum_order) as sort_max
- FROM ".$table_forums."
- WHERE
- c_id = $course_id AND
- forum_category='".Database::escape_string($values['forum_category'])."'";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $new_max = $row['sort_max'] + 1;
- }
- $clean_title = Database::escape_string($values['forum_title']);
-
- $image_moved = false;
- if (!empty($_FILES['picture']['name'])) {
- $upload_ok = process_uploaded_file($_FILES['picture']);
- $has_attachment = true;
- } else {
- $image_moved = true;
- }
-
- if (!empty($_POST['remove_picture'])) {
- delete_forum_image($values['forum_id']);
- }
- if (isset($upload_ok)) {
- if ($has_attachment) {
- $course_dir = $courseInfo['path'].'/upload/forum/images';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$course_dir;
-
- $new_file_name = add_ext_on_mime(Database::escape_string($_FILES['picture']['name']), $_FILES['picture']['type']);
- if (!filter_extension($new_file_name)) {
-
- $image_moved = false;
- } else {
- $file_extension = explode('.', $_FILES['picture']['name']);
- $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
- $new_file_name = uniqid('').'.'.$file_extension;
- $new_path = $updir.'/'.$new_file_name;
- $result = @move_uploaded_file($_FILES['picture']['tmp_name'], $new_path);
-
- if ($result) {
- $image_moved = true;
- }
- }
- }
- }
- if (isset($values['forum_id'])) {
- $sql_image = isset($sql_image) ? $sql_image : '';
- $new_file_name = isset($new_file_name) ? $new_file_name : '';
- if ($image_moved) {
- if (empty($_FILES['picture']['name'])) {
- $sql_image = "";
- } else {
- $sql_image = $new_file_name;
- delete_forum_image($values['forum_id']);
- }
- }
-
- $params = [
- 'forum_title'=> $values['forum_title'],
- 'forum_image'=> $sql_image,
- 'forum_comment'=> $values['forum_comment'],
- 'forum_category'=> $values['forum_category'],
- 'allow_anonymous'=> $values['allow_anonymous_group']['allow_anonymous'],
- 'allow_edit'=> $values['students_can_edit_group']['students_can_edit'],
- 'approval_direct_post'=> $values['approval_direct_group']['approval_direct'],
- 'allow_attachments'=> $values['allow_attachments_group']['allow_attachments'],
- 'allow_new_threads'=> $values['allow_new_threads_group']['allow_new_threads'],
- 'default_view'=> $values['default_view_type_group']['default_view_type'],
- 'forum_of_group'=> $values['group_forum'],
- 'forum_group_public_private'=> $values['public_private_group_forum_group']['public_private_group_forum'],
- 'forum_order'=> $new_max,
- 'session_id'=> $session_id,
- ];
- Database::update(
- $table_forums,
- $params,
- ['c_id = ? AND forum_id = ?' => [$course_id, $values['forum_id']]]
- );
- api_item_property_update(
- $courseInfo,
- TOOL_FORUM,
- Database::escape_string($values['forum_id']),
- 'ForumUpdated',
- api_get_user_id(),
- $group_id
- );
- $return_message = get_lang('ForumEdited');
- } else {
- if ($image_moved) {
- $new_file_name = isset($new_file_name) ? $new_file_name : '';
- }
- $params = [
- 'c_id' => $course_id,
- 'forum_title'=> $values['forum_title'],
- 'forum_image'=> $new_file_name,
- 'forum_comment'=> isset($values['forum_comment']) ? $values['forum_comment'] : null,
- 'forum_category'=> isset($values['forum_category']) ? $values['forum_category'] : null,
- 'allow_anonymous'=> isset($values['allow_anonymous_group']['allow_anonymous']) ? $values['allow_anonymous_group']['allow_anonymous'] : null,
- 'allow_edit'=> isset($values['students_can_edit_group']['students_can_edit']) ? $values['students_can_edit_group']['students_can_edit'] : null,
- 'approval_direct_post'=> isset($values['approval_direct_group']['approval_direct']) ? $values['approval_direct_group']['approval_direct'] : null,
- 'allow_attachments'=> isset($values['allow_attachments_group']['allow_attachments']) ? $values['allow_attachments_group']['allow_attachments'] : null,
- 'allow_new_threads'=> isset($values['allow_new_threads_group']['allow_new_threads']) ? $values['allow_new_threads_group']['allow_new_threads'] : null,
- 'default_view'=> isset($values['default_view_type_group']['default_view_type']) ? $values['default_view_type_group']['default_view_type'] : null,
- 'forum_of_group'=> isset($values['group_forum']) ? $values['group_forum'] : null,
- 'forum_group_public_private'=> isset($values['public_private_group_forum_group']['public_private_group_forum']) ? $values['public_private_group_forum_group']['public_private_group_forum'] : null,
- 'forum_order'=> isset($new_max) ? $new_max : null,
- 'session_id'=> $session_id,
- ];
- $last_id = Database::insert($table_forums, $params);
- if ($last_id > 0) {
- $sql = "UPDATE $table_forums SET forum_id = iid WHERE iid = $last_id";
- Database::query($sql);
- api_item_property_update(
- $courseInfo,
- TOOL_FORUM,
- $last_id,
- 'ForumAdded',
- api_get_user_id(),
- $group_id
- );
- api_set_default_visibility(
- $last_id,
- TOOL_FORUM,
- $group_id,
- $courseInfo
- );
- }
- $return_message = get_lang('ForumAdded');
- if ($returnId) {
- return $last_id;
- }
- }
- return $return_message;
- }
- function deleteForumCategoryThread($content, $id)
- {
- $_course = api_get_course_info();
- $table_forums = Database::get_course_table(TABLE_FORUM);
- $table_forums_post = Database::get_course_table(TABLE_FORUM_POST);
- $table_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD);
- $course_id = api_get_course_int_id();
- $groupId = api_get_group_id();
- $userId = api_get_user_id();
- $id = intval($id);
-
- $sql = "SELECT post_id FROM $table_forums_post
- WHERE c_id = $course_id AND thread_id = '".$id."' ";
- $res = Database::query($sql);
- while ($poster_id = Database::fetch_row($res)) {
- delete_attachment($poster_id[0]);
- }
- $tool_constant = null;
- $return_message = '';
- if ($content == 'forumcategory') {
- $tool_constant = TOOL_FORUM_CATEGORY;
- $return_message = get_lang('ForumCategoryDeleted');
- if (!empty($forum_list)) {
- $sql = "SELECT forum_id FROM ".$table_forums."
- WHERE c_id = $course_id AND forum_category='".$id."'";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- foreach ($row as $arr_forum) {
- $forum_id = $arr_forum['forum_id'];
- api_item_property_update(
- $_course,
- 'forum',
- $forum_id,
- 'delete',
- api_get_user_id()
- );
- }
- }
- }
- if ($content == 'forum') {
- $tool_constant = TOOL_FORUM;
- $return_message = get_lang('ForumDeleted');
- if (!empty($number_threads)) {
- $sql = "SELECT thread_id FROM".$table_forum_thread."
- WHERE c_id = $course_id AND forum_id='".$id."'";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- foreach ($row as $arr_forum) {
- $forum_id = $arr_forum['thread_id'];
- api_item_property_update($_course, 'forum_thread', $forum_id, 'delete', api_get_user_id());
- }
- }
- }
- if ($content == 'thread') {
- $tool_constant = TOOL_FORUM_THREAD;
- $return_message = get_lang('ThreadDeleted');
- }
- api_item_property_update(
- $_course,
- $tool_constant,
- $id,
- 'delete',
- $userId,
- $groupId
- );
-
- return $return_message;
- }
- function delete_post($post_id)
- {
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $post_id = intval($post_id);
- $course_id = api_get_course_int_id();
-
- $tab_post_info = get_post_information($post_id);
- if ($tab_post_info) {
- $post_parent_id_of_deleted_post = intval($tab_post_info['post_parent_id']);
- $thread_id_of_deleted_post = $tab_post_info['thread_id'];
- $forum_if_of_deleted_post = $tab_post_info['forum_id'];
- $sql = "UPDATE $table_posts
- SET post_parent_id=$post_parent_id_of_deleted_post
- WHERE
- c_id = $course_id AND
- post_parent_id=$post_id AND
- thread_id=$thread_id_of_deleted_post AND
- forum_id=$forum_if_of_deleted_post";
- Database::query($sql);
-
- $sql = "DELETE FROM $table_posts
- WHERE c_id = $course_id AND post_id = ".intval($post_id)."";
- Database::query($sql);
-
- delete_attachment($post_id);
- }
- $last_post_of_thread = check_if_last_post_of_thread($_GET['thread']);
- if (is_array($last_post_of_thread)) {
-
- $sql = "UPDATE $table_threads SET thread_replies=thread_replies-1,
- thread_last_post = ".intval($last_post_of_thread['post_id']).",
- thread_date='".Database::escape_string($last_post_of_thread['post_date'])."'
- WHERE c_id = $course_id AND thread_id = ".intval($_GET['thread'])."";
- Database::query($sql);
- return 'PostDeleted';
- }
- if (!$last_post_of_thread) {
-
- $sql = "DELETE FROM $table_threads
- WHERE c_id = $course_id AND thread_id = ".intval($_GET['thread'])."";
- Database::query($sql);
- return 'PostDeletedSpecial';
- }
- }
- function check_if_last_post_of_thread($thread_id)
- {
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM $table_posts
- WHERE c_id = $course_id AND thread_id = ".intval($thread_id)."
- ORDER BY post_date DESC";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0) {
- $row = Database::fetch_array($result);
- return $row;
- } else {
- return false;
- }
- }
- function display_visible_invisible_icon($content, $id, $current_visibility_status, $additional_url_parameters = '')
- {
- echo return_visible_invisible_icon($content, $id, $current_visibility_status, $additional_url_parameters);
- }
- function return_visible_invisible_icon($content, $id, $current_visibility_status, $additional_url_parameters = '')
- {
- $html = '';
- $id = Security::remove_XSS($id);
- if ($current_visibility_status == '1') {
- $html .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&';
- if (is_array($additional_url_parameters)) {
- foreach ($additional_url_parameters as $key => $value) {
- $html .= $key . '=' . $value . '&';
- }
- }
- $html.='action=invisible&content='.$content.'&id='.$id.'">'.Display::return_icon('visible.png', get_lang('MakeInvisible'), array(), ICON_SIZE_SMALL).'</a>';
- }
- if ($current_visibility_status == '0') {
- $html .= '<a href="' . api_get_self() . '?' . api_get_cidreq() . '&';
- if (is_array($additional_url_parameters)) {
- foreach ($additional_url_parameters as $key => $value) {
- $html .= $key . '=' . $value . '&';
- }
- }
- $html .= 'action=visible&content=' . $content . '&id=' . $id . '">' . Display::return_icon('invisible.png', get_lang('MakeVisible'), array(), ICON_SIZE_SMALL) . '</a>';
- }
- return $html;
- }
- function display_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters = '')
- {
- echo return_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters);
- }
- function return_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters = '')
- {
- $html = '';
- $id = intval($id);
-
- if ($content == 'thread') {
- if (api_resource_is_locked_by_gradebook($id, LINK_FORUM_THREAD)) {
- $html .= Display::return_icon('lock_na.png', get_lang('ResourceLockedByGradebook'), array(), ICON_SIZE_SMALL);
- return $html;
- }
- }
- if ($current_lock_status == '1') {
- $html .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&';
- if (is_array($additional_url_parameters)) {
- foreach ($additional_url_parameters as $key => $value) {
- $html .= $key . '=' . $value . '&';
- }
- }
- $html.= 'action=unlock&content='.$content.'&id='.$id.'">'.Display::return_icon('lock.png', get_lang('Unlock'), array(), ICON_SIZE_SMALL).'</a>';
- }
- if ($current_lock_status == '0') {
- $html .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&';
- if (is_array($additional_url_parameters)) {
- foreach ($additional_url_parameters as $key => $value) {
- $html .= $key . '=' . $value . '&';
- }
- }
- $html .= 'action=lock&content=' . $content . '&id=' . $id . '">' . Display::return_icon('unlock.png', get_lang('Lock'), array(), ICON_SIZE_SMALL) . '</a>';
- }
- return $html;
- }
- function display_up_down_icon($content, $id, $list)
- {
- echo return_up_down_icon($content, $id, $list);
- }
- function return_up_down_icon($content, $id, $list)
- {
- $id = strval(intval($id));
- $total_items = count($list);
- $position = 0;
- $internal_counter = 0;
- $forumCategory = isset($_GET['forumcategory']) ? Security::remove_XSS($_GET['forumcategory']) : null;
- if (is_array($list)) {
- foreach ($list as $key => $listitem) {
- $internal_counter++;
- if ($id == $key) {
- $position = $internal_counter;
- }
- }
- }
- if ($position > 1) {
- $return_value = '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=move&direction=up&content='.$content.'&forumcategory='.$forumCategory.'&id='.$id.'" title="'.get_lang('MoveUp').'">'.
- Display::return_icon('up.png', get_lang('MoveUp'), array(), ICON_SIZE_SMALL).'</a>';
- } else {
- $return_value = Display::return_icon('up_na.png', '-', array(), ICON_SIZE_SMALL);
- }
- if ($position < $total_items) {
- $return_value .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=move&direction=down&content='.$content.'&forumcategory='.$forumCategory.'&id='.$id.'" title="'.get_lang('MoveDown').'" >'.
- Display::return_icon('down.png', get_lang('MoveDown'), array(), ICON_SIZE_SMALL).'</a>';
- } else {
- $return_value .= Display::return_icon('down_na.png', '-', array(), ICON_SIZE_SMALL);
- }
- return $return_value;
- }
- function change_visibility($content, $id, $target_visibility)
- {
- $_course = api_get_course_info();
- $constants = array(
- 'forumcategory' => TOOL_FORUM_CATEGORY,
- 'forum' => TOOL_FORUM,
- 'thread' => TOOL_FORUM_THREAD
- );
- api_item_property_update(
- $_course,
- $constants[$content],
- $id,
- $target_visibility,
- api_get_user_id()
- );
- if ($target_visibility == 'visible') {
- handle_mail_cue($content, $id);
- }
- return get_lang('VisibilityChanged');
- }
- function change_lock_status($content, $id, $action)
- {
- $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
-
- if ($content == 'forumcategory') {
- $table = $table_categories;
- $id_field = 'cat_id';
- } elseif ($content == 'forum') {
- $table = $table_forums;
- $id_field = 'forum_id';
- } elseif ($content == 'thread') {
- $table = $table_threads;
- $id_field = 'thread_id';
- } else {
- return get_lang('Error');
- }
-
- if ($action == 'lock') {
- $db_locked = 1;
- $return_message = get_lang('Locked');
- } elseif ($action == 'unlock') {
- $db_locked = 0;
- $return_message = get_lang('Unlocked');
- } else {
- return get_lang('Error');
- }
- $course_id = api_get_course_int_id();
-
- $sql = "UPDATE $table SET locked='".Database::escape_string($db_locked)."'
- WHERE c_id = $course_id AND $id_field='".Database::escape_string($id)."'";
- if (Database::query($sql)) {
- return $return_message;
- } else {
- return get_lang('Error');
- }
- }
- function move_up_down($content, $direction, $id)
- {
- $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $course_id = api_get_course_int_id();
- $id = intval($id);
-
- if ($content == 'forumcategory') {
- $table = $table_categories;
- $sort_column = 'cat_order';
- $id_column = 'cat_id';
- $sort_column = 'cat_order';
- } elseif ($content == 'forum') {
- $table = $table_forums;
- $sort_column = 'forum_order';
- $id_column = 'forum_id';
- $sort_column = 'forum_order';
-
- $sql = "SELECT forum_category FROM $table_forums
- WHERE c_id = $course_id AND forum_id = ".intval($id);
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $forum_category = $row['forum_category'];
- } else {
- return get_lang('Error');
- }
-
- if ($direction == 'down') {
- $sort_direction = 'ASC';
- } elseif ($direction == 'up') {
- $sort_direction = 'DESC';
- } else {
- return get_lang('Error');
- }
-
- if ($content == 'forumcategory') {
- $sql = "SELECT *
- FROM $table_categories forum_categories, $table_item_property item_properties
- WHERE
- forum_categories.c_id = $course_id AND
- item_properties.c_id = $course_id AND
- forum_categories.cat_id=item_properties.ref AND
- item_properties.tool='" . TOOL_FORUM_CATEGORY . "'
- ORDER BY forum_categories.cat_order $sort_direction";
- }
- if ($content == 'forum') {
- $sql = "SELECT *
- FROM $table
- WHERE
- c_id = $course_id AND
- forum_category='" . Database::escape_string($forum_category) . "'
- ORDER BY forum_order $sort_direction";
- }
-
-
- $result = Database::query($sql);
- $found = false;
- while ($row = Database::fetch_array($result)) {
-
- if ($found) {
- $next_id = $row[$id_column];
- $next_sort = $row[$sort_column];
- $found = false;
- }
- if ($id == $row[$id_column]) {
- $this_id = $id;
- $this_sort = $row[$sort_column];
- $found = true;
- }
- }
-
-
-
- if ($this_sort != '' && $next_sort != '' && $next_id != '' && $this_id != '') {
- $sql_update1 = "UPDATE $table SET $sort_column='".Database::escape_string($this_sort)."'
- WHERE c_id = $course_id AND $id_column='".Database::escape_string($next_id)."'";
- $sql_update2 = "UPDATE $table SET $sort_column='".Database::escape_string($next_sort)."'
- WHERE c_id = $course_id AND $id_column='".Database::escape_string($this_id)."'";
- Database::query($sql_update1);
- Database::query($sql_update2);
- }
- return get_lang(ucfirst($content).'Moved');
- }
- function class_visible_invisible($current_visibility_status)
- {
- $current_visibility_status = intval($current_visibility_status);
- if ($current_visibility_status == 0) {
- return 'class="invisible"';
- }
- }
- function return_visible_invisible($current_visibility_status)
- {
- $current_visibility_status = intval($current_visibility_status);
- if ($current_visibility_status == 0) {
- $status='invisible';
- return $status;
- }
- }
- function get_forum_categories($id = '')
- {
- $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
-
- $session_id = api_get_session_id();
- $course_id = api_get_course_int_id();
- $condition_session = api_get_session_condition($session_id, true, true, 'forum_categories.session_id');
- $condition_session .= " AND forum_categories.c_id = $course_id AND item_properties.c_id = $course_id";
- if (empty($id)) {
- $sql = "SELECT *
- FROM ".$table_categories." forum_categories, ".$table_item_property." item_properties
- WHERE
- forum_categories.cat_id=item_properties.ref AND
- item_properties.visibility=1 AND
- item_properties.tool = '".TOOL_FORUM_CATEGORY."'
- $condition_session
- ORDER BY forum_categories.cat_order ASC";
- if (api_is_allowed_to_edit()) {
- $sql = "SELECT *
- FROM ".$table_categories." forum_categories, ".$table_item_property." item_properties
- WHERE
- forum_categories.cat_id=item_properties.ref AND
- item_properties.visibility<>2 AND
- item_properties.tool='".TOOL_FORUM_CATEGORY."'
- $condition_session
- ORDER BY forum_categories.cat_order ASC";
- }
- } else {
- $sql = "SELECT *
- FROM ".$table_categories." forum_categories, ".$table_item_property." item_properties
- WHERE
- forum_categories.cat_id=item_properties.ref AND
- item_properties.tool='".TOOL_FORUM_CATEGORY."' AND
- forum_categories.cat_id = ".intval($id)."
- $condition_session
- ORDER BY forum_categories.cat_order ASC";
- }
- $result = Database::query($sql);
- $forum_categories_list = array();
- while ($row = Database::fetch_array($result)) {
- if (empty($id)) {
- $forum_categories_list[$row['cat_id']] = $row;
- } else {
- $forum_categories_list = $row;
- }
- }
- return $forum_categories_list;
- }
- function get_forums_in_category($cat_id)
- {
- $table_forums = Database::get_course_table(TABLE_FORUM);
- $table_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
- $forum_list = array();
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM ".$table_forums." forum , ".$table_item_property." item_properties
- WHERE
- forum.forum_category='".Database::escape_string($cat_id)."' AND
- forum.forum_id=item_properties.ref AND
- item_properties.visibility = 1 AND
- item_properties.c_id = $course_id AND
- item_properties.tool='".TOOL_FORUM."' AND
- forum.c_id = $course_id
- ORDER BY forum.forum_order ASC";
- if (api_is_allowed_to_edit()) {
- $sql = "SELECT * FROM ".$table_forums." forum , ".$table_item_property." item_properties
- WHERE
- forum.forum_category = '".Database::escape_string($cat_id)."' AND
- forum.forum_id = item_properties.ref AND
- item_properties.visibility <> 2 AND
- item_properties.tool = '".TOOL_FORUM."' AND
- item_properties.c_id = $course_id AND
- forum.c_id = $course_id
- ORDER BY forum_order ASC";
- }
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- $forum_list[$row['forum_id']] = $row;
- }
- return $forum_list;
- }
- function get_forums(
- $id = '',
- $course_code = '',
- $includeGroupsForum = true,
- $sessionId = 0
- ) {
- $course_info = api_get_course_info($course_code);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
-
-
- if (empty($sessionId)) {
- $session_id = api_get_session_id();
- } else {
- $session_id = $sessionId;
- }
- $condition_session = api_get_session_condition(
- $session_id,
- true,
- false,
- 'item_properties.session_id'
- );
- $course_id = $course_info['real_id'];
- $forum_list = array();
- $includeGroupsForumSelect = "";
- if (!$includeGroupsForum) {
- $includeGroupsForumSelect = " AND forum_of_group = 0 ";
- }
- if ($id == '') {
-
-
- $sql = "SELECT * FROM $table_forums forum
- INNER JOIN ".$table_item_property." item_properties
- ON (
- forum.forum_id = item_properties.ref AND
- forum.c_id = item_properties.c_id
- )
- WHERE
- item_properties.visibility=1 AND
- item_properties.tool = '".TOOL_FORUM."'
- $condition_session AND
- forum.c_id = $course_id AND
- item_properties.c_id = $course_id
- $includeGroupsForumSelect
- ORDER BY forum.forum_order ASC";
-
- $sql2 = "SELECT count(*) AS number_of_threads, threads.forum_id
- FROM $table_threads threads
- INNER JOIN ".$table_item_property." item_properties
- ON (
- threads.thread_id=item_properties.ref AND
- threads.c_id = item_properties.c_id AND
- threads.session_id = item_properties.session_id
- )
- WHERE
- item_properties.visibility=1 AND
- item_properties.tool='".TOOL_FORUM_THREAD."' AND
- threads.c_id = $course_id AND
- item_properties.c_id = $course_id
- GROUP BY threads.forum_id";
-
- $sql3 = "SELECT count(*) AS number_of_posts, posts.forum_id
- FROM $table_posts posts, $table_threads threads, ".$table_item_property." item_properties
- WHERE
- posts.visible=1 AND
- posts.thread_id=threads.thread_id AND
- threads.thread_id=item_properties.ref AND
- threads.session_id = item_properties.session_id AND
- item_properties.visibility=1 AND
- item_properties.tool='".TOOL_FORUM_THREAD."' AND
- threads.c_id = $course_id AND
- posts.c_id = $course_id AND
- item_properties.c_id = $course_id
- GROUP BY threads.forum_id";
-
- if (api_is_allowed_to_edit()) {
-
- $sql = "SELECT * FROM ".$table_forums." forum
- INNER JOIN ".$table_item_property." item_properties
- ON (
- forum.forum_id = item_properties.ref AND
- forum.c_id = item_properties.c_id
- )
- WHERE
- item_properties.visibility <> 2 AND
- item_properties.tool='".TOOL_FORUM."'
- $condition_session AND
- forum.c_id = $course_id AND
- item_properties.c_id = $course_id
- $includeGroupsForumSelect
- ORDER BY forum_order ASC";
-
- $sql2 = "SELECT count(*) AS number_of_threads, threads.forum_id
- FROM $table_threads threads
- INNER JOIN ".$table_item_property." item_properties
- ON (
- threads.thread_id=item_properties.ref AND
- threads.c_id = item_properties.c_id AND
- threads.session_id = item_properties.session_id
- )
- WHERE
- item_properties.visibility<>2 AND
- item_properties.tool='".TOOL_FORUM_THREAD."' AND
- threads.c_id = $course_id AND
- item_properties.c_id = $course_id
- GROUP BY threads.forum_id";
-
- $sql3 = "SELECT count(*) AS number_of_posts, posts.forum_id
- FROM $table_posts posts, $table_threads threads, ".$table_item_property." item_properties
- WHERE
- posts.thread_id=threads.thread_id AND
- threads.thread_id=item_properties.ref AND
- threads.session_id = item_properties.session_id AND
- item_properties.visibility=1 AND
- item_properties.tool='".TOOL_FORUM_THREAD."' AND
- posts.c_id = $course_id AND
- threads.c_id = $course_id AND
- item_properties.c_id = $course_id
- GROUP BY threads.forum_id";
- }
- } else {
-
-
-
- $sql = "SELECT * FROM $table_forums forum, ".$table_item_property." item_properties
- WHERE
- forum.forum_id=item_properties.ref AND
- forum_id = ".intval($id)." AND
- item_properties.visibility<>2 AND
- item_properties.tool='".TOOL_FORUM."'
- $condition_session AND
- forum.c_id = $course_id AND
- item_properties.c_id = $course_id
- ORDER BY forum_order ASC";
-
- $sql2 = "SELECT count(*) AS number_of_threads, forum_id
- FROM $table_threads
- WHERE
- forum_id = ".intval($id)." AND
- c_id = $course_id
- GROUP BY forum_id";
-
- $sql3 = "SELECT count(*) AS number_of_posts, forum_id
- FROM $table_posts
- WHERE
- forum_id = ".intval($id)." AND
- c_id = $course_id
- GROUP BY forum_id";
-
- $sql4 = "SELECT
- post.post_id,
- post.forum_id,
- post.poster_id,
- post.poster_name,
- post.post_date,
- users.lastname,
- users.firstname
- FROM $table_posts post, $table_users users
- WHERE
- forum_id = ".intval($id)." AND
- post.poster_id=users.user_id AND
- post.c_id = $course_id
- GROUP BY post.forum_id
- ORDER BY post.post_id ASC";
- }
-
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- if ($id == '') {
- $forum_list[$row['forum_id']] = $row;
- } else {
- $forum_list = $row;
- }
- }
-
- $result2 = Database::query($sql2);
- while ($row2 = Database::fetch_array($result2)) {
- if ($id == '') {
- $forum_list[$row2['forum_id']]['number_of_threads'] = $row2['number_of_threads'];
- } else {
- $forum_list['number_of_threads'] = $row2['number_of_threads'];
- }
- }
-
- $result3 = Database::query($sql3);
- while ($row3 = Database::fetch_array($result3)) {
- if ($id == '') {
-
- if (array_key_exists($row3['forum_id'], $forum_list)) {
- $forum_list[$row3['forum_id']]['number_of_posts'] = $row3['number_of_posts'];
- }
- } else {
- $forum_list['number_of_posts'] = $row3['number_of_posts'];
- }
- }
-
- if ($id == '') {
- if (is_array($forum_list)) {
- foreach ($forum_list as $key => $value) {
- $last_post_info_of_forum = get_last_post_information($key, api_is_allowed_to_edit(), $course_id);
- $forum_list[$key]['last_post_id'] = $last_post_info_of_forum['last_post_id'];
- $forum_list[$key]['last_poster_id'] = $last_post_info_of_forum['last_poster_id'];
- $forum_list[$key]['last_post_date'] = $last_post_info_of_forum['last_post_date'];
- $forum_list[$key]['last_poster_name'] = $last_post_info_of_forum['last_poster_name'];
- $forum_list[$key]['last_poster_lastname'] = $last_post_info_of_forum['last_poster_lastname'];
- $forum_list[$key]['last_poster_firstname'] = $last_post_info_of_forum['last_poster_firstname'];
- }
- } else {
- $forum_list = array();
- }
- } else {
- $last_post_info_of_forum = get_last_post_information($id, api_is_allowed_to_edit(), $course_id);
- $forum_list['last_post_id'] = $last_post_info_of_forum['last_post_id'];
- $forum_list['last_poster_id'] = $last_post_info_of_forum['last_poster_id'];
- $forum_list['last_post_date'] = $last_post_info_of_forum['last_post_date'];
- $forum_list['last_poster_name'] = $last_post_info_of_forum['last_poster_name'];
- $forum_list['last_poster_lastname'] = $last_post_info_of_forum['last_poster_lastname'];
- $forum_list['last_poster_firstname'] = $last_post_info_of_forum['last_poster_firstname'];
- }
- return $forum_list;
- }
- function get_last_post_by_thread($course_id, $thread_id, $forum_id, $show_visible = true)
- {
- if (empty($thread_id) || empty($forum_id) || empty($course_id)) {
- return false;
- }
- $thread_id = intval($thread_id);
- $forum_id = intval($forum_id);
- $course_id = intval($course_id);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $sql = "SELECT * FROM $table_posts
- WHERE c_id = $course_id AND thread_id = $thread_id AND forum_id = $forum_id";
- if ($show_visible == false) {
- $sql .= " AND visible = 1 ";
- }
- $sql .= " ORDER BY post_id DESC LIMIT 1";
- $result = Database::query($sql);
- if (Database::num_rows($result)) {
- return Database::fetch_array($result, 'ASSOC');
- } else {
- return false;
- }
- }
- function get_last_post_information($forum_id, $show_invisibles = false, $course_id = null)
- {
- if (!isset($course_id)) {
- $course_id = api_get_course_int_id();
- } else {
- $course_id = intval($course_id);
- }
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT post.post_id, post.forum_id, post.poster_id, post.poster_name, post.post_date, users.lastname, users.firstname, post.visible, thread_properties.visibility AS thread_visibility, forum_properties.visibility AS forum_visibility
- FROM
- $table_posts post,
- $table_users users,
- $table_item_property thread_properties,
- $table_item_property forum_properties
- WHERE
- post.forum_id = ".intval($forum_id)."
- AND post.poster_id=users.user_id
- AND post.thread_id=thread_properties.ref
- AND thread_properties.tool='".TOOL_FORUM_THREAD."'
- AND post.forum_id=forum_properties.ref
- AND forum_properties.tool='".TOOL_FORUM."'
- AND post.c_id = $course_id AND
- thread_properties.c_id = $course_id AND
- forum_properties.c_id = $course_id
- ORDER BY post.post_id DESC";
- $result = Database::query($sql);
- if ($show_invisibles) {
- $row = Database::fetch_array($result);
- $return_array['last_post_id'] = $row['post_id'];
- $return_array['last_poster_id'] = $row['poster_id'];
- $return_array['last_post_date'] = $row['post_date'];
- $return_array['last_poster_name'] = $row['poster_name'];
- $return_array['last_poster_lastname'] = $row['lastname'];
- $return_array['last_poster_firstname'] = $row['firstname'];
- return $return_array;
- } else {
-
-
- while ($row = Database::fetch_array($result)) {
- if ($row['visible'] == '1' && $row['thread_visibility'] == '1' && $row['forum_visibility'] == '1') {
- $return_array['last_post_id'] = $row['post_id'];
- $return_array['last_poster_id'] = $row['poster_id'];
- $return_array['last_post_date'] = $row['post_date'];
- $return_array['last_poster_name'] = $row['poster_name'];
- $return_array['last_poster_lastname'] = $row['lastname'];
- $return_array['last_poster_firstname'] = $row['firstname'];
- return $return_array;
- }
- }
- }
- }
- function get_threads($forum_id, $course_code = null)
- {
- $course_info = api_get_course_info($course_code);
- if (empty($course_info)) {
- return array();
- }
- $course_id = $course_info['real_id'];
- $groupId = api_get_group_id();
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
-
-
-
-
- $groupCondition = api_get_group_id() != 0 ? " AND item_properties.to_group_id = '$groupId' AND item_properties.c_id = '$course_id'" : "";
- $sql = "SELECT
- thread.*,
- item_properties.*,
- users.firstname,
- users.lastname,
- users.user_id,
- thread.locked as locked
- FROM $table_threads thread
- INNER JOIN $table_item_property item_properties
- ON
- thread.thread_id = item_properties.ref AND
- item_properties.c_id = thread.c_id AND
- item_properties.c_id = $course_id AND
- item_properties.tool = '".TABLE_FORUM_THREAD."' $groupCondition
- LEFT JOIN $table_users users
- ON thread.thread_poster_id=users.user_id
- WHERE
- item_properties.visibility='1' AND
- thread.forum_id = ".intval($forum_id)."
- ORDER BY thread.thread_sticky DESC, thread.thread_date DESC";
- if (api_is_allowed_to_edit()) {
- $sql = "SELECT
- thread.*,
- item_properties.*,
- users.firstname,
- users.lastname,
- users.user_id,
- thread.locked as locked
- FROM $table_threads thread
- INNER JOIN $table_item_property item_properties
- ON
- thread.thread_id = item_properties.ref AND
- item_properties.c_id = $course_id AND
- thread.c_id = $course_id AND
- item_properties.tool = '".TABLE_FORUM_THREAD."' $groupCondition
- LEFT JOIN $table_users users
- ON thread.thread_poster_id=users.user_id
- WHERE
- item_properties.visibility<>2 AND
- thread.forum_id = ".intval($forum_id)."
- ORDER BY thread.thread_sticky DESC, thread.thread_date DESC";
- }
- $result = Database::query($sql);
- $thread_list = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $thread_list[] = $row;
- }
- return $thread_list;
- }
- function getPosts($threadId, $orderDirection = 'ASC', $recursive = false, $postId = 0, $depth = -1)
- {
- $list = [];
- $em = Database::getManager();
- if (api_is_allowed_to_edit(false, true)) {
- $visibleCriteria = Criteria::expr()->neq('visible', 2);
- } else {
- $visibleCriteria = Criteria::expr()->eq('visible', 1);
- }
- $criteria = Criteria::create();
- $criteria
- ->where(Criteria::expr()->eq('threadId', $threadId))
- ->andWhere(Criteria::expr()->eq('cId', api_get_course_int_id()))
- ->andWhere($visibleCriteria)
- ;
- if ($recursive) {
- $criteria->andWhere(Criteria::expr()->eq('postParentId', $postId));
- }
- $qb = $em->getRepository('ChamiloCourseBundle:CForumPost')->createQueryBuilder('p');
- $qb->select('p')
- ->addCriteria($criteria)
- ->addOrderBy('p.postId', $orderDirection);
- $posts = $qb->getQuery()->getResult();
- $depth++;
- foreach ($posts as $post) {
- $user = $em->find('ChamiloUserBundle:User', $post->getPosterId());
- $list[$post->getPostId()] = [
- 'c_id' => $post->getCId(),
- 'post_id' => $post->getPostId(),
- 'post_title' => $post->getPostTitle(),
- 'post_text' => $post->getPostText(),
- 'thread_id' => $post->getThreadId(),
- 'forum_id' => $post->getForumId(),
- 'poster_id' => $post->getPosterId(),
- 'poster_name' => $post->getPosterName(),
- 'post_date' => $post->getPostDate(),
- 'post_notification' => $post->getPostNotification(),
- 'post_parent_id' => $post->getPostParentId(),
- 'visible' => $post->getVisible(),
- 'indent_cnt' => $depth,
- 'user_id' => $user->getUserId(),
- 'username' => $user->getUsername(),
- 'username_canonical' => $user->getUsernameCanonical(),
- 'lastname' => $user->getLastname(),
- 'firstname' => $user->getFirstname(),
- ];
- if (!$recursive) {
- continue;
- }
- $list = array_merge(
- $list,
- getPosts(
- $threadId,
- $orderDirection,
- $recursive,
- $post->getPostId(),
- $depth
- )
- );
- }
- return $list;
- }
- function get_post_information($post_id)
- {
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $course_id = api_get_course_int_id();
- $sql = "SELECT * FROM ".$table_posts." posts, ".$table_users." users
- WHERE
- c_id = $course_id AND
- posts.poster_id=users.user_id AND
- posts.post_id = ".intval($post_id)."";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return $row;
- }
- function get_thread_information($thread_id)
- {
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $course_id = api_get_course_int_id();
- $thread_id = intval($thread_id);
- $sql = "SELECT * FROM ".$table_threads." threads, ".$table_item_property." item_properties
- WHERE
- item_properties.tool= '".TOOL_FORUM_THREAD."' AND
- item_properties.c_id = $course_id AND
- item_properties.ref = ".$thread_id." AND
- threads.thread_id = ".$thread_id." AND
- threads.c_id = $course_id
- ";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return $row;
- }
- function get_thread_users_details($thread_id)
- {
- $t_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $t_users = Database :: get_main_table(TABLE_MAIN_USER);
- $t_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $t_session_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $course_code = api_get_course_id();
- $course_code = Database::escape_string($course_code);
- $course_id = api_get_course_int_id();
- $is_western_name_order = api_is_western_name_order();
- if ($is_western_name_order) {
- $orderby = 'ORDER BY user.firstname, user.lastname ';
- } else {
- $orderby = 'ORDER BY user.lastname, user.firstname';
- }
- if (api_get_session_id()) {
- $session_info = api_get_session_info(api_get_session_id());
- $user_to_avoid = "'".$session_info['id_coach']."', '".$session_info['session_admin_id']."'";
-
- $sql = "SELECT DISTINCT user.id, user.lastname, user.firstname, thread_id
- FROM $t_posts p, $t_users user, $t_session_rel_user session_rel_user_rel_course
- WHERE p.poster_id = user.id AND
- user.id = session_rel_user_rel_course.user_id AND
- session_rel_user_rel_course.status<>'2' AND
- session_rel_user_rel_course.user_id NOT IN ($user_to_avoid) AND
- p.thread_id = ".intval($thread_id)." AND
- session_id = ".api_get_session_id()." AND
- p.c_id = $course_id AND
- session_rel_user_rel_course.c_id = ".$course_id." $orderby ";
- } else {
- $sql = "SELECT DISTINCT user.id, user.lastname, user.firstname, thread_id
- FROM $t_posts p, $t_users user, $t_course_user course_user
- WHERE p.poster_id = user.id
- AND user.id = course_user.user_id
- AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
- AND p.thread_id = ".intval($thread_id)."
- AND course_user.status NOT IN('1') AND
- p.c_id = $course_id AND
- course_user.c_id = ".$course_id." $orderby";
- }
- $result = Database::query($sql);
- return $result;
- }
- function get_thread_users_qualify($thread_id)
- {
- $t_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $t_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
- $t_users = Database :: get_main_table(TABLE_MAIN_USER);
- $t_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $t_session_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $course_id = api_get_course_int_id();
- $is_western_name_order = api_is_western_name_order();
- if ($is_western_name_order) {
- $orderby = 'ORDER BY user.firstname, user.lastname ';
- } else {
- $orderby = 'ORDER BY user.lastname, user.firstname';
- }
- if (api_get_session_id()) {
- $session_info = api_get_session_info(api_get_session_id());
- $user_to_avoid = "'".$session_info['id_coach']."', '".$session_info['session_admin_id']."'";
-
- $sql = "SELECT DISTINCT post.poster_id, user.lastname, user.firstname, post.thread_id,user.id,qualify.qualify
- FROM $t_posts post , $t_users user, $t_session_rel_user scu, $t_qualify qualify
- WHERE poster_id = user.id
- AND post.poster_id = qualify.user_id
- AND user.id = session_rel_user_rel_course.user_id
- AND scu.status<>'2'
- AND scu.user_id NOT IN ($user_to_avoid)
- AND qualify.thread_id = ".intval($thread_id)."
- AND post.thread_id = ".intval($thread_id)."
- AND session_id = ".api_get_session_id()."
- AND scu.c_id = ".$course_id." AND
- qualify.c_id = $course_id AND
- post.c_id = $course_id
- $orderby ";
- } else {
- $sql = "SELECT DISTINCT post.poster_id, user.lastname, user.firstname, post.thread_id,user.id,qualify.qualify
- FROM $t_posts post,
- $t_qualify qualify,
- $t_users user,
- $t_course_user course_user
- WHERE
- post.poster_id = user.id
- AND post.poster_id = qualify.user_id
- AND user.id = course_user.user_id
- AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
- AND qualify.thread_id = ".intval($thread_id)."
- AND post.thread_id = ".intval($thread_id)."
- AND course_user.status not in('1')
- AND course_user.c_id = $course_id
- AND qualify.c_id = $course_id
- AND post.c_id = $course_id
- $orderby ";
- }
- $result = Database::query($sql);
- return $result;
- }
- function get_thread_users_not_qualify($thread_id)
- {
- $t_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $t_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY);
- $t_users = Database :: get_main_table(TABLE_MAIN_USER);
- $t_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
- $t_session_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
- $is_western_name_order = api_is_western_name_order();
- if ($is_western_name_order) {
- $orderby = 'ORDER BY user.firstname, user.lastname ';
- } else {
- $orderby = 'ORDER BY user.lastname, user.firstname';
- }
- $course_id = api_get_course_int_id();
- $sql1 = "SELECT user_id FROM $t_qualify
- WHERE c_id = $course_id AND thread_id = '".$thread_id."'";
- $result1 = Database::query($sql1);
- $cad = '';
- while ($row = Database::fetch_array($result1)) {
- $cad .= $row['user_id'].',';
- }
- if ($cad == '') {
- $cad = '0';
- } else {
- $cad = substr($cad, 0, strlen($cad) - 1);
- }
- if (api_get_session_id()) {
- $session_info = api_get_session_info(api_get_session_id());
- $user_to_avoid = "'".$session_info['id_coach']."', '".$session_info['session_admin_id']."'";
-
- $sql = "SELECT DISTINCT user.id, user.lastname, user.firstname, post.thread_id
- FROM $t_posts post , $t_users user, $t_session_rel_user session_rel_user_rel_course
- WHERE poster_id = user.id
- AND user.id NOT IN (".$cad.")
- AND user.id = session_rel_user_rel_course.user_id
- AND session_rel_user_rel_course.status<>'2'
- AND session_rel_user_rel_course.user_id NOT IN ($user_to_avoid)
- AND post.thread_id = ".intval($thread_id)."
- AND session_id = ".api_get_session_id()."
- AND session_rel_user_rel_course.c_id = $course_id AND post.c_id = $course_id $orderby ";
- } else {
- $sql = "SELECT DISTINCT user.id, user.lastname, user.firstname, post.thread_id
- FROM $t_posts post, $t_users user,$t_course_user course_user
- WHERE post.poster_id = user.id
- AND user.id NOT IN (".$cad.")
- AND user.id = course_user.user_id
- AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
- AND post.thread_id = ".intval($thread_id)."
- AND course_user.status not in('1')
- AND course_user.c_id = $course_id AND post.c_id = $course_id $orderby";
- }
- $result = Database::query($sql);
- return $result;
- }
- function get_forum_information($forum_id, $courseId = 0)
- {
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $courseId = empty($courseId) ? api_get_course_int_id(): intval($courseId);
- $forum_id = intval($forum_id);
- $sql = "SELECT *
- FROM $table_forums forums
- INNER JOIN $table_item_property item_properties
- ON (forums.c_id = item_properties.c_id)
- WHERE
- item_properties.tool = '".TOOL_FORUM."' AND
- item_properties.ref = '".$forum_id."' AND
- forums.forum_id = '".$forum_id."' AND
- forums.c_id = ".$courseId."
- ";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $row['approval_direct_post'] = 0;
-
- return $row;
- }
- function get_forumcategory_information($cat_id)
- {
- $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $course_id = api_get_course_int_id();
- $sql = "SELECT *
- FROM ".$table_categories." forumcategories, ".$table_item_property." item_properties
- WHERE
- forumcategories.c_id = $course_id AND
- item_properties.c_id = $course_id AND
- item_properties.tool='".TOOL_FORUM_CATEGORY."' AND
- item_properties.ref='".Database::escape_string($cat_id)."' AND
- forumcategories.cat_id='".Database::escape_string($cat_id)."'";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return $row;
- }
- function count_number_of_forums_in_category($cat_id)
- {
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $course_id = api_get_course_int_id();
- $sql = "SELECT count(*) AS number_of_forums
- FROM ".$table_forums."
- WHERE c_id = $course_id AND forum_category='".Database::escape_string($cat_id)."'";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return $row['number_of_forums'];
- }
- function store_thread($current_forum, $values, $courseInfo = array(), $showMessage = true)
- {
- $courseInfo = empty($courseInfo) ? api_get_course_info() : $courseInfo ;
- $_user = api_get_user_info();
- $course_id = $courseInfo['real_id'];
- $courseCode = $courseInfo['code'];
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : '';
- $upload_ok = 1;
- $has_attachment = false;
- if (!empty($_FILES['user_upload']['name'])) {
- $upload_ok = process_uploaded_file($_FILES['user_upload']);
- $has_attachment = true;
- }
- if ($upload_ok) {
- $post_date = api_get_utc_datetime();
- if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) {
- $visible = 0;
- } else {
- $visible = 1;
- }
- $clean_post_title = $values['post_title'];
-
- $last_thread_id = Database::insert(
- $table_threads,
- [
- 'c_id' => $course_id,
- 'thread_title' => $clean_post_title,
- 'forum_id' => $values['forum_id'],
- 'thread_poster_id' => $_user['user_id'],
- 'thread_poster_name' => stripslashes(isset($values['poster_name']) ? $values['poster_name'] : null),
- 'thread_date' => $post_date,
- 'thread_sticky' => isset($values['thread_sticky']) ? $values['thread_sticky'] : null,
- 'thread_title_qualify' => stripslashes($values['calification_notebook_title']),
- 'thread_qualify_max' => $values['numeric_calification'],
- 'thread_weight' => $values['weight_calification'],
- 'thread_peer_qualify' => $values['thread_peer_qualify'],
- 'session_id' => api_get_session_id()
- ]
- );
-
- if (isset($values['thread_qualify_gradebook']) &&
- 1 == $values['thread_qualify_gradebook']
- ) {
-
- $resourcetype = 5;
- $resourceid = $last_thread_id;
- $resourcename = stripslashes($values['calification_notebook_title']);
- $maxqualify = $values['numeric_calification'];
- $weigthqualify = $values['weight_calification'];
- $resourcedescription = '';
- GradebookUtils::add_resource_to_course_gradebook(
- $values['category_id'],
- $courseCode,
- $resourcetype,
- $resourceid,
- $resourcename,
- $weigthqualify,
- $maxqualify,
- $resourcedescription,
- 0,
- api_get_session_id()
- );
- }
- if ($last_thread_id) {
- $sql = "UPDATE $table_threads SET thread_id = $last_thread_id
- WHERE iid = $last_thread_id";
- Database::query($sql);
- api_item_property_update(
- $courseInfo,
- TOOL_FORUM_THREAD,
- $last_thread_id,
- 'ForumThreadAdded',
- api_get_user_id(),
- api_get_group_id(),
- null,
- null,
- null,
- api_get_session_id()
- );
-
-
-
-
-
-
-
-
- api_set_default_visibility(
- $last_thread_id,
- TOOL_FORUM_THREAD,
- api_get_group_id(),
- $courseInfo
- );
- if ($visible == 0) {
- api_item_property_update(
- $courseInfo,
- TOOL_FORUM_THREAD,
- $last_thread_id,
- 'invisible',
- api_get_user_id(),
- api_get_group_id()
- );
- $visible = 1;
- }
- }
-
- $params = [
- 'c_id' => $course_id,
- 'post_title' => $clean_post_title,
- 'post_text' => $values['post_text'],
- 'thread_id' => $last_thread_id,
- 'forum_id' => $values['forum_id'],
- 'poster_id' => $_user['user_id'],
- 'poster_name' => isset($values['poster_name']) ? $values['poster_name'] : null,
- 'post_date' => $post_date,
- 'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : null,
- 'post_parent_id' => 0,
- 'visible' => $visible,
- ];
- $last_post_id = Database::insert($table_posts, $params);
- if ($last_post_id) {
- $sql = "UPDATE $table_posts SET post_id = $last_post_id
- WHERE iid = $last_post_id";
- Database::query($sql);
- }
-
- if (!empty($_POST['file_ids']) && is_array($_POST['file_ids'])) {
- foreach ($_POST['file_ids'] as $key => $id) {
- editAttachedFile(
- array(
- 'comment' => $_POST['file_comments'][$key],
- 'post_id' => $last_post_id,
- ),
- $id
- );
- }
- }
-
-
- $sql = "UPDATE $table_threads
- SET thread_last_post = '".Database::escape_string($last_post_id)."'
- WHERE
- c_id = $course_id AND
- thread_id='".Database::escape_string($last_thread_id)."'";
- $result = Database::query($sql);
- $message = get_lang('NewThreadStored');
-
- if ($has_attachment) {
-
- $new_file_name = add_ext_on_mime(
- stripslashes($_FILES['user_upload']['name']),
- $_FILES['user_upload']['type']
- );
- if (!filter_extension($new_file_name)) {
- if ($showMessage) {
- Display:: display_error_message(
- get_lang('UplUnableToSaveFileFilteredExtension')
- );
- }
- } else {
- if ($result) {
- add_forum_attachment_file(
- isset($values['file_comment']) ? $values['file_comment'] : null,
- $last_post_id
- );
- }
- }
- } else {
- $message .= '<br />';
- }
- if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) {
- $message .= get_lang('MessageHasToBeApproved').'<br />';
- $message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'">'.get_lang('Forum').'</a><br />';
- } else {
- $message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'">'.get_lang('Forum').'</a><br />';
- $message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'&gradebook='.$gradebook.'&thread='.$last_thread_id.'">'.get_lang('Message').'</a>';
- }
- $reply_info['new_post_id'] = $last_post_id;
- $my_post_notification = isset($values['post_notification']) ? $values['post_notification'] : null;
- if ($my_post_notification == 1) {
- set_notification('thread', $last_thread_id, true);
- }
- send_notification_mails($last_thread_id, $reply_info);
- Session::erase('formelements');
- Session::erase('origin');
- Session::erase('breadcrumbs');
- Session::erase('addedresource');
- Session::erase('addedresourceid');
- if ($showMessage) {
- Display:: display_confirmation_message($message, false);
- }
- } else {
- if ($showMessage) {
- Display::display_error_message(get_lang('UplNoFileUploaded'));
- }
- }
- }
- function show_add_post_form($current_forum, $forum_setting, $action = '', $id = '', $form_values = '')
- {
- $_user = api_get_user_info();
- $action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
-
- $myThread = isset($_GET['thread']) ? $_GET['thread'] : '';
- $my_forum = isset($_GET['forum']) ? $_GET['forum'] : '';
- $my_post = isset($_GET['post']) ? $_GET['post'] : '';
- $my_gradebook = isset($_GET['gradebook']) ? Security::remove_XSS($_GET['gradebook']) : '';
- $form = new FormValidator(
- 'thread',
- 'post',
- api_get_self().'?forum='.Security::remove_XSS($my_forum).'&'.api_get_cidreq().'&thread='.Security::remove_XSS($myThread).'&post='.Security::remove_XSS($my_post).'&action='.$action
- );
- $form->setConstants(array('forum' => '5'));
-
- $form->addElement('hidden', 'forum_id', intval($my_forum));
- $form->addElement('hidden', 'thread_id', intval($myThread));
- $form->addElement('hidden', 'gradebook', $my_gradebook);
-
- if ($current_forum['allow_anonymous'] == 1 && !isset($_user['user_id'])) {
- $form->addElement('text', 'poster_name', get_lang('Name'));
- $form->applyFilter('poster_name', 'html_filter');
- }
- $form->addElement('text', 'post_title', get_lang('Title'));
- $form->addHtmlEditor(
- 'post_text',
- get_lang('Text'),
- true,
- api_is_allowed_to_edit(null, true) ? array(
- 'ToolbarSet' => 'Forum',
- 'Width' => '100%',
- 'Height' => '300',
- ) : array(
- 'ToolbarSet' => 'ForumStudent',
- 'Width' => '100%',
- 'Height' => '300',
- 'UserStatus' => 'student',
- )
- );
- $form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
- $iframe = null;
- $myThread = Security::remove_XSS($myThread);
- if ($forum_setting['show_thread_iframe_on_reply'] && $action != 'newthread' && !empty($myThread)) {
- $iframe = "<iframe style=\"border: 1px solid black\" src=\"iframe_thread.php?".api_get_cidreq()."&forum=".Security::remove_XSS($my_forum)."&thread=".$myThread."#".Security::remove_XSS($my_post)."\" width=\"100%\"></iframe>";
- }
- if (!empty($iframe)) {
- $form->addElement('label', get_lang('Thread'), $iframe);
- }
- $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
- $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
- if ((api_is_course_admin() || api_is_course_coach() || api_is_course_tutor()) && !($myThread)) {
-
- if (Gradebook::is_active()) {
-
- GradebookUtils::load_gradebook_select_in_tool($form);
- $form->addElement(
- 'checkbox',
- 'thread_qualify_gradebook',
- '',
- get_lang('QualifyThreadGradebook'),
- 'onclick="javascript:if(this.checked==true){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"'
- );
- } else {
- $form->addElement('hidden', 'thread_qualify_gradebook', false);
- }
- $form->addElement('html', '<div id="options_field" style="display:none">');
- $form->addElement('text', 'numeric_calification', get_lang('QualificationNumeric'));
- $form->applyFilter('numeric_calification', 'html_filter');
- $form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'));
- $form->applyFilter('calification_notebook_title', 'html_filter');
- $form->addElement(
- 'text',
- 'weight_calification',
- get_lang('QualifyWeight'),
- array('value' => '0.00', 'onfocus' => "javascript: this.select();")
- );
- $form->applyFilter('weight_calification', 'html_filter');
- $group = array();
- $group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('Yes'), 1);
- $group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('No'), 0);
- $form->addGroup(
- $group,
- '',
- [
- get_lang('ForumThreadPeerScoring'),
- get_lang('ForumThreadPeerScoringComment'),
- ],
- ' '
- );
- $form->addElement('html', '</div>');
- }
- if ($forum_setting['allow_post_notification'] && isset($_user['user_id'])) {
- $form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail').' ('.$_user['mail'].')');
- }
- if ($forum_setting['allow_sticky'] && api_is_allowed_to_edit(null, true) && $action == 'newthread') {
- $form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
- }
- if ($current_forum['allow_attachments'] == '1' || api_is_allowed_to_edit(null, true)) {
- $values = $form->exportValues();
- }
- $form->addElement('html', '</div>');
- if (in_array($action, ['quote', 'replymessage'])) {
- $form->addFile('user_upload[]', get_lang('Attachment'));
- $form->addButton(
- 'add_attachment',
- get_lang('AddAttachment'),
- 'paperclip',
- 'default',
- 'default',
- null,
- ['id' => 'reply-add-attachment']
- );
- } else {
- $form->addFile('user_upload', get_lang('Attachment'));
- }
-
- if ($action == 'quote') {
- $form->addButtonCreate(get_lang('QuoteMessage'), 'SubmitPost');
- } elseif ($action == 'replythread') {
- $form->addButtonCreate(get_lang('ReplyToThread'), 'SubmitPost');
- } elseif ($action == 'replymessage') {
- $form->addButtonCreate(get_lang('ReplyToMessage'), 'SubmitPost');
- } else {
- $form->addButtonCreate(get_lang('CreateThread'), 'SubmitPost');
- }
- if (!empty($form_values)) {
- $defaults['post_title'] = prepare4display($form_values['post_title']);
- $defaults['post_text'] = prepare4display($form_values['post_text']);
- $defaults['post_notification'] = strval(intval($form_values['post_notification']));
- $defaults['thread_sticky'] = strval(intval($form_values['thread_sticky']));
- $defaults['thread_peer_qualify'] = intval($form_values['thread_peer_qualify']);
- } else {
- $defaults['thread_peer_qualify'] = 0;
- }
-
-
- if (($action == 'quote' || $action == 'replymessage') && isset($my_post)) {
-
- $form->addElement('hidden', 'post_parent_id', intval($my_post));
-
- $values = get_post_information($my_post);
- $defaults['post_title'] = get_lang('ReplyShort').api_html_entity_decode($values['post_title'], ENT_QUOTES);
-
-
- if ($action == 'quote') {
- $defaults['post_text'] = '<div> </div><div style="margin: 5px;"><div style="font-size: 90%; font-style: italic;">'.get_lang('Quoting').' '.api_get_person_name($values['firstname'], $values['lastname']).':</div><div style="color: #006600; font-size: 90%; font-style: italic; background-color: #FAFAFA; border: #D1D7DC 1px solid; padding: 3px;">'.prepare4display($values['post_text']).'</div></div><div> </div><div> </div>';
- }
- }
- $form->setDefaults(isset($defaults) ? $defaults : null);
-
- $form->addRule('post_title', get_lang('ThisFieldIsRequired'), 'required');
- if ($current_forum['allow_anonymous'] == 1 && !isset($_user['user_id'])) {
- $form->addRule('poster_name', get_lang('ThisFieldIsRequired'), 'required');
- }
-
- if ($form->validate()) {
- $check = Security::check_token('post');
- if ($check) {
- $values = $form->exportValues();
- if (isset($values['thread_qualify_gradebook']) &&
- $values['thread_qualify_gradebook'] == '1' &&
- empty($values['weight_calification'])
- ) {
- Display::display_error_message(
- get_lang('YouMustAssignWeightOfQualification').' <a href="javascript:window.history.go(-1);">'.get_lang('Back').'</a>',
- false
- );
- return false;
- }
- Security::clear_token();
- return $values;
- }
- } else {
- $token = Security::get_token();
- $form->addElement('hidden', 'sec_token');
- $form->setConstants(array('sec_token' => $token));
-
-
- clearAttachedFiles(FORUM_NEW_POST);
-
- $attachmentAjaxTable = getAttachmentsAjaxTable(0, $current_forum['forum_id']);
- $ajaxHtml = $attachmentAjaxTable;
- $form->addElement('html', $ajaxHtml);
- $form->display();
- }
- }
- function saveThreadScore(
- $threadInfo,
- $user_id,
- $thread_id,
- $thread_qualify = 0,
- $qualify_time,
- $session_id = 0
- ) {
- $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
- $table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
- $course_id = api_get_course_int_id();
- $session_id = intval($session_id);
- $currentUserId = api_get_user_id();
- if ($user_id == strval(intval($user_id)) &&
- $thread_id == strval(intval($thread_id)) &&
- $thread_qualify == strval(floatval($thread_qualify))
- ) {
-
- $sql = "SELECT thread_qualify_max FROM $table_threads
- WHERE c_id = $course_id AND thread_id=".$thread_id;
- $res_string = Database::query($sql);
- $row_string = Database::fetch_array($res_string);
- if ($thread_qualify <= $row_string[0]) {
- if ($threadInfo['thread_peer_qualify'] == 0) {
- $sql = "SELECT COUNT(*) FROM $table_threads_qualify
- WHERE
- c_id = $course_id AND
- user_id = $user_id AND
- thread_id = ".$thread_id;
- } else {
- $sql = "SELECT COUNT(*) FROM $table_threads_qualify
- WHERE
- c_id = $course_id AND
- user_id = $user_id AND
- qualify_user_id = $currentUserId AND
- thread_id = ".$thread_id;
- }
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- if ($row[0] == 0) {
- $sql = "INSERT INTO $table_threads_qualify (c_id, user_id, thread_id,qualify,qualify_user_id,qualify_time,session_id)
- VALUES (".$course_id.", '".$user_id."','".$thread_id."',".(float)$thread_qualify.", '".$currentUserId."','".$qualify_time."','".$session_id."')";
- Database::query($sql);
- $insertId = Database::insert_id();
- if ($insertId) {
- $sql = "UPDATE $table_threads_qualify SET id = iid
- WHERE iid = $insertId";
- Database::query($sql);
- }
- return 'insert';
- } else {
- saveThreadScoreHistory(
- '1',
- $course_id,
- $user_id,
- $thread_id
- );
-
- $sql = "UPDATE $table_threads_qualify
- SET
- qualify = '".$thread_qualify."',
- qualify_time = '".$qualify_time."'
- WHERE
- c_id = $course_id AND
- user_id=".$user_id." AND
- thread_id=".$thread_id." AND
- qualify_user_id = $currentUserId
- ";
- Database::query($sql);
- return 'update';
- }
- } else {
- return null;
- }
- }
- }
- function showQualify($option, $user_id, $thread_id)
- {
- $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
- $table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
- $course_id = api_get_course_int_id();
- $user_id = intval($user_id);
- $thread_id = intval($thread_id);
- if (empty($user_id) || empty($thread_id)) {
- return false;
- }
- $sql = '';
- switch ($option) {
- case 1:
- $sql = "SELECT qualify FROM $table_threads_qualify
- WHERE
- c_id = $course_id AND
- user_id=".$user_id." AND
- thread_id=".$thread_id;
- break;
- case 2:
- $sql = "SELECT thread_qualify_max FROM $table_threads
- WHERE c_id = $course_id AND thread_id=".$thread_id;
- break;
- }
- if (!empty($sql)) {
- $rs = Database::query($sql);
- $row = Database::fetch_array($rs);
- return $row[0];
- }
- return array();
- }
- function getThreadScoreHistory($user_id, $thread_id, $opt)
- {
- $table_threads_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
- $course_id = api_get_course_int_id();
- if ($opt == 'false') {
- $sql = "SELECT * FROM ".$table_threads_qualify_log."
- WHERE
- c_id = $course_id AND
- thread_id='".Database::escape_string($thread_id)."' AND
- user_id='".Database::escape_string($user_id)."'
- ORDER BY qualify_time";
- } else {
- $sql = "SELECT * FROM ".$table_threads_qualify_log."
- WHERE
- c_id = $course_id AND
- thread_id='".Database::escape_string($thread_id)."' AND
- user_id='".Database::escape_string($user_id)."'
- ORDER BY qualify_time DESC";
- }
- $rs = Database::query($sql);
- $log = array();
- while ($row = Database::fetch_array($rs, 'ASSOC')) {
- $log[] = $row;
- }
- return $log;
- }
- function saveThreadScoreHistory(
- $option,
- $course_id,
- $user_id,
- $thread_id
- ) {
- $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
- $table_threads_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
- $course_id = intval($course_id);
- $qualify_user_id = api_get_user_id();
- if ($user_id == strval(intval($user_id)) &&
- $thread_id == strval(intval($thread_id)) && $option == 1
- ) {
-
- $sql = "SELECT qualify, qualify_time
- FROM $table_threads_qualify
- WHERE
- c_id = $course_id AND
- user_id = ".$user_id." AND
- thread_id = ".$thread_id." AND
- qualify_user_id = $qualify_user_id
- ";
- $rs = Database::query($sql);
- $row = Database::fetch_array($rs);
-
- $sql = "INSERT INTO $table_threads_qualify_log (c_id, user_id, thread_id, qualify, qualify_user_id,qualify_time,session_id)
- VALUES(".$course_id.", '".$user_id."','".$thread_id."',".(float) $row[0].", '".$qualify_user_id."','".$row[1]."','')";
- Database::query($sql);
- $insertId = Database::insert_id();
- if ($insertId) {
- $sql = "UPDATE $table_threads_qualify_log SET id = iid
- WHERE iid = $insertId";
- Database::query($sql);
- }
- }
- }
- function current_qualify_of_thread($threadId, $sessionId, $userId)
- {
- $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
- $course_id = api_get_course_int_id();
- $currentUserId = api_get_user_id();
- $sessionId = intval($sessionId);
- $threadId = intval($threadId);
- $sql = "SELECT qualify FROM $table_threads_qualify
- WHERE
- c_id = $course_id AND
- thread_id = $threadId AND
- session_id = $sessionId AND
- qualify_user_id = $currentUserId AND
- user_id = $userId
- ";
- $res = Database::query($sql);
- $row = Database::fetch_array($res, 'ASSOC');
- return $row['qualify'];
- }
- function store_reply($current_forum, $values)
- {
- $_course = api_get_course_info();
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $post_date = api_get_utc_datetime();
- if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(null, true)) {
- $visible = 0;
- } else {
- $visible = 1;
- }
- $upload_ok = 1;
- $return = array();
- if ($upload_ok) {
-
- $new_post_id = Database::insert(
- $table_posts,
- [
- 'c_id' => api_get_course_int_id(),
- 'post_title' => $values['post_title'],
- 'post_text' => isset($values['post_text']) ? ($values['post_text']) : null,
- 'thread_id' => $values['thread_id'],
- 'forum_id' => $values['forum_id'],
- 'poster_id' => api_get_user_id(),
- 'post_date' => $post_date,
- 'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : null,
- 'post_parent_id' => isset($values['post_parent_id']) ? $values['post_parent_id'] : null,
- 'visible' => $visible
- ]
- );
- if ($new_post_id) {
- $sql = "UPDATE $table_posts SET post_id = iid WHERE iid = $new_post_id";
- Database::query($sql);
- $values['new_post_id'] = $new_post_id;
- $message = get_lang('ReplyAdded');
- if (!empty($_POST['file_ids']) && is_array($_POST['file_ids'])) {
- foreach ($_POST['file_ids'] as $key => $id) {
- editAttachedFile(
- array(
- 'comment' => $_POST['file_comments'][$key],
- 'post_id' => $new_post_id
- ),
- $id
- );
- }
- }
-
- update_thread($values['thread_id'], $new_post_id, $post_date);
-
- api_item_property_update(
- $_course,
- TOOL_FORUM,
- $values['forum_id'],
- 'NewMessageInForum',
- api_get_user_id()
- );
- if ($current_forum['approval_direct_post'] == '1' && !api_is_allowed_to_edit(
- null,
- true
- )
- ) {
- $message .= '<br />'.get_lang(
- 'MessageHasToBeApproved'
- ).'<br />';
- }
-
- $my_post_notification = isset($values['post_notification']) ? $values['post_notification'] : null;
- if ($my_post_notification == 1) {
- set_notification('thread', $values['thread_id'], true);
- }
- send_notification_mails($values['thread_id'], $values);
- add_forum_attachment_file('', $new_post_id);
- }
- Session::erase('formelements');
- Session::erase('origin');
- Session::erase('breadcrumbs');
- Session::erase('addedresource');
- Session::erase('addedresourceid');
- $return['msg'] = $message;
- $return['type'] = 'confirmation';
- } else {
- $return['msg'] = get_lang('UplNoFileUploaded').' '.get_lang('UplSelectFileFirst');
- $return['type'] = 'error';
- }
- return $return;
- }
- function show_edit_post_form($forum_setting, $current_post, $current_thread, $current_forum, $form_values = '', $id_attach = 0)
- {
-
- $form = new FormValidator(
- 'edit_post',
- 'post',
- api_get_self().'?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&post='.Security::remove_XSS($_GET['post'])
- );
- $form->addElement('header', get_lang('EditPost'));
-
- $form->addElement('hidden', 'post_id', $current_post['post_id']);
- $form->addElement('hidden', 'thread_id', $current_thread['thread_id']);
- $form->addElement('hidden', 'id_attach', $id_attach);
- if ($current_post['post_parent_id'] == 0) {
- $form->addElement('hidden', 'is_first_post_of_thread', '1');
- }
- $form->addElement('text', 'post_title', get_lang('Title'));
- $form->applyFilter('post_title', 'html_filter');
- $form->addElement(
- 'html_editor',
- 'post_text',
- get_lang('Text'),
- null,
- api_is_allowed_to_edit(null, true) ? array(
- 'ToolbarSet' => 'Forum',
- 'Width' => '100%',
- 'Height' => '400'
- ) : array(
- 'ToolbarSet' => 'ForumStudent',
- 'Width' => '100%',
- 'Height' => '400',
- 'UserStatus' => 'student'
- )
- );
- $form->addRule('post_text', get_lang('ThisFieldIsRequired'), 'required');
- $form->addButtonAdvancedSettings('advanced_params');
- $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
- if (!isset($_GET['edit'])) {
- if (Gradebook::is_active()) {
- $form->addElement('label', '<strong>'.get_lang('AlterQualifyThread').'</strong>');
- $form->addElement('checkbox', 'thread_qualify_gradebook', '', get_lang('QualifyThreadGradebook'), 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"');
- $link_info = GradebookUtils::is_resource_in_course_gradebook(api_get_course_id(), 5, $_GET['thread'], api_get_session_id());
- if (!empty($link_info)) {
- $defaults['thread_qualify_gradebook'] = true;
- $defaults['category_id'] = $link_info['category_id'];
- } else {
- $defaults['thread_qualify_gradebook'] = false;
- $defaults['category_id'] = '';
- }
- } else {
- $form->addElement('hidden', 'thread_qualify_gradebook', false);
- $defaults['thread_qualify_gradebook'] = false;
- }
- if (!empty($defaults['thread_qualify_gradebook'])) {
- $form->addElement('html', '<div id="options_field" style="display:block">');
- } else {
- $form->addElement('html', '<div id="options_field" style="display:none">');
- }
-
- GradebookUtils::load_gradebook_select_in_tool($form);
- $form->addElement(
- 'text',
- 'numeric_calification',
- get_lang('QualificationNumeric'),
- array(
- 'value' => $current_thread['thread_qualify_max'],
- 'style' => 'width:40px',
- )
- );
- $form->applyFilter('numeric_calification', 'html_filter');
- $form->addElement(
- 'text',
- 'calification_notebook_title',
- get_lang('TitleColumnGradebook'),
- array('value' => $current_thread['thread_title_qualify'])
- );
- $form->applyFilter('calification_notebook_title', 'html_filter');
- $form->addElement(
- 'text',
- 'weight_calification',
- array(get_lang('QualifyWeight'), null, ''),
- array(
- 'value' => $current_thread['thread_weight'],
- 'style' => 'width:40px',
- )
- );
- $form->applyFilter('weight_calification', 'html_filter');
- $group = array();
- $group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('Yes'), 1);
- $group[] = $form->createElement('radio', 'thread_peer_qualify', null, get_lang('No'), 0);
- $form->addGroup(
- $group,
- '',
- [
- get_lang('ForumThreadPeerScoring'),
- get_lang('ForumThreadPeerScoringComment'),
- ],
- ' '
- );
- $form->addElement('html', '</div>');
- }
- if ($forum_setting['allow_post_notification']) {
- $form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail').' ('.$current_post['email'].')');
- }
- if ($forum_setting['allow_sticky'] &&
- api_is_allowed_to_edit(null, true) &&
- $current_post['post_parent_id'] == 0
- ) {
-
- $form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
- if ($current_thread['thread_sticky'] == 1) {
- $defaults['thread_sticky'] = true;
- }
- }
- if ($current_forum['allow_attachments'] == '1' || api_is_allowed_to_edit(null, true)) {
- if (empty($form_values) && !isset($_POST['SubmitPost'])) {
-
- }
- }
- $form->addElement('html', '</div>');
- $form->addFile('user_upload[]', get_lang('Attachment'));
- $form->addButton(
- 'add_attachment',
- get_lang('AddAttachment'),
- 'paperclip',
- 'default',
- 'default',
- null,
- ['id' => 'reply-add-attachment']
- );
- $form->addButtonUpdate(get_lang('ModifyThread'), 'SubmitPost');
-
- $defaults['post_title'] = $current_post['post_title'];
- $defaults['post_text'] = $current_post['post_text'];
- if ($current_post['post_notification'] == 1) {
- $defaults['post_notification'] = true;
- }
- if (!empty($form_values)) {
- $defaults['post_notification'] = Security::remove_XSS($form_values['post_notification']);
- $defaults['thread_sticky'] = Security::remove_XSS($form_values['thread_sticky']);
- }
- $defaults['thread_peer_qualify'] = intval($current_thread['thread_peer_qualify']);
- $form->setDefaults($defaults);
-
- $form->addRule('post_title', get_lang('ThisFieldIsRequired'), 'required');
-
- if ($form->validate()) {
- $values = $form->exportValues();
- if (isset($values['thread_qualify_gradebook']) && $values['thread_qualify_gradebook'] == '1' &&
- empty($values['weight_calification'])
- ) {
- Display::display_error_message(get_lang('YouMustAssignWeightOfQualification').' <a href="javascript:window.history.go(-1);">'.get_lang('Back').'</a>', false);
- return false;
- }
- return $values;
- } else {
-
- clearAttachedFiles($current_post['post_id']);
-
- $fileData = getAttachmentsAjaxTable($current_post['post_id'], $current_forum['forum_id']);
- $form->addElement('html', $fileData);
- $form->display();
- }
- }
- function store_edit_post($values)
- {
- $threadTable = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $gradebook = Security::remove_XSS($_GET['gradebook']);
- $course_id = api_get_course_int_id();
-
-
-
- $posts = getPosts($values['thread_id']);
- $first_post = null;
- if (!empty($posts)) {
- $first_post = $posts[0];
- }
- if (!empty($first_post) && $first_post['post_id'] == $values['post_id']) {
- $params = [
- 'thread_title' => $values['post_title'],
- 'thread_sticky' => isset($values['thread_sticky']) ? $values['thread_sticky'] : null,
- 'thread_title_qualify' => $values['calification_notebook_title'],
- 'thread_qualify_max' => $values['numeric_calification'],
- 'thread_weight' => $values['weight_calification'],
- 'thread_peer_qualify' => $values['thread_peer_qualify']
- ];
- $where = ['c_id = ? AND thread_id = ?' => [$course_id, $values['thread_id']]];
- Database::update($threadTable, $params, $where);
- }
-
- $params = [
- 'post_title' => $values['post_title'],
- 'post_text' => $values['post_text'],
- 'post_notification' => isset($values['post_notification']) ? $values['post_notification'] : ''
- ];
- $where = ['c_id = ? AND post_id = ?' => [$course_id, $values['post_id']]];
- Database::update($table_posts, $params, $where);
-
- if (!empty($_POST['file_ids']) && is_array($_POST['file_ids'])) {
- foreach ($_POST['file_ids'] as $key => $id) {
- editAttachedFile(array('comment' => $_POST['file_comments'][$key], 'post_id' => $values['post_id']), $id);
- }
- }
- if (!empty($values['remove_attach'])) {
- delete_attachment($values['post_id']);
- }
- if (empty($values['id_attach'])) {
- add_forum_attachment_file(
- isset($values['file_comment']) ? $values['file_comment'] : null,
- $values['post_id']
- );
- } else {
- edit_forum_attachment_file(
- isset($values['file_comment']) ? $values['file_comment'] : null,
- $values['post_id'],
- $values['id_attach']
- );
- }
- if (api_is_course_admin() == true) {
- $ccode = api_get_course_id();
- $sid = api_get_session_id();
- $link_info = GradebookUtils::is_resource_in_course_gradebook($ccode, 5, $values['thread_id'], $sid);
- $link_id = $link_info['id'];
- $thread_qualify_gradebook = isset($values['thread_qualify_gradebook']) ? $values['thread_qualify_gradebook'] : null;
- if ($thread_qualify_gradebook != 1) {
- if ($link_info !== false) {
- GradebookUtils::remove_resource_from_course_gradebook($link_id);
- }
- } else {
- if ($link_info === false && !$_GET['thread']) {
- $weigthqualify = $values['weight_calification'];
- GradebookUtils::add_resource_to_course_gradebook($values['category_id'], $ccode, 5, $values['thread_id'], Database::escape_string(stripslashes($values['calification_notebook_title'])), $weigthqualify, $values['numeric_calification'], null, 0, $sid);
- }
- }
- }
-
-
- $message = get_lang('EditPostStored').'<br />';
- $message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&">'.get_lang('Forum').'</a><br />';
- $message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&gradebook='.$gradebook.'&thread='.$values['thread_id'].'&post='.Security::remove_XSS($_GET['post']).'">'.get_lang('Message').'</a>';
- Session::erase('formelements');
- Session::erase('origin');
- Session::erase('breadcrumbs');
- Session::erase('addedresource');
- Session::erase('addedresourceid');
- Display :: display_confirmation_message($message, false);
- }
- function display_user_link($user_id, $name, $origin = '', $in_title = '')
- {
- if ($user_id != 0) {
- $userInfo = api_get_user_info($user_id);
- return '<a href="'.$userInfo['profile_url'].'">'.Security::remove_XSS($userInfo['complete_name']).'</a>';
- } else {
- return $name.' ('.get_lang('Anonymous').')';
- }
- }
- function display_user_image($user_id, $name, $origin = '')
- {
- $userInfo = api_get_user_info($user_id);
- $link = '<a href="'.$userInfo['profile_url'].'" '.(!empty($origin) ? 'target="_self"' : '').'>';
- if ($user_id != 0) {
- return $link.'<img src="'.$userInfo['avatar'].'" alt="'.$name.'" title="'.$name.'" /></a>';
- } else {
- return $link.'<img src="'.api_get_path(WEB_CODE_PATH)."img/unknown.jpg".'" alt="'.$name.'" title="'.$name.'" /></a>';
- }
- }
- function increase_thread_view($thread_id)
- {
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $course_id = api_get_course_int_id();
- $sql = "UPDATE $table_threads SET thread_views=thread_views+1
- WHERE c_id = $course_id AND thread_id='".Database::escape_string($thread_id)."'";
- Database::query($sql);
- }
- function update_thread($thread_id, $last_post_id, $post_date)
- {
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $course_id = api_get_course_int_id();
- $sql = "UPDATE $table_threads SET thread_replies=thread_replies+1,
- thread_last_post='".Database::escape_string($last_post_id)."',
- thread_date='".Database::escape_string($post_date)."'
- WHERE c_id = $course_id AND thread_id='".Database::escape_string($thread_id)."'";
- Database::query($sql);
- }
- function forum_not_allowed_here()
- {
- Display :: display_error_message(get_lang('NotAllowedHere'));
- Display :: display_footer();
- return false;
- }
- function get_whats_new()
- {
- $_user = api_get_user_info();
- $_course = api_get_course_info();
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $tracking_last_tool_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
-
-
- $tool = TOOL_FORUM;
-
-
-
- $course_id = api_get_course_int_id();
- $lastForumAccess = Session::read('last_forum_access');
- if (!$lastForumAccess) {
- $sql = "SELECT * FROM ".$tracking_last_tool_access."
- WHERE
- access_user_id='".Database::escape_string($_user['user_id'])."' AND
- c_id ='".$course_id."' AND
- access_tool='".Database::escape_string($tool)."'";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $_SESSION['last_forum_access'] = $row['access_date'];
- }
- $whatsNew = Session::read('whatsnew_post_info');
- if (!$whatsNew) {
- if ($lastForumAccess != '') {
- $whatsnew_post_info = array();
- $sql = "SELECT * FROM $table_posts
- WHERE
- c_id = $course_id AND
- post_date >'".Database::escape_string($_SESSION['last_forum_access'])."'";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- $whatsnew_post_info[$row['forum_id']][$row['thread_id']][$row['post_id']] = $row['post_date'];
- }
- $_SESSION['whatsnew_post_info'] = $whatsnew_post_info;
- }
- }
- }
- function get_post_topics_of_forum($forum_id)
- {
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $course_id = api_get_course_int_id();
- if (api_is_allowed_to_edit(null, true)) {
- $sql = "SELECT count(*) as number_of_posts
- FROM $table_posts posts, $table_threads threads, $table_item_property item_property
- WHERE
- posts.c_id = $course_id AND
- item_property.c_id = $course_id AND
- posts.forum_id='".Database::escape_string($forum_id)."'
- AND posts.thread_id=threads.thread_id
- AND item_property.ref=threads.thread_id
- AND item_property.visibility<>2
- AND item_property.tool='".TOOL_FORUM_THREAD."'
- ";
- } else {
- $sql = "SELECT count(*) as number_of_posts
- FROM $table_posts posts, $table_threads threads, $table_item_property item_property
- WHERE
- posts.c_id = $course_id AND
- item_property.c_id = $course_id AND
- posts.forum_id='".Database::escape_string($forum_id)."'
- AND posts.thread_id=threads.thread_id
- AND item_property.ref=threads.thread_id
- AND item_property.visibility=1
- AND posts.visible=1
- AND item_property.tool='".TOOL_FORUM_THREAD."'
- ";
- }
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $number_of_posts = $row['number_of_posts'];
-
- if (api_is_allowed_to_edit(null, true)) {
- $sql = "SELECT count(*) as number_of_topics
- FROM $table_threads threads, $table_item_property item_property
- WHERE
- threads.c_id = $course_id AND
- item_property.c_id = $course_id AND
- threads.forum_id='".Database::escape_string($forum_id)."'
- AND item_property.ref=threads.thread_id
- AND item_property.visibility<>2
- AND item_property.tool='".TOOL_FORUM_THREAD."'
- ";
- } else {
- $sql = "SELECT count(*) as number_of_topics
- FROM $table_threads threads, $table_item_property item_property
- WHERE
- threads.c_id = $course_id AND
- item_property.c_id = $course_id AND
- threads.forum_id='".Database::escape_string($forum_id)."'
- AND item_property.ref=threads.thread_id
- AND item_property.visibility=1
- AND item_property.tool='".TOOL_FORUM_THREAD."'
- ";
- }
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $number_of_topics = $row['number_of_topics'];
- if ($number_of_topics == '') {
- $number_of_topics = 0;
- }
- $return = array('number_of_topics' => $number_of_topics, 'number_of_posts' => $number_of_posts);
- return $return;
- }
- function approve_post($post_id, $action)
- {
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $course_id = api_get_course_int_id();
- if ($action == 'invisible') {
- $visibility_value = 0;
- }
- if ($action == 'visible') {
- $visibility_value = 1;
- handle_mail_cue('post', $post_id);
- }
- $sql = "UPDATE $table_posts SET
- visible='".Database::escape_string($visibility_value)."'
- WHERE c_id = $course_id AND post_id='".Database::escape_string($post_id)."'";
- $return = Database::query($sql);
- if ($return) {
- return 'PostVisibilityChanged';
- }
- }
- function get_unaproved_messages($forum_id)
- {
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $course_id = api_get_course_int_id();
- $return_array = array();
- $sql = "SELECT DISTINCT thread_id FROM $table_posts
- WHERE c_id = $course_id AND forum_id='".Database::escape_string($forum_id)."' AND visible='0'";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- $return_array[] = $row['thread_id'];
- }
- return $return_array;
- }
- function send_notification_mails($thread_id, $reply_info)
- {
- $table = Database::get_course_table(TABLE_FORUM_MAIL_QUEUE);
-
-
-
-
-
- $current_thread = get_thread_information($thread_id);
- $current_forum = get_forum_information($current_thread['forum_id']);
- $current_forum_category = null;
- if (isset($current_forum['forum_category'])) {
- $current_forum_category = get_forumcategory_information(
- $current_forum['forum_category']
- );
- }
- if ($current_thread['visibility'] == '1' &&
- $current_forum['visibility'] == '1' &&
- ($current_forum_category && $current_forum_category['visibility'] == '1') &&
- $current_forum['approval_direct_post'] != '1'
- ) {
- $send_mails = true;
- } else {
- $send_mails = false;
- }
-
- if ($send_mails) {
- if (isset($current_thread['forum_id'])) {
- send_notifications($current_thread['forum_id'], $thread_id);
- }
- } else {
- $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
- if (isset($current_forum['forum_id'])) {
- $sql = "SELECT * FROM $table_notification
- WHERE
- c_id = ".api_get_course_int_id()." AND
- (
- forum_id = '".intval($current_forum['forum_id'])."' OR
- thread_id = '".intval($thread_id)."'
- ) ";
- $result = Database::query($sql);
- $user_id = api_get_user_id();
- while ($row = Database::fetch_array($result)) {
- $sql = "INSERT INTO $table (c_id, thread_id, post_id, user_id)
- VALUES (".api_get_course_int_id().", '".intval($thread_id)."', '".intval($reply_info['new_post_id'])."', '$user_id' )";
- Database::query($sql);
- }
- }
- }
- }
- function handle_mail_cue($content, $id)
- {
- $table_mailcue = Database :: get_course_table(TABLE_FORUM_MAIL_QUEUE);
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $course_id = api_get_course_int_id();
-
- if ($content == 'post') {
-
- $post_info = get_post_information($id);
- $thread_id = intval($post_info['thread_id']);
-
- $sql = "SELECT users.firstname, users.lastname, users.user_id, users.email
- FROM $table_mailcue mailcue, $table_posts posts, $table_users users
- WHERE
- posts.c_id = $course_id AND
- mailcue.c_id = $course_id AND
- posts.thread_id='$thread_id'
- AND posts.post_notification='1'
- AND mailcue.thread_id='$thread_id'
- AND users.user_id=posts.poster_id
- AND users.active=1
- GROUP BY users.email";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- send_mail($row, get_thread_information($post_info['thread_id']));
- }
- } elseif ($content == 'thread') {
-
- $sql = "SELECT users.firstname, users.lastname, users.user_id, users.email
- FROM $table_mailcue mailcue, $table_posts posts, $table_users users
- WHERE
- posts.c_id = $course_id AND
- mailcue.c_id = $course_id AND
- posts.thread_id = ".intval($id)."
- AND posts.post_notification='1'
- AND mailcue.thread_id = ".intval($id)."
- AND users.user_id=posts.poster_id
- AND users.active=1
- GROUP BY users.email";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- send_mail($row, get_thread_information($id));
- }
-
- $sql = "DELETE FROM $table_mailcue
- WHERE c_id = $course_id AND thread_id='".Database::escape_string($id)."'";
- Database::query($sql);
- } elseif ($content == 'forum') {
- $sql = "SELECT thread_id FROM $table_threads
- WHERE c_id = $course_id AND forum_id='".Database::escape_string($id)."'";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- handle_mail_cue('thread', $row['thread_id']);
- }
- } elseif ($content == 'forum_category') {
- $sql = "SELECT forum_id FROM $table_forums
- WHERE c_id = $course_id AND forum_category ='".Database::escape_string($id)."'";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- handle_mail_cue('forum', $row['forum_id']);
- }
- } else {
- return get_lang('Error');
- }
- }
- function send_mail($user_info = array(), $thread_information = array())
- {
- $_course = api_get_course_info();
- $user_id = api_get_user_id();
- $subject = get_lang('NewForumPost').' - '.$_course['official_code'];
- if (isset($thread_information) && is_array($thread_information)) {
- $thread_link = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$thread_information['forum_id'].'&thread='.$thread_information['thread_id'];
- }
- $email_body = get_lang('Dear').' '.api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS).", <br />\n\r";
- $email_body .= get_lang('NewForumPost')."\n";
- $email_body .= get_lang('Course').': '.$_course['name'].' - ['.$_course['official_code']."] - <br />\n";
- $email_body .= get_lang('YouWantedToStayInformed')."<br />\n";
- $email_body .= get_lang('ThreadCanBeFoundHere')." : <br /><a href=\"".$thread_link."\">".$thread_link."</a>\n";
- if ($user_info['user_id'] <> $user_id) {
- MessageManager::send_message($user_info['user_id'], $subject, $email_body, null, null, null, null, null, null, $user_id);
- }
- }
- function move_thread_form()
- {
- $gradebook = Security::remove_XSS($_GET['gradebook']);
-
- $form = new FormValidator('movepost', 'post', api_get_self().'?forum='.Security::remove_XSS($_GET['forum']).'&gradebook='.$gradebook.'&thread='.Security::remove_XSS($_GET['thread']).'&action='.Security::remove_XSS($_GET['action']).'&'.api_get_cidreq());
-
- $form->addElement('header', '', get_lang('MoveThread'));
-
- $form->addElement('hidden', 'thread_id', intval($_GET['thread']));
-
- $forum_categories = get_forum_categories();
- $forums = get_forums();
- $htmlcontent = '<div class="row">
- <div class="label">
- <span class="form_required">*</span>'.get_lang('MoveTo').'
- </div>
- <div class="formw">';
- $htmlcontent .= '<select name="forum">';
- foreach ($forum_categories as $key => $category) {
- $htmlcontent .= '<optgroup label="'.$category['cat_title'].'">';
- foreach ($forums as $key => $forum) {
- if ($forum['forum_category'] == $category['cat_id']) {
- $htmlcontent .= '<option value="'.$forum['forum_id'].'">'.$forum['forum_title'].'</option>';
- }
- }
- $htmlcontent .= '</optgroup>';
- }
- $htmlcontent .= "</select>";
- $htmlcontent .= ' </div>
- </div>';
- $form->addElement('html', $htmlcontent);
-
- $form->addButtonSave(get_lang('MoveThread'), 'SubmitForum');
-
- if ($form->validate()) {
- $values = $form->exportValues();
- if (isset($_POST['forum'])) {
- store_move_thread($values);
- }
- } else {
- $form->display();
- }
- }
- function move_post_form()
- {
- $gradebook = Security::remove_XSS($_GET['gradebook']);
-
- $form = new FormValidator('movepost', 'post', api_get_self().'?'.api_get_cidreq().'&forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&gradebook='.$gradebook.'&post='.Security::remove_XSS($_GET['post']).'&action='.Security::remove_XSS($_GET['action']).'&post='.Security::remove_XSS($_GET['post']));
-
- $form->addElement('header', '', get_lang('MovePost'));
-
- $form->addElement('hidden', 'post_id', intval($_GET['post']));
-
- $threads = get_threads($_GET['forum']);
-
- $threads_list[0] = get_lang('ANewThread');
- foreach ($threads as $key => $value) {
- $threads_list[$value['thread_id']] = $value['thread_title'];
- }
- $form->addElement('select', 'thread', get_lang('MoveToThread'), $threads_list);
- $form->applyFilter('thread', 'html_filter');
-
- $form->addButtonSave(get_lang('MovePost'), 'submit');
-
- $form->addRule('thread', get_lang('ThisFieldIsRequired'), 'required');
-
- if ($form->validate()) {
- $values = $form->exportValues();
- store_move_post($values);
- } else {
- $form->display();
- }
- }
- function store_move_post($values)
- {
- $_course = api_get_course_info();
- $course_id = api_get_course_int_id();
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- if ($values['thread'] == '0') {
- $current_post = get_post_information($values['post_id']);
-
- $params = [
- 'c_id' => $course_id,
- 'thread_title' => $current_post['post_title'],
- 'forum_id' => $current_post['forum_id'],
- 'thread_poster_id' => $current_post['poster_id'],
- 'thread_poster_name' => $current_post['poster_name'],
- 'thread_last_post' => $values['post_id'],
- 'thread_date' => $current_post['post_date'],
- ];
- $new_thread_id = Database::insert($table_threads, $params);
- api_item_property_update(
- $_course,
- TOOL_FORUM_THREAD,
- $new_thread_id,
- 'visible',
- $current_post['poster_id']
- );
-
- $sql = "UPDATE $table_posts SET thread_id='".intval($new_thread_id)."', post_parent_id='0'
- WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'";
- Database::query($sql);
-
- $sql = "UPDATE $table_posts SET post_parent_id='0'
- WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'";
- Database::query($sql);
-
- $sql = "UPDATE $table_forums SET forum_threads=forum_threads+1
- WHERE c_id = $course_id AND forum_id='".intval($current_post['forum_id'])."'";
- Database::query($sql);
-
- $sql = "SELECT * FROM $table_posts
- WHERE c_id = $course_id AND thread_id='".intval($current_post['thread_id'])."'
- ORDER BY post_id DESC";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $sql = "UPDATE $table_threads SET
- thread_last_post='".$row['post_id']."',
- thread_replies=thread_replies-1
- WHERE
- c_id = $course_id AND
- thread_id='".intval($current_post['thread_id'])."'";
- Database::query($sql);
- } else {
-
- $sql = "SELECT thread_id FROM ".$table_posts."
- WHERE c_id = $course_id AND post_id = '".$values['post_id']."' ";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $original_thread_id = $row['thread_id'];
- $sql = "SELECT thread_last_post FROM ".$table_threads."
- WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' ";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $thread_is_last_post = $row['thread_last_post'];
-
- if ($thread_is_last_post == $values['post_id']) {
- $sql = "SELECT post_id FROM ".$table_posts."
- WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' AND post_id <> '".$values['post_id']."'
- ORDER BY post_date DESC LIMIT 1";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- $thread_new_last_post = $row['post_id'];
- $sql = "UPDATE ".$table_threads." SET thread_last_post = '".$thread_new_last_post."'
- WHERE c_id = $course_id AND thread_id = '".$original_thread_id."' ";
- Database::query($sql);
- }
- $sql = "UPDATE $table_threads SET thread_replies=thread_replies-1
- WHERE c_id = $course_id AND thread_id='".$original_thread_id."'";
- Database::query($sql);
-
- $sql = "UPDATE $table_posts SET thread_id='".intval($_POST['thread'])."', post_parent_id='0'
- WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'";
- Database::query($sql);
-
- $sql = "UPDATE $table_posts SET post_parent_id='0'
- WHERE c_id = $course_id AND post_parent_id='".intval($values['post_id'])."'";
- Database::query($sql);
- $sql = "UPDATE $table_threads SET thread_replies=thread_replies+1
- WHERE c_id = $course_id AND thread_id='".intval($_POST['thread'])."'";
- Database::query($sql);
- }
- return get_lang('ThreadMoved');
- }
- function store_move_thread($values)
- {
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $course_id = api_get_course_int_id();
-
- $sql = "UPDATE $table_threads SET forum_id='".Database::escape_string($_POST['forum'])."'
- WHERE c_id = $course_id AND thread_id='".Database::escape_string($_POST['thread_id'])."'";
- Database::query($sql);
-
- $sql = "UPDATE $table_posts SET forum_id='".Database::escape_string($_POST['forum'])."'
- WHERE c_id = $course_id AND thread_id='".Database::escape_string($_POST['thread_id'])."'";
- Database::query($sql);
- return get_lang('ThreadMoved');
- }
- function prepare4display($input)
- {
- static $highlightcolors = array('yellow', '#33CC33', '#3399CC', '#9999FF', '#33CC33');
- static $search;
- if (!isset($search)) {
- if (isset($_POST['search_term'])) {
- $search = $_POST['search_term'];
- } elseif (isset($_GET['search'])) {
- $search = $_GET['search'];
- } else {
- $search = '';
- }
- }
- if (!empty($search)) {
- if (strstr($search, '+')) {
- $search_terms = explode('+', $search);
- } else {
- $search_terms[] = trim($search);
- }
- $counter = 0;
- foreach ($search_terms as $key => $search_term) {
- $input = api_preg_replace('/'.preg_quote(trim($search_term), '/').'/i', '<span style="background-color: '.$highlightcolors[$counter].'">$0</span>', $input);
- $counter++;
- }
- }
-
-
- return Security::remove_XSS($input, STUDENT, true);
- }
- function forum_search()
- {
-
- $form = new FormValidator('forumsearch', 'post', 'forumsearch.php?'.api_get_cidreq());
-
- $form->addElement('header', '', get_lang('ForumSearch'));
- $form->addElement('text', 'search_term', get_lang('SearchTerm'), array('autofocus'));
- $form->applyFilter('search_term', 'html_filter');
- $form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation'));
- $form->addButtonSearch(get_lang('Search'));
-
- $form->addRule('search_term', get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('search_term', get_lang('TooShort'), 'minlength', 3);
-
- if ($form->validate()) {
- $values = $form->exportValues();
- $form->setDefaults($values);
- $form->display();
-
- display_forum_search_results(stripslashes($values['search_term']));
- } else {
- $form->display();
- }
- }
- function display_forum_search_results($search_term)
- {
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $session_id = api_get_session_id();
- $gradebook = Security::remove_XSS($_GET['gradebook']);
- $course_id = api_get_course_int_id();
-
- if (strstr($search_term, '+')) {
- $search_terms = explode('+', $search_term);
- } else {
- $search_terms[] = $search_term;
- }
-
- foreach ($search_terms as $value) {
- $search_restriction[] = "
- (posts.post_title LIKE '%".Database::escape_string(trim($value))."%'
- OR posts.post_text LIKE '%".Database::escape_string(trim($value))."%')";
- }
- $sql = "SELECT posts.*
- FROM $table_posts posts, $table_threads threads, $table_item_property item_property
- WHERE
- posts.c_id = $course_id
- AND item_property.c_id = $course_id
- AND posts.thread_id = threads.thread_id
- AND item_property.ref = threads.thread_id
- AND item_property.visibility = 1
- AND item_property.session_id = $session_id
- AND posts.visible = 1
- AND item_property.tool = '".TOOL_FORUM_THREAD."'
- AND ".implode(' AND ', $search_restriction)."
- GROUP BY posts.post_id";
-
- $forum_categories_list = get_forum_categories();
-
- $forum_list = get_forums();
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $display_result = false;
-
- if (!api_is_allowed_to_edit(null, true)) {
- if ($forum_categories_list[$forum_list[$row['forum_id']]['forum_category']]['visibility'] == '1' AND
- $forum_list[$row['forum_id']]['visibility'] == '1' AND $row['visible'] == '1'
- ) {
- $display_result = true;
- }
- } else {
- $display_result = true;
- }
- if ($display_result) {
- $search_results_item = '<li><a href="viewforumcategory.php?'.api_get_cidreq().'&forumcategory='.$forum_list[$row['forum_id']]['forum_category'].'&search='.urlencode($search_term).'">'.
- prepare4display($forum_categories_list[$row['forum_id']['forum_category']]['cat_title']).'</a> > ';
- $search_results_item .= '<a href="viewforum.php?'.api_get_cidreq().'&forum='.$row['forum_id'].'&search='.urlencode($search_term).'">'.
- prepare4display($forum_list[$row['forum_id']]['forum_title']).'</a> > ';
-
- $search_results_item .= '<a href="viewthread.php?'.api_get_cidreq().'&forum='.$row['forum_id'].'&gradebook='.$gradebook.'&thread='.$row['thread_id'].'&search='.urlencode($search_term).'">'.
- prepare4display($row['post_title']).'</a>';
- $search_results_item .= '<br />';
- if (api_strlen($row['post_title']) > 200) {
- $search_results_item .= prepare4display(api_substr(strip_tags($row['post_title']), 0, 200)).'...';
- } else {
- $search_results_item .= prepare4display($row['post_title']);
- }
- $search_results_item .= '</li>';
- $search_results[] = $search_results_item;
- }
- }
- echo '<legend>'.count($search_results).' '.get_lang('ForumSearchResults').'</legend>';
- echo '<ol>';
- if ($search_results) {
- echo implode($search_results);
- }
- echo '</ol>';
- }
- function search_link()
- {
- $return = '';
- $origin = api_get_origin();
- if ($origin != 'learnpath') {
- $return = '<a href="forumsearch.php?'.api_get_cidreq().'&action=search"> ';
- $return .= Display::return_icon('search.png', get_lang('Search'), '', ICON_SIZE_MEDIUM).'</a>';
- if (!empty($_GET['search'])) {
- $return .= ': '.Security::remove_XSS($_GET['search']).' ';
- $url = api_get_self().'?';
- $url_parameter = array();
- foreach ($_GET as $key => $value) {
- if ($key != 'search') {
- $url_parameter[] = Security::remove_XSS($key).'='.Security::remove_XSS($value);
- }
- }
- $url = $url.implode('&', $url_parameter);
- $return .= '<a href="'.$url.'">'.Display::return_icon('delete.gif', get_lang('RemoveSearchResults')).'</a>';
- }
- }
- return $return;
- }
- function add_forum_attachment_file($file_comment, $last_id)
- {
- $_course = api_get_course_info();
- $agenda_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
- if (!isset($_FILES['user_upload'])) {
- return false;
- }
- $fileCount = count($_FILES['user_upload']['name']);
- $filesData = [];
- if (!is_array($_FILES['user_upload']['name'])) {
- $filesData[] = $_FILES['user_upload'];
- } else {
- $fileKeys = array_keys($_FILES['user_upload']);
- for ($i = 0; $i < $fileCount; $i++) {
- foreach ($fileKeys as $key) {
- $filesData[$i][$key] = $_FILES['user_upload'][$key][$i];
- }
- }
- }
- foreach ($filesData as $attachment) {
- if (empty($attachment['name'])) {
- continue;
- }
- $upload_ok = process_uploaded_file($attachment);
- if (!$upload_ok) {
- continue;
- }
- $course_dir = $_course['path'] . '/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path . $course_dir;
-
- $new_file_name = add_ext_on_mime(
- stripslashes($attachment['name']),
- $attachment['type']
- );
-
- $file_name = $attachment['name'];
- if (!filter_extension($new_file_name)) {
- Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
- return;
- }
- $new_file_name = uniqid('');
- $new_path = $updir . '/' . $new_file_name;
- $result = @move_uploaded_file($attachment['tmp_name'], $new_path);
- $safe_file_comment = Database::escape_string($file_comment);
- $safe_file_name = Database::escape_string($file_name);
- $safe_new_file_name = Database::escape_string($new_file_name);
- $last_id = intval($last_id);
-
- if (!$result) {
- return;
- }
- $last_id_file = Database::insert(
- $agenda_forum_attachment,
- [
- 'c_id' => api_get_course_int_id(),
- 'filename' => $safe_file_name,
- 'comment' => $safe_file_comment,
- 'path' => $safe_new_file_name,
- 'post_id' => $last_id,
- 'size' => intval($attachment['size'])
- ]
- );
- api_item_property_update(
- $_course,
- TOOL_FORUM_ATTACH,
- $last_id_file,
- 'ForumAttachmentAdded',
- api_get_user_id()
- );
- }
- }
- function edit_forum_attachment_file($file_comment, $post_id, $id_attach)
- {
- $_course = api_get_course_info();
- $table_forum_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
- $course_id = api_get_course_int_id();
- $fileCount = count($_FILES['user_upload']['name']);
- $filesData = [];
- if (!is_array($_FILES['user_upload']['name'])) {
- $filesData[] = $_FILES['user_upload'];
- } else {
- $fileKeys = array_keys($_FILES['user_upload']);
- for ($i = 0; $i < $fileCount; $i++) {
- foreach ($fileKeys as $key) {
- $filesData[$i][$key] = $_FILES['user_upload'][$key][$i];
- }
- }
- }
- foreach ($filesData as $attachment) {
- if (empty($attachment['name'])) {
- continue;
- }
- $upload_ok = process_uploaded_file($attachment);
- if (!$upload_ok) {
- continue;
- }
- $course_dir = $_course['path'].'/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$course_dir;
-
- $new_file_name = add_ext_on_mime(stripslashes($attachment['name']), $attachment['type']);
-
- $file_name = $attachment['name'];
- if (!filter_extension($new_file_name)) {
- Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
- } else {
- $new_file_name = uniqid('');
- $new_path = $updir.'/'.$new_file_name;
- $result = @move_uploaded_file($attachment['tmp_name'], $new_path);
- $safe_file_comment = Database::escape_string($file_comment);
- $safe_file_name = Database::escape_string($file_name);
- $safe_new_file_name = Database::escape_string($new_file_name);
- $safe_post_id = (int) $post_id;
- $safe_id_attach = (int) $id_attach;
-
- if ($result) {
- $sql = "UPDATE $table_forum_attachment SET filename = '$safe_file_name', comment = '$safe_file_comment', path = '$safe_new_file_name', post_id = '$safe_post_id', size ='".$attachment['size']."'
- WHERE c_id = $course_id AND id = '$safe_id_attach'";
- Database::query($sql);
- api_item_property_update($_course, TOOL_FORUM_ATTACH, $safe_id_attach, 'ForumAttachmentUpdated', api_get_user_id());
- }
- }
- }
- }
- function get_attachment($post_id)
- {
- $forum_table_attachment = Database :: get_course_table(TABLE_FORUM_ATTACHMENT);
- $course_id = api_get_course_int_id();
- $row = array();
- $post_id = intval($post_id);
- $sql = "SELECT iid, path, filename,comment FROM $forum_table_attachment
- WHERE c_id = $course_id AND post_id = $post_id";
- $result = Database::query($sql);
- if (Database::num_rows($result) != 0) {
- $row = Database::fetch_array($result);
- }
- return $row;
- }
- function getAllAttachment($postId)
- {
- $forumAttachmentTable = Database :: get_course_table(TABLE_FORUM_ATTACHMENT);
- $courseId = api_get_course_int_id();
- $postId = intval($postId);
- $columns = array('iid', 'path', 'filename', 'comment');
- $conditions = array(
- 'where' => array(
- 'c_id = ? AND post_id = ?' => array($courseId, $postId)
- )
- );
- $array = Database::select(
- $columns,
- $forumAttachmentTable,
- $conditions,
- 'all',
- 'ASSOC'
- );
- return $array;
- }
- function delete_attachment($post_id, $id_attach = 0, $display = true)
- {
- $_course = api_get_course_info();
- $forum_table_attachment = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
- $course_id = api_get_course_int_id();
- $cond = (!empty($id_attach)) ? " iid = " . (int) $id_attach . "" : " post_id = " . (int) $post_id . "";
- $sql = "SELECT path FROM $forum_table_attachment WHERE c_id = $course_id AND $cond";
- $res = Database::query($sql);
- $row = Database::fetch_array($res);
- $course_dir = $_course['path'] . '/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path . $course_dir;
- $my_path = isset($row['path']) ? $row['path'] : null;
- $file = $updir . '/' . $my_path;
- if (Security::check_abs_path($file, $updir)) {
- @unlink($file);
- }
-
- $sql = "DELETE FROM $forum_table_attachment WHERE c_id = $course_id AND $cond ";
- $result = Database::query($sql);
- if ($result !== false) {
- $affectedRows = Database::affected_rows($result);
- } else {
- $affectedRows = 0;
- }
-
- api_item_property_update($_course, TOOL_FORUM_ATTACH, $id_attach, 'ForumAttachmentDelete', api_get_user_id());
- if (!empty($result) && !empty($id_attach) && $display) {
- $message = get_lang(get_lang('AttachmentFileDeleteSuccess'));
- Display::display_confirmation_message($message);
- }
- return $affectedRows;
- }
- function get_forums_of_group($group_id)
- {
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $course_id = api_get_course_int_id();
-
-
- $sql = "SELECT * FROM ".$table_forums." forum , ".$table_item_property." item_properties
- WHERE
- forum.forum_of_group = '".Database::escape_string($group_id)."' AND
- forum.c_id = $course_id AND
- item_properties.c_id = $course_id AND
- forum.forum_id = item_properties.ref AND
- item_properties.visibility = 1 AND
- item_properties.tool = '".TOOL_FORUM."'
- ORDER BY forum.forum_order ASC";
-
- $sql2 = "SELECT count(thread_id) AS number_of_threads, threads.forum_id
- FROM $table_threads threads, ".$table_item_property." item_properties
- WHERE
- threads.thread_id = item_properties.ref AND
- threads.c_id = $course_id AND
- item_properties.c_id = $course_id AND
- item_properties.visibility = 1 AND
- item_properties.tool='".TOOL_FORUM_THREAD."'
- GROUP BY threads.forum_id";
-
- $sql3 = "SELECT count(post_id) AS number_of_posts, posts.forum_id
- FROM $table_posts posts, $table_threads threads, ".$table_item_property." item_properties
- WHERE posts.visible=1 AND
- posts.c_id = $course_id AND
- item_properties.c_id = $course_id AND
- threads.c_id = $course_id
- AND posts.thread_id=threads.thread_id
- AND threads.thread_id=item_properties.ref
- AND item_properties.visibility = 1
- AND item_properties.tool='".TOOL_FORUM_THREAD."'
- GROUP BY threads.forum_id";
-
- if (api_is_allowed_to_edit()) {
-
- $sql = "SELECT *
- FROM ".$table_forums." forum , ".$table_item_property." item_properties
- WHERE
- forum.forum_of_group = '".Database::escape_string($group_id)."' AND
- forum.c_id = $course_id AND
- item_properties.c_id = $course_id AND
- forum.forum_id = item_properties.ref AND
- item_properties.visibility <> 2 AND
- item_properties.tool = '".TOOL_FORUM."'
- ORDER BY forum_order ASC";
-
- $sql2 = "SELECT count(thread_id) AS number_of_threads, threads.forum_id
- FROM $table_threads threads, ".$table_item_property." item_properties
- WHERE
- threads.thread_id=item_properties.ref AND
- threads.c_id = $course_id AND
- item_properties.c_id = $course_id AND
- item_properties.visibility <> 2 AND
- item_properties.tool='".TOOL_FORUM_THREAD."'
- GROUP BY threads.forum_id";
-
- $sql3 = "SELECT count(post_id) AS number_of_posts, forum_id
- FROM $table_posts
- WHERE c_id = $course_id GROUP BY forum_id";
- }
-
- $result = Database::query($sql);
- $forum_list = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $forum_list[$row['forum_id']] = $row;
- }
-
- $result2 = Database::query($sql2);
- while ($row2 = Database::fetch_array($result2, 'ASSOC')) {
- if (is_array($forum_list)) {
- if (array_key_exists($row2['forum_id'], $forum_list)) {
- $forum_list[$row2['forum_id']]['number_of_threads'] = $row2['number_of_threads'];
- }
- }
- }
-
- $result3 = Database::query($sql3);
- while ($row3 = Database::fetch_array($result3, 'ASSOC')) {
- if (is_array($forum_list)) {
- if (array_key_exists($row3['forum_id'], $forum_list)) {
-
- $forum_list[$row3['forum_id']]['number_of_posts'] = $row3['number_of_posts'];
- }
- }
- }
-
- if (!empty($forum_list)) {
- foreach ($forum_list as $key => $value) {
- $last_post_info_of_forum = get_last_post_information($key, api_is_allowed_to_edit());
- $forum_list[$key]['last_post_id'] = $last_post_info_of_forum['last_post_id'];
- $forum_list[$key]['last_poster_id'] = $last_post_info_of_forum['last_poster_id'];
- $forum_list[$key]['last_post_date'] = $last_post_info_of_forum['last_post_date'];
- $forum_list[$key]['last_poster_name'] = $last_post_info_of_forum['last_poster_name'];
- $forum_list[$key]['last_poster_lastname'] = $last_post_info_of_forum['last_poster_lastname'];
- $forum_list[$key]['last_poster_firstname'] = $last_post_info_of_forum['last_poster_firstname'];
- }
- }
- return $forum_list;
- }
- function set_notification($content, $id, $add_only = false)
- {
- $_user = api_get_user_info();
-
- $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
- $course_id = api_get_course_int_id();
-
- if ($content == 'forum') {
- $database_field = 'forum_id';
- } else {
- $database_field = 'thread_id';
- }
-
- $sql = "SELECT * FROM $table_notification
- WHERE
- c_id = $course_id AND
- $database_field = '".Database::escape_string($id)."' AND
- user_id = '".intval($_user['user_id'])."'";
- $result = Database::query($sql);
- $total = Database::num_rows($result);
-
-
- if ($total <= 0) {
- $sql = "INSERT INTO $table_notification (c_id, $database_field, user_id)
- VALUES (".$course_id.", '".Database::escape_string($id)."','".intval($_user['user_id'])."')";
- $result = Database::query($sql);
- Session::erase('forum_notification');
- get_notifications_of_user(0, true);
- return get_lang('YouWillBeNotifiedOfNewPosts');
- } else {
- if (!$add_only) {
- $sql = "DELETE FROM $table_notification
- WHERE
- c_id = $course_id AND
- $database_field = '".Database::escape_string($id)."' AND
- user_id = '".intval($_user['user_id'])."'";
- Database::query($sql);
- Session::erase('forum_notification');
- get_notifications_of_user(0, true);
- return get_lang('YouWillNoLongerBeNotifiedOfNewPosts');
- }
- }
- }
- function get_notifications($content, $id)
- {
-
- $table_users = Database::get_main_table(TABLE_MAIN_USER);
- $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
- $course_id = api_get_course_int_id();
-
- if ($content == 'forum') {
- $database_field = 'forum_id';
- } else {
- $database_field = 'thread_id';
- }
- $sql = "SELECT user.user_id, user.firstname, user.lastname, user.email, user.user_id user
- FROM $table_users user, $table_notification notification
- WHERE notification.c_id = $course_id AND user.active = 1 AND
- user.user_id = notification.user_id AND
- notification.$database_field= '".Database::escape_string($id)."'";
- $result = Database::query($sql);
- $return = array();
- while ($row = Database::fetch_array($result)) {
- $return['user'.$row['user_id']] = array('email' => $row['email'], 'user_id' => $row['user_id']);
- }
- return $return;
- }
- function send_notifications($forum_id = 0, $thread_id = 0, $post_id = 0)
- {
- $_course = api_get_course_info();
-
- $thread_link = api_get_path(WEB_CODE_PATH).'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum_id.'&thread='.$thread_id;
-
- if ($forum_id != 0) {
- $users_to_be_notified_by_forum = get_notifications('forum', $forum_id);
- } else {
- return false;
- }
- $current_thread = get_thread_information($thread_id);
- $current_forum = get_forum_information($current_thread['forum_id']);
- $subject = get_lang('NewForumPost').' - '.$_course['official_code'].' - '.$current_forum['forum_title'].' - '.$current_thread['thread_title'];
-
- if ($thread_id != 0) {
- $users_to_be_notified_by_thread = get_notifications('thread', $thread_id);
- }
-
- $users_to_be_notified = array_merge($users_to_be_notified_by_forum, $users_to_be_notified_by_thread);
- $sender_id = api_get_user_id();
- if (is_array($users_to_be_notified)) {
- foreach ($users_to_be_notified as $value) {
- $user_info = api_get_user_info($value['user_id']);
- $email_body = get_lang('Dear').' '.api_get_person_name($user_info['firstname'], $user_info['lastname'], null, PERSON_NAME_EMAIL_ADDRESS).", <br />\n\r";
- $email_body .= get_lang('NewForumPost').": ".$current_forum['forum_title'].' - '.$current_thread['thread_title']." <br />\n";
- $email_body .= get_lang('Course').': '.$_course['name'].' - ['.$_course['official_code']."] <br />\n";
- $email_body .= get_lang('YouWantedToStayInformed')."<br />\n";
- $email_body .= get_lang('ThreadCanBeFoundHere').': <br /> <a href="'.$thread_link.'">'.$thread_link."</a>\n";
- MessageManager::send_message_simple(
- $value['user_id'], $subject, $email_body, $sender_id
- );
- }
- }
- }
- function get_notifications_of_user($user_id = 0, $force = false)
- {
-
- $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
- $course_id = api_get_course_int_id();
- if (empty($course_id) || $course_id == -1) {
- return null;
- }
- if ($user_id == 0) {
- $user_id = api_get_user_id();
- }
- if (!isset($_SESSION['forum_notification']) ||
- $_SESSION['forum_notification']['course'] != $course_id ||
- $force = true
- ) {
- $_SESSION['forum_notification']['course'] = $course_id;
- $sql = "SELECT * FROM $table_notification
- WHERE c_id = $course_id AND user_id='".intval($user_id)."'";
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- if (!is_null($row['forum_id'])) {
- $_SESSION['forum_notification']['forum'][] = $row['forum_id'];
- }
- if (!is_null($row['thread_id'])) {
- $_SESSION['forum_notification']['thread'][] = $row['thread_id'];
- }
- }
- }
- }
- function count_number_of_post_in_thread($thread_id)
- {
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $course_id = api_get_course_int_id();
- if (empty($course_id)) {
- return 0;
- }
- $sql = "SELECT * FROM $table_posts
- WHERE c_id = $course_id AND thread_id='".intval($thread_id)."' ";
- $result = Database::query($sql);
- return count(Database::store_result($result));
- }
- function count_number_of_post_for_user_thread($thread_id, $user_id)
- {
- $table_posts = Database::get_course_table(TABLE_FORUM_POST);
- $course_id = api_get_course_int_id();
- $sql = "SELECT count(*) as count FROM $table_posts
- WHERE c_id = $course_id AND
- thread_id=".intval($thread_id)." AND
- poster_id = ".intval($user_id)." AND visible = 1 ";
- $result = Database::query($sql);
- $count = 0;
- if (Database::num_rows($result) > 0) {
- $count = Database::fetch_array($result);
- $count = $count['count'];
- }
- return $count;
- }
- function count_number_of_user_in_course($course_id)
- {
- $table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
- $sql = "SELECT * FROM $table
- WHERE c_id ='".intval($course_id)."' ";
- $result = Database::query($sql);
- return count(Database::store_result($result));
- }
- function get_statistical_information($thread_id, $user_id, $course_id)
- {
- $result = array();
- $result['user_course'] = count_number_of_user_in_course($course_id);
- $result['post'] = count_number_of_post_in_thread($thread_id);
- $result['user_post'] = count_number_of_post_for_user_thread($thread_id, $user_id);
- return $result;
- }
- function get_thread_user_post($course_code, $thread_id, $user_id)
- {
- $table_posts = Database::get_course_table(TABLE_FORUM_POST);
- $table_users = Database::get_main_table(TABLE_MAIN_USER);
- $thread_id = intval($thread_id);
- $user_id = intval($user_id);
- $course_info = api_get_user_info($course_code);
- $course_id = $course_info['real_id'];
- if (empty($course_id)) {
- $course_id = api_get_course_int_id();
- }
- $sql = "SELECT * FROM $table_posts posts
- LEFT JOIN $table_users users
- ON posts.poster_id=users.user_id
- WHERE
- posts.c_id = $course_id AND
- posts.thread_id='$thread_id'
- AND posts.poster_id='$user_id'
- ORDER BY posts.post_id ASC";
- $result = Database::query($sql);
- $post_list = array();
- while ($row = Database::fetch_array($result)) {
- $row['status'] = '1';
- $post_list[] = $row;
- $sql = "SELECT * FROM $table_posts posts
- LEFT JOIN $table_users users
- ON posts.poster_id=users.user_id
- WHERE
- posts.c_id = $course_id AND
- posts.thread_id='$thread_id'
- AND posts.post_parent_id='".$row['post_id']."'
- ORDER BY posts.post_id ASC";
- $result2 = Database::query($sql);
- while ($row2 = Database::fetch_array($result2)) {
- $row2['status'] = '0';
- $post_list[] = $row2;
- }
- }
- return $post_list;
- }
- function get_name_thread_by_id($thread_id)
- {
- $t_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD);
- $course_id = api_get_course_int_id();
- $sql = "SELECT thread_title FROM ".$t_forum_thread."
- WHERE c_id = $course_id AND thread_id = '".intval($thread_id)."' ";
- $result = Database::query($sql);
- $row = Database::fetch_array($result);
- return $row[0];
- }
- function get_all_post_from_user($user_id, $course_code)
- {
- $j = 0;
- $forums = get_forums('', $course_code);
- krsort($forums);
- $forum_results = '';
- foreach ($forums as $forum) {
- if ($forum['visibility'] == 0) {
- continue;
- }
- if ($j <= 4) {
- $threads = get_threads($forum['forum_id'], $course_code);
- if (is_array($threads)) {
- $i = 0;
- $hand_forums = '';
- $post_counter = 0;
- foreach ($threads as $thread) {
- if ($thread['visibility'] == 0) {
- continue;
- }
- if ($i <= 4) {
- $post_list = get_thread_user_post_limit($course_code, $thread['thread_id'], $user_id, 1);
- $post_counter = count($post_list);
- if (is_array($post_list) && count($post_list) > 0) {
- $hand_forums.= '<div id="social-thread">';
- $hand_forums.= Display::return_icon('thread.png', get_lang('Thread'), '', ICON_SIZE_MEDIUM);
- $hand_forums.= ' '.Security::remove_XSS($thread['thread_title'], STUDENT);
- $hand_forums.= '</div>';
- foreach ($post_list as $posts) {
- $hand_forums.= '<div id="social-post">';
- $hand_forums.= '<strong>'.Security::remove_XSS($posts['post_title'], STUDENT).'</strong>';
- $hand_forums.= '<br / >';
- $hand_forums.= Security::remove_XSS($posts['post_text'], STUDENT);
- $hand_forums.= '</div>';
- $hand_forums.= '<br / >';
- }
- }
- }
- $i++;
- }
- $forum_results .='<div id="social-forum">';
- $forum_results .='<div class="clear"></div><br />';
- $forum_results .='<div id="social-forum-title">'.
- Display::return_icon('forum.gif', get_lang('Forum')).' '.Security::remove_XSS($forum['forum_title'], STUDENT).
- '<div style="float:right;margin-top:-35px">
- <a href="../forum/viewforum.php?cidReq='.$course_code.'&gidReq=&forum='.$forum['forum_id'].' " >'.get_lang('SeeForum').'</a>
- </div></div>';
- $forum_results .='<br / >';
- if ($post_counter > 0) {
- $forum_results .=$hand_forums;
- }
- $forum_results .='</div>';
- }$j++;
- }
- }
- return $forum_results;
- }
- function get_thread_user_post_limit($course_code, $thread_id, $user_id, $limit = 10)
- {
- $table_posts = Database::get_course_table(TABLE_FORUM_POST);
- $table_users = Database::get_main_table(TABLE_MAIN_USER);
- $course_info = api_get_course_info($course_code);
- $course_id = $course_info['real_id'];
- $sql = "SELECT * FROM $table_posts posts
- LEFT JOIN $table_users users
- ON posts.poster_id=users.user_id
- WHERE
- posts.c_id = $course_id AND
- posts.thread_id='".Database::escape_string($thread_id)."'
- AND posts.poster_id='".Database::escape_string($user_id)."'
- ORDER BY posts.post_id DESC LIMIT $limit ";
- $result = Database::query($sql);
- $post_list = array();
- while ($row = Database::fetch_array($result)) {
- $row['status'] = '1';
- $post_list[] = $row;
- }
- return $post_list;
- }
- function getForumCreatedByUser($user_id, $courseId, $sessionId)
- {
- $items = api_get_item_property_list_by_tool_by_user(
- $user_id,
- 'forum',
- $courseId,
- $sessionId
- );
- $courseInfo = api_get_course_info_by_id($courseId);
- $forumList = array();
- if (!empty($items)) {
- foreach ($items as $forum) {
- $forumInfo = get_forums(
- $forum['ref'],
- $courseInfo['code'],
- true,
- $sessionId
- );
- $forumList[] = array(
- $forumInfo['forum_title'],
- api_get_local_time($forum['insert_date']),
- api_get_local_time($forum['lastedit_date'])
- );
- }
- }
- return $forumList;
- }
- function calculate_children($rows)
- {
- $sorted_rows = array(0 => array());
- if (!empty($rows)) {
- foreach ($rows as $row) {
- $rows_with_children[$row['post_id']] = $row;
- $rows_with_children[$row['post_parent_id']]['children'][] = $row['post_id'];
- }
- $rows = $rows_with_children;
- forumRecursiveSort($rows, $sorted_rows);
- unset($sorted_rows[0]);
- }
- return $sorted_rows;
- }
- function forumRecursiveSort($rows, &$threads, $seed = 0, $indent = 0)
- {
- if ($seed > 0) {
- $threads[$rows[$seed]['post_id']] = $rows[$seed];
- $threads[$rows[$seed]['post_id']]['indent_cnt'] = $indent;
- $indent++;
- }
- if (isset($rows[$seed]['children'])) {
- foreach ($rows[$seed]['children'] as $child) {
- forumRecursiveSort($rows, $threads, $child, $indent);
- }
- }
- }
- function editAttachedFile($array, $id, $courseId = null) {
-
- $setString = '';
- $id = intval($id);
- $courseId = intval($courseId);
- if (empty($courseId)) {
-
- $courseId= api_get_course_int_id();
- }
-
- if ($id > 0 && $courseId > 0 && !empty($array) && is_array($array)) {
- foreach($array as $key => &$item) {
- $item = Database::escape_string($item);
- $setString .= $key . ' = "' .$item . '", ';
- }
-
- $setString = substr($setString, 0, strlen($setString) - 2);
- $forumAttachmentTable = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
- $sql = "UPDATE $forumAttachmentTable SET $setString WHERE c_id = $courseId AND id = $id";
- $result = Database::query($sql);
- if ($result !== false) {
- $affectedRows = Database::affected_rows($result);
- if ($affectedRows > 0) {
-
- if (!empty($_SESSION['forum']['upload_file'][$courseId][$id])) {
- unset($_SESSION['forum']['upload_file'][$courseId][$id]);
- }
- }
- return $affectedRows;
- }
- }
- return 0;
- }
- function getAttachmentAjaxForm($forumId, $threadId, $postId)
- {
- $forumId = intval($forumId);
- $postId = intval($postId);
- $threadId = !empty($threadId) ? intval($threadId) : isset($_REQUEST['thread']) ? intval($_REQUEST['thread']) : '';
- if ($forumId === 0) {
-
- return '';
- }
- $url = api_get_path(WEB_AJAX_PATH).'forum.ajax.php?'.api_get_cidreq().'&forum=' . $forumId . '&thread=' . $threadId . '&postId=' . $postId . '&a=upload_file';
-
- $formFileUpload = '<div class="form-ajax">
- <form id="file_upload" action="'.$url.'" method="POST" enctype="multipart/form-data">
- <input type="file" name="user_upload" multiple>
- <button type="submit">Upload</button>
- <div class="button-load">
- '.get_lang('UploadFiles').'
- </div>
- </form></div>
- ';
- return $formFileUpload;
- }
- function getAttachmentsAjaxTable($postId = null)
- {
-
- $postId = intval($postId);
- $courseId = api_get_course_int_id();
- $attachIds = getAttachmentIdsByPostId($postId, $courseId);
- $fileDataContent = '';
-
- if (!empty($_REQUEST['file_ids']) && is_array($_REQUEST['file_ids'])) {
-
- foreach ($_REQUEST['file_ids'] as $key => $attachId) {
- if (!empty($_SESSION['forum']['upload_file'][$courseId][$attachId]) &&
- is_array($_SESSION['forum']['upload_file'][$courseId][$attachId])
- ) {
-
- $_SESSION['forum']['upload_file'][$courseId][$attachId]['comment'] = $_POST['file_comments'][$key];
- }
- }
- }
-
- if (!empty($_SESSION['forum']['upload_file'][$courseId]) &&
- is_array($_SESSION['forum']['upload_file'][$courseId])
- ) {
- $uploadedFiles = $_SESSION['forum']['upload_file'][$courseId];
- foreach ($uploadedFiles as $k => $uploadedFile) {
- if (!empty($uploadedFile) && in_array($uploadedFile['id'], $attachIds)) {
-
- $fileDataContent .= '<tr id="' . $uploadedFile['id'] . '" ><td>' . $uploadedFile['name'] . '</td><td>' . $uploadedFile['size'] . '</td><td> ' . $uploadedFile['result'] .
- ' </td><td> <input style="width:90%;" type="text" value="' . $uploadedFile['comment'] . '" name="file_comments[]"> </td><td>' .
- $uploadedFile['delete'] . '</td>' .
- '<input type="hidden" value="' . $uploadedFile['id'] .'" name="file_ids[]">' . '</tr>';
- } else {
-
- unset($_SESSION['forum']['upload_file'][$courseId][$k]);
- }
- }
- }
- $style = empty($fileDataContent) ? 'display: none;' : '';
-
- $fileData = '
- <div class="control-group " style="'. $style . '">
- <label class="control-label">'.get_lang('AttachmentFilesList').'</label>
- <div class="controls">
- <table id="attachmentFileList" class="files data_table span10">
- <tr>
- <th>'.get_lang('FileName').'</th>
- <th>'.get_lang('Size').'</th>
- <th>'.get_lang('Status').'</th>
- <th>'.get_lang('Comment').'</th>
- <th>'.get_lang('Delete').'</th>
- </tr>
- '.$fileDataContent.'
- </table>
- </div>
- </div>';
- return $fileData;
- }
- function getAttachedFiles($forumId, $threadId, $postId = null, $attachId = null, $courseId = null)
- {
- $forumId = intval($forumId);
- $courseId = intval($courseId);
- $attachId = intval($attachId);
- $postId = intval($postId);
- $threadId = !empty($threadId) ? intval($threadId) : isset($_REQUEST['thread']) ? intval($_REQUEST['thread']) : '';
- if (empty($courseId)) {
-
- $courseId = api_get_course_int_id();
- }
- if (empty($forumId)) {
- if (!empty($_REQUEST['forum'])) {
- $forumId = intval($_REQUEST['forum']);
- } else {
-
- return array();
- }
- }
-
- if (empty($postId) && empty($attachId)) {
- return array();
- } elseif (empty($postId)) {
- $filter = "AND iid = $attachId";
- } elseif (empty($attachId)) {
- $filter = "AND post_id = $postId";
- } else {
- $filter = "AND post_id = $postId AND iid = $attachId";
- }
- $forumAttachmentTable = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
- $sql = "SELECT iid, comment, filename, path, size
- FROM $forumAttachmentTable
- WHERE c_id = $courseId $filter";
- $result = Database::query($sql);
- $json = array();
- if ($result !== false && Database::num_rows($result) > 0) {
- while ($row = Database::fetch_array($result, 'ASSOC')) {
-
- $json['name'] = Display::url(
- api_htmlentities($row['filename']),
- api_get_path(WEB_CODE_PATH) . 'forum/download.php?file='.$row['path'].'&'.api_get_cidreq(),
- array('target'=>'_blank', 'class' => 'attachFilename')
- );
- $json['id'] = $row['iid'];
- $json['comment'] = $row['comment'];
-
- $json['size'] = format_file_size($row['size']);
-
- if (!empty($row) && is_array($row)) {
-
- $json['result'] = Display::return_icon('accept.png', get_lang('Uploaded'));
- $url = api_get_path(WEB_CODE_PATH) . 'forum/viewthread.php?' . api_get_cidreq() . '&action=delete_attach&forum=' . $forumId . '&thread=' . $threadId.'&id_attach=' . $row['iid'];
- $json['delete'] = Display::url(
- Display::return_icon('delete.png',get_lang('Delete'), array(), ICON_SIZE_SMALL),
- $url,
- array('class' => 'deleteLink')
- );
- } else {
-
- $json['result'] = Display::return_icon('exclamation.png', get_lang('Error'));
- }
-
- $_SESSION['forum']['upload_file'][$courseId][$json['id']] = $json;
- }
- }
- return $json;
- }
- function clearAttachedFiles($postId = null, $courseId = null) {
-
- $courseId = intval($courseId);
- $postId = intval($postId);
- $array = array();
- if (empty($courseId)) {
-
- $courseId = api_get_course_int_id();
- }
- if ($postId === -1) {
-
- if (!empty($_SESSION['forum']['upload_file'][$courseId])) {
- $array = array_keys($_SESSION['forum']['upload_file'][$courseId]);
- unset($_SESSION['forum']['upload_file'][$courseId]);
- }
- } else {
- $attachIds = getAttachmentIdsByPostId($postId, $courseId);
- if (!empty($_SESSION['forum']['upload_file'][$courseId]) &&
- is_array($_SESSION['forum']['upload_file'][$courseId])) {
- foreach ($_SESSION['forum']['upload_file'][$courseId] as $attachId => $attach) {
- if (!in_array($attachId, $attachIds)) {
-
-
- $array[] = $attachId;
- if ($postId !== 0) {
-
- delete_attachment(0, $attachId, false);
- }
-
- unset($_SESSION['forum']['upload_file'][$courseId][$attachId]);
- }
- }
- }
- }
- return $array;
- }
- function getAttachmentIdsByPostId($postId, $courseId = null) {
-
- $array = array();
- $courseId = intval($courseId);
- $postId = intval($postId);
- if (empty($courseId)) {
-
- $courseId = api_get_course_int_id();
- }
- if ($courseId > 0) {
- $forumAttachmentTable = Database::get_course_table(TABLE_FORUM_ATTACHMENT);
- $sql = "SELECT id FROM $forumAttachmentTable WHERE c_id = $courseId AND post_id = $postId";
- $result = Database::query($sql);
- if ($result !== false && Database::num_rows($result) > 0) {
- while ($row = Database::fetch_array($result,'ASSOC')) {
- $array[] = $row['id'];
- }
- }
- }
- return $array;
- }
|