12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952 |
- <?php
- use \ChamiloSession as Session;
- require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
- get_notifications_of_user();
- $htmlHeadXtra[] = '<script type="text/javascript">
- function setFocus(){
- $("#forum_title").focus();
- $("#category_title").focus();
- $("#search_title").focus();
- }
- $(document).ready(function () {
- setFocus();
- });
- </script>';
- function handle_forum_and_forumcategories($lp_id = null)
- {
- $action_forum_cat = isset($_GET['action']) ? $_GET['action'] : '';
- $post_submit_cat = isset($_POST['SubmitForumCategory']) ? true : false;
- $post_submit_forum = isset($_POST['SubmitForum']) ? true : false;
- $get_id = isset($_GET['id']) ? $_GET['id'] : '';
-
- 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(intval($get_id));
- } else {
- $inputvalues = array();
- }
- show_add_forum_form($inputvalues, $lp_id);
- }
-
- if (($action_forum_cat == 'edit' && $_GET['content'] == 'forumcategory' && isset($_GET['id'])) || (isset($_POST['SubmitEditForumCategory'])) ? true : false) {
- $forum_category = get_forum_categories(strval(intval($_GET['id'])));
- show_edit_forumcategory_form($forum_category);
- }
-
- if ((isset($_GET['action']) && $_GET['action'] == 'delete') && isset($_GET['content']) && $get_id) {
- $id_forum = intval($get_id);
- $list_threads = get_threads($id_forum);
- for ($i = 0; $i < count($list_threads); $i++) {
- delete_forum_forumcategory_thread('thread', $list_threads[$i]['thread_id']);
- require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
- $link_info = is_resource_in_course_gradebook(
- api_get_course_id(),
- 5,
- intval($list_threads[$i]['thread_id']),
- api_get_session_id()
- );
- if ($link_info !== false) {
- remove_resource_from_course_gradebook($link_info['id']);
- }
- }
- $return_message = delete_forum_forumcategory_thread($_GET['content'], $_GET['id']);
- Display::display_confirmation_message($return_message, false);
- }
-
- if (($action_forum_cat == 'invisible' || $action_forum_cat == 'visible') && isset($_GET['content']) && isset($_GET['id'])) {
- $return_message = change_visibility(
- $_GET['content'],
- $_GET['id'],
- $_GET['action']
- );
- Display::display_confirmation_message($return_message, false);
- }
-
- if (($action_forum_cat == 'lock' || $action_forum_cat == 'unlock') && isset($_GET['content']) && isset($_GET['id'])) {
- $return_message = change_lock_status(
- $_GET['content'],
- $_GET['id'],
- $_GET['action']
- );
- Display::display_confirmation_message($return_message, false);
- }
-
- if ($action_forum_cat == 'move' && isset($_GET['content']) && isset($_GET['id']) && 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'), 'class="input_titles" id="category_title"');
-
- $form->addElement(
- 'html_editor',
- 'forum_category_comment',
- get_lang('Description'),
- null,
- array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')
- );
-
- $form->addElement('style_submit_button', 'SubmitForumCategory', get_lang('CreateCategory'), 'class="add"');
-
- $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'), 'class="input_titles" id="forum_title"');
-
- $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->addElement('advanced_settings', 'options', get_lang('AdvancedParameters'));
- $form->addElement('html', '<div id="options_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') {
- $class = 'save';
- $text = get_lang('ModifyForum');
- } else {
- $class = 'add';
- $text = get_lang('CreateForum');
- }
- $form->addElement('style_submit_button', 'SubmitForum', $text, 'class="'.$class.'"');
-
- $form->addRule('forum_title', get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('forum_category', get_lang('ThisFieldIsRequired'), 'required');
-
- 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'] = 0;
- $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'] : null;
- $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 = Database::escape_string($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())
- {
-
- $gradebook = Security::remove_XSS($_GET['gradebook']);
- $form = new FormValidator('forumcategory', 'post', 'index.php?&gradebook='.$gradebook.'');
-
- $form->addElement('header', '', get_lang('EditForumCategory'));
- $form->addElement('hidden', 'forum_category_id');
- $form->addElement('text', 'forum_category_title', get_lang('Title'), 'class="input_titles"');
-
- $form->addElement(
- 'html_editor',
- 'forum_category_comment',
- get_lang('Comment'),
- null,
- array('ToolbarSet' => 'Forum', 'Width' => '98%', 'Height' => '200')
- );
-
- $form->addElement('style_submit_button', 'SubmitEditForumCategory', get_lang('ModifyCategory'), 'class="save"');
-
- $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)
- {
- $_course = api_get_course_info();
- $course_id = api_get_course_int_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 = Database::escape_string($values['forum_category_title']);
- if (isset($values['forum_category_id'])) {
- $sql = "UPDATE ".$table_categories." SET cat_title='".$clean_cat_title."', cat_comment='".Database::escape_string(
- $values['forum_category_comment']
- )."'
- WHERE c_id = $course_id AND cat_id='".Database::escape_string($values['forum_category_id'])."'";
- Database::query($sql);
- $last_id = Database::insert_id();
- api_item_property_update(
- api_get_course_info(),
- TOOL_FORUM_CATEGORY,
- $values['forum_category_id'],
- 'ForumCategoryUpdated',
- api_get_user_id()
- );
- $return_message = get_lang('ForumCategoryEdited');
- } else {
- $sql = "INSERT INTO ".$table_categories." (c_id, cat_title, cat_comment, cat_order, session_id)
- VALUES (".$course_id.", '".$clean_cat_title."','".Database::escape_string(
- $values['forum_category_comment']
- )."','".Database::escape_string($new_max)."','".Database::escape_string($session_id)."')";
- Database::query($sql);
- $last_id = Database::insert_id();
- if ($last_id > 0) {
- api_item_property_update(
- api_get_course_info(),
- TOOL_FORUM_CATEGORY,
- $last_id,
- 'ForumCategoryAdded',
- api_get_user_id()
- );
- api_set_default_visibility($_course, $last_id, TOOL_FORUM_CATEGORY);
- }
- $return_message = get_lang('ForumCategoryAdded');
- }
- Display :: display_confirmation_message($return_message);
- }
- function store_forum($values)
- {
- $_course = api_get_course_info();
- $course_id = api_get_course_int_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 = FileManager::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 = $_course['path'].'/upload/forum/images';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$course_dir;
-
- $new_file_name = FileManager::add_ext_on_mime(
- Database::escape_string($_FILES['picture']['name']),
- $_FILES['picture']['type']
- );
-
- $file_name = $_FILES['picture']['name'];
- if (!FileManager::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 = " forum_image='".Database::escape_string($new_file_name)."', ";
- delete_forum_image($values['forum_id']);
- }
- }
-
- $sql = "UPDATE ".$table_forums." SET
- forum_title='".$clean_title."',
- ".$sql_image."
- forum_comment='".Database::escape_string(stripslashes($values['forum_comment']))."',
- forum_category='".Database::escape_string(stripslashes($values['forum_category']))."',
- allow_anonymous='".Database::escape_string(
- isset($values['allow_anonymous_group']['allow_anonymous']) ? $values['allow_anonymous_group']['allow_anonymous'] : null
- )."',
- allow_edit='".Database::escape_string($values['students_can_edit_group']['students_can_edit'])."',
- approval_direct_post='".Database::escape_string(
- isset($values['approval_direct_group']['approval_direct']) ? $values['approval_direct_group']['approval_direct'] : null
- )."',
- allow_attachments='".Database::escape_string(
- isset($values['allow_attachments_group']['allow_attachments']) ? $values['allow_attachments_group']['allow_attachments'] : null
- )."',
- allow_new_threads='".Database::escape_string($values['allow_new_threads_group']['allow_new_threads'])."',
- forum_group_public_private='".Database::escape_string(
- $values['public_private_group_forum_group']['public_private_group_forum']
- )."',
- default_view='".Database::escape_string($values['default_view_type_group']['default_view_type'])."',
- forum_of_group='".Database::escape_string($values['group_forum'])."'
- WHERE c_id = $course_id AND forum_id='".Database::escape_string($values['forum_id'])."'";
- Database::query($sql);
- api_item_property_update(
- $_course,
- TOOL_FORUM,
- Database::escape_string($values['forum_id']),
- 'ForumUpdated',
- api_get_user_id(),
- $group_id
- );
- $return_message = get_lang('ForumEdited');
- } else {
- $sql_image = '';
- if ($image_moved) {
- $new_file_name = isset($new_file_name) ? $new_file_name : '';
- $sql_image = "'".$new_file_name."', ";
- }
- $b = isset($values['forum_comment']) ? $values['forum_comment'] : null;
- $sql = "INSERT INTO ".$table_forums." (c_id, forum_title, forum_image, forum_comment, forum_category, allow_anonymous, allow_edit, approval_direct_post, allow_attachments, allow_new_threads, default_view, forum_of_group, forum_group_public_private, forum_order, session_id)
- VALUES (
- ".$course_id.",
- '".$clean_title."',
- ".$sql_image."
- '".Database::escape_string(isset($values['forum_comment']) ? $values['forum_comment'] : null)."',
- '".Database::escape_string(isset($values['forum_category']) ? $values['forum_category'] : null)."',
- '".Database::escape_string(
- isset($values['allow_anonymous_group']['allow_anonymous']) ? $values['allow_anonymous_group']['allow_anonymous'] : null
- )."',
- '".Database::escape_string(
- isset($values['students_can_edit_group']['students_can_edit']) ? $values['students_can_edit_group']['students_can_edit'] : null
- )."',
- '".Database::escape_string(
- isset($values['approval_direct_group']['approval_direct']) ? $values['approval_direct_group']['approval_direct'] : null
- )."',
- '".Database::escape_string(
- isset($values['allow_attachments_group']['allow_attachments']) ? $values['allow_attachments_group']['allow_attachments'] : null
- )."',
- '".Database::escape_string(
- isset($values['allow_new_threads_group']['allow_new_threads']) ? $values['allow_new_threads_group']['allow_new_threads'] : null
- )."',
- '".Database::escape_string(
- isset($values['default_view_type_group']['default_view_type']) ? $values['default_view_type_group']['default_view_type'] : null
- )."',
- '".Database::escape_string(isset($values['group_forum']) ? $values['group_forum'] : null)."',
- '".Database::escape_string(
- isset($values['public_private_group_forum_group']['public_private_group_forum']) ? $values['public_private_group_forum_group']['public_private_group_forum'] : null
- )."',
- '".Database::escape_string(isset($new_max) ? $new_max : null)."',
- ".intval($session_id).")";
- Database::query($sql);
- $last_id = Database::insert_id();
- if ($last_id > 0) {
- api_item_property_update($_course, TOOL_FORUM, $last_id, 'ForumAdded', api_get_user_id(), $group_id);
- api_set_default_visibility($_course, $last_id, TOOL_FORUM, $group_id);
- }
- $return_message = get_lang('ForumAdded');
- }
- return $return_message;
- }
- function delete_forum_forumcategory_thread($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();
-
- $sql = "SELECT post_id FROM $table_forums_post WHERE c_id = $course_id AND thread_id = '".(int)$id."' ";
- $res = Database::query($sql);
- while ($poster_id = Database::fetch_row($res)) {
- delete_attachment($poster_id[0]);
- }
- 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',
- api_get_user_id()
- );
- 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 = $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='".Database::escape_string(
- $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='".Database::escape_string($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='".Database::escape_string(
- $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 = '')
- {
- global $origin;
- $gradebook = Security::remove_XSS($_GET['gradebook']);
- $id = Security::remove_XSS($id);
- if ($current_visibility_status == '1') {
- echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&gidReq='.api_get_group_id().'&';
- if (is_array($additional_url_parameters)) {
- foreach ($additional_url_parameters as $key => $value) {
- echo $key.'='.$value.'&';
- }
- }
- echo 'action=invisible&content='.$content.'&id='.$id.'&gradebook='.$gradebook.'&origin='.$origin.'">'.Display::return_icon(
- 'visible.png',
- get_lang('MakeInvisible'),
- array(),
- ICON_SIZE_SMALL
- ).'</a>';
- }
- if ($current_visibility_status == '0') {
- echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&';
- if (is_array($additional_url_parameters)) {
- foreach ($additional_url_parameters as $key => $value) {
- echo $key.'='.$value.'&';
- }
- }
- echo 'action=visible&content='.$content.'&id='.$id.'&gradebook='.$gradebook.'&origin='.$origin.'">'.Display::return_icon(
- 'invisible.png',
- get_lang('MakeVisible'),
- array(),
- ICON_SIZE_SMALL
- ).'</a>';
- }
- }
- function display_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters = '')
- {
- $id = intval($id);
-
- if ($content == 'thread') {
- if (api_resource_is_locked_by_gradebook($id, LINK_FORUM_THREAD)) {
- echo Display::return_icon('lock_na.png', get_lang('ResourceLockedByGradebook'), array(), ICON_SIZE_SMALL);
- return;
- }
- }
- if ($current_lock_status == '1') {
- echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&';
- if (is_array($additional_url_parameters)) {
- foreach ($additional_url_parameters as $key => $value) {
- echo $key.'='.$value.'&';
- }
- }
- echo 'action=unlock&content='.$content.'&id='.$id.'">'.Display::return_icon(
- 'lock.png',
- get_lang('Unlock'),
- array(),
- ICON_SIZE_SMALL
- ).'</a>';
- }
- if ($current_lock_status == '0') {
- echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&';
- if (is_array($additional_url_parameters)) {
- foreach ($additional_url_parameters as $key => $value) {
- echo $key.'='.$value.'&';
- }
- }
- echo 'action=lock&content='.$content.'&id='.$id.'">'.Display::return_icon(
- 'unlock.png',
- get_lang('Lock'),
- array(),
- ICON_SIZE_SMALL
- ).'</a>';
- }
- }
- function display_up_down_icon($content, $id, $list)
- {
- $id = strval(intval($id));
- $total_items = count($list);
- $position = 0;
- $internal_counter = 0;
- 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().'&gidReq='.Security::remove_XSS(
- $_GET['gidReq']
- ).'&action=move&direction=up&content='.$content.'&forumcategory='.Security::remove_XSS(
- $_GET['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().'&gidReq='.Security::remove_XSS(
- $_GET['gidReq']
- ).'&action=move&direction=down&content='.$content.'&forumcategory='.Security::remove_XSS(
- $_GET['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);
- }
- echo $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);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
-
- 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();
-
- 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=".Database::escape_string(
- $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)
- {
- if ($current_visibility_status == '0') {
- return 'class="invisible"';
- }
- }
- function get_forum_categories($id = '')
- {
- $table_categories = Database :: get_course_table(TABLE_FORUM_CATEGORY);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $forum_categories_list = array();
-
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id);
- $course_id = api_get_course_int_id();
- $condition_session .= "AND forum_categories.c_id = $course_id AND item_properties.c_id = $course_id";
- if ($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 (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='".Database::escape_string($id)."' $condition_session
- ORDER BY forum_categories.cat_order ASC";
- }
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- if ($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 (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 = '')
- {
- $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);
-
-
- $session_id = api_get_session_id();
- $condition_session = api_get_session_condition($session_id);
- $course_id = $course_info['real_id'];
- $forum_list = array();
- if ($id == '') {
-
-
- $sql = "SELECT * FROM $table_forums forum , ".$table_item_property." item_properties
- WHERE forum.forum_id=item_properties.ref
- AND 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
- ORDER BY forum.forum_order ASC";
-
- $sql2 = "SELECT count(*) AS number_of_threads, threads.forum_id FROM $table_threads threads, ".$table_item_property." item_properties
- WHERE threads.thread_id=item_properties.ref
- AND 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 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 (is_allowed_to_edit()) {
-
- $sql = "SELECT * FROM ".$table_forums." forum , ".$table_item_property." item_properties
- WHERE forum.forum_id=item_properties.ref
- 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, threads.forum_id FROM $table_threads threads, ".$table_item_property." item_properties
- WHERE threads.thread_id=item_properties.ref
- AND 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 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='".Database::escape_string($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=".Database::escape_string($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=".Database::escape_string($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=".Database::escape_string($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=".Database::escape_string($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'];
- $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);
- $thread_list = array();
-
-
-
-
- $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."'
- LEFT JOIN $table_users users
- ON thread.thread_poster_id=users.user_id
- WHERE
- item_properties.visibility='1' AND
- thread.forum_id='".Database::escape_string($forum_id)."'
- ORDER BY thread.thread_sticky DESC, thread.thread_date DESC";
- if (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."'
- LEFT JOIN $table_users users
- ON thread.thread_poster_id=users.user_id
- WHERE
- item_properties.visibility<>2 AND
- thread.forum_id='".Database::escape_string($forum_id)."'
- ORDER BY thread.thread_sticky DESC, thread.thread_date DESC";
- }
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $thread_list[] = $row;
- }
- return $thread_list;
- }
- function get_posts($thread_id)
- {
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $course_id = api_get_course_int_id();
-
- if (api_is_allowed_to_edit(null, true)) {
- $sql = "SELECT * FROM $table_posts posts
- LEFT JOIN $table_users users
- ON posts.poster_id=users.user_id
- WHERE
- c_id = $course_id AND
- posts.thread_id='".Database::escape_string($thread_id)."'
- ORDER BY posts.post_id ASC";
- } else {
-
- $sql = "SELECT * FROM $table_posts posts
- LEFT JOIN $table_users users
- ON posts.poster_id=users.user_id
- WHERE
- c_id = $course_id AND
- posts.thread_id='".Database::escape_string($thread_id)."'
- AND posts.visible='1'
- ORDER BY posts.post_id ASC";
- }
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- $post_list[] = $row;
- }
- return $post_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='".Database::escape_string(
- $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();
- $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 = '".Database::escape_string($thread_id)."' AND
- threads.thread_id = '".Database::escape_string($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.user_id, user.lastname, user.firstname, thread_id
- FROM $t_posts , $t_users user, $t_session_rel_user session_rel_user_rel_course
- WHERE poster_id = user.user_id AND
- user.user_id = session_rel_user_rel_course.id_user AND
- session_rel_user_rel_course.status<>'2' AND
- session_rel_user_rel_course.id_user NOT IN ($user_to_avoid) AND
- thread_id = '".Database::escape_string($thread_id)."' AND
- id_session = '".api_get_session_id()."' AND
- c_id = $course_id AND
- course_code = '".$course_code."' $orderby ";
- } else {
- $sql = "SELECT DISTINCT user.user_id, user.lastname, user.firstname, thread_id
- FROM $t_posts, $t_users user, $t_course_user course_user
- WHERE poster_id = user.user_id AND
- course_user.c_id = $t_posts.c_id
- user.user_id = course_user.user_id AND
- course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND
- thread_id = '".Database::escape_string($thread_id)."' AND
- course_user.status NOT IN('1') 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();
- $course_code = api_get_course_id();
- $course_code = Database::escape_string($course_code);
- $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.user_id,qualify.qualify
- FROM $t_posts post , $t_users user, $t_session_rel_user session_rel_user_rel_course, $t_qualify qualify
- WHERE poster_id = user.user_id
- AND post.poster_id = qualify.user_id
- AND user.user_id = session_rel_user_rel_course.id_user
- AND session_rel_user_rel_course.status<>'2'
- AND session_rel_user_rel_course.id_user NOT IN ($user_to_avoid)
- AND qualify.thread_id = '".Database::escape_string($thread_id)."
- AND thread_id = '".Database::escape_string($thread_id)."'
- AND id_session = '".api_get_session_id()."'
- AND course_code = '".$course_code."' 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.user_id,qualify.qualify
- FROM $t_posts post,
- $t_qualify qualify,
- $t_users user,
- $t_course_user course_user
- WHERE
- post.poster_id = user.user_id
- AND post.poster_id = qualify.user_id
- AND user.user_id = course_user.user_id
- AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
- AND qualify.thread_id = '".Database::escape_string($thread_id)."'
- AND post.thread_id = '".Database::escape_string($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();
- $course_code = api_get_course_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.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.user_id
- AND user.user_id NOT IN (".$cad.")
- AND user.user_id = session_rel_user_rel_course.id_user
- AND session_rel_user_rel_course.status<>'2'
- AND session_rel_user_rel_course.id_user NOT IN ($user_to_avoid)
- AND post.thread_id = '".Database::escape_string($thread_id)."'
- AND id_session = '".api_get_session_id()."'
- AND course_code = '".$course_code."' AND post.c_id = $course_id $orderby ";
- } else {
- $sql = "SELECT DISTINCT user.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.user_id
- AND user.user_id NOT IN (".$cad.")
- AND user.user_id = course_user.user_id
- AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH."
- AND post.thread_id = '".Database::escape_string($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)
- {
- $table_forums = Database :: get_course_table(TABLE_FORUM);
- $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
- $sql = "SELECT * FROM ".$table_forums." forums, ".$table_item_property." item_properties
- WHERE item_properties.tool = '".TOOL_FORUM."' AND
- item_properties.ref = '".Database::escape_string($forum_id)."' AND
- item_properties.c_id = ".api_get_course_int_id()." AND
- forums.forum_id = '".Database::escape_string($forum_id)."' AND
- forums.c_id = ".api_get_course_int_id()."
- ";
- $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($values)
- {
- global $_user;
- $_course = api_get_course_info();
- global $current_forum;
- global $origin;
- $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();
- $gradebook = Security::remove_XSS($_GET['gradebook']);
- $upload_ok = 1;
- $has_attachment = false;
- if (!empty($_FILES['user_upload']['name'])) {
- $upload_ok = FileManager::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 = Database::escape_string(stripslashes($values['post_title']));
-
- $sql = "INSERT INTO $table_threads (c_id, thread_title, forum_id, thread_poster_id, thread_poster_name, thread_date, thread_sticky,thread_title_qualify,thread_qualify_max,thread_weight,session_id)
- VALUES (
- ".$course_id.",
- '".$clean_post_title."',
- '".Database::escape_string($values['forum_id'])."',
- '".Database::escape_string($_user['user_id'])."',
- '".Database::escape_string(
- stripslashes(isset($values['poster_name']) ? $values['poster_name'] : null)
- )."',
- '".Database::escape_string($post_date)."',
- '".Database::escape_string(
- isset($values['thread_sticky']) ? $values['thread_sticky'] : null
- )."',".
- "'".Database::escape_string(stripslashes($values['calification_notebook_title']))."',".
- "'".Database::escape_string($values['numeric_calification'])."',".
- "'".Database::escape_string($values['weight_calification'])."',".
- "'".api_get_session_id()."')";
- $result = Database::query($sql);
- $last_thread_id = Database::insert_id();
-
- if (isset($values['thread_qualify_gradebook']) && 1 == $values['thread_qualify_gradebook']) {
-
- $coursecode = api_get_course_id();
- $resourcetype = 5;
- $resourceid = $last_thread_id;
- $resourcename = stripslashes($values['calification_notebook_title']);
- $maxqualify = $values['numeric_calification'];
- $weigthqualify = $values['weight_calification'];
- $resourcedescription = '';
- add_resource_to_course_gradebook(
- $values['category_id'],
- $coursecode,
- $resourcetype,
- $resourceid,
- $resourcename,
- $weigthqualify,
- $maxqualify,
- $resourcedescription,
- 0,
- api_get_session_id()
- );
- }
- if ($last_thread_id) {
- api_item_property_update(
- $_course,
- TOOL_FORUM_THREAD,
- $last_thread_id,
- 'ForumThreadAdded',
- api_get_user_id()
- );
-
-
-
-
-
- api_set_default_visibility($_course, $last_thread_id, TOOL_FORUM_THREAD);
- if ($visible == 0) {
- api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id, 'invisible', api_get_user_id());
- $visible = 1;
- }
- }
-
- $sql = "INSERT INTO $table_posts (c_id, post_title, post_text, thread_id, forum_id, poster_id, poster_name, post_date, post_notification, post_parent_id, visible)
- VALUES (
- ".$course_id.",
- '".$clean_post_title."',
- '".Database::escape_string($values['post_text'])."',
- '".Database::escape_string($last_thread_id)."',
- '".Database::escape_string($values['forum_id'])."',
- '".Database::escape_string($_user['user_id'])."',
- '".Database::escape_string(stripslashes(isset($values['poster_name']) ? $values['poster_name'] : null))."',
- '".Database::escape_string($post_date)."',
- '".Database::escape_string(isset($values['post_notification']) ? $values['post_notification'] : null)."','0',
- '".Database::escape_string($visible)."')";
- Database::query($sql);
- $last_post_id = Database::insert_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) {
- $course_dir = $_course['path'].'/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$course_dir;
-
- $new_file_name = FileManager::add_ext_on_mime(
- stripslashes($_FILES['user_upload']['name']),
- $_FILES['user_upload']['type']
- );
-
- $file_name = $_FILES['user_upload']['name'];
- if (!FileManager::filter_extension($new_file_name)) {
- Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
- } else {
- if ($result) {
- $comment = Database::escape_string($comment);
- add_forum_attachment_file($comment, $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'].'&gidReq='.$_SESSION['toolgroup'].'&origin='.$origin.'">'.get_lang(
- 'Forum'
- ).'</a><br />';
- } else {
- $message .= get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq(
- ).'&forum='.$values['forum_id'].'&gidReq='.$_SESSION['toolgroup'].'&origin='.$origin.'">'.get_lang(
- 'Forum'
- ).'</a><br />';
- $message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq(
- ).'&forum='.$values['forum_id'].'&gidReq='.$_SESSION['toolgroup'].'&origin='.$origin.'&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');
- Display :: display_confirmation_message($message, false);
- } else {
- Display::display_error_message(get_lang('UplNoFileUploaded'));
- }
- }
- function show_add_post_form($action = '', $id = '', $form_values = '')
- {
- global $forum_setting;
- global $current_forum;
- global $_user;
- global $origin;
- $gradebook = Security::remove_XSS($_GET['gradebook']);
-
- if ($_GET['action'] == 'quote') {
- $class = 'save';
- $text = get_lang('QuoteMessage');
- } elseif ($_GET['action'] == 'replythread') {
- $class = 'save';
- $text = get_lang('ReplyToThread');
- } elseif ($_GET['action'] == 'replymessage') {
- $class = 'save';
- $text = get_lang('ReplyToMessage');
- } else {
- $class = 'add';
- $text = get_lang('CreateThread');
- }
-
- $my_thread = isset($_GET['thread']) ? $_GET['thread'] : '';
- $my_forum = isset($_GET['forum']) ? $_GET['forum'] : '';
- $my_action = isset($_GET['action']) ? $_GET['action'] : '';
- $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
- ).'&gradebook='.$gradebook.'&thread='.Security::remove_XSS($my_thread).'&post='.Security::remove_XSS(
- $my_post
- ).'&action='.Security::remove_XSS($my_action).'&origin='.$origin);
- $form->setConstants(array('forum' => '5'));
- $form->addElement('header', $text);
-
- $form->addElement('hidden', 'forum_id', intval($my_forum));
- $form->addElement('hidden', 'thread_id', intval($my_thread));
- $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->addElement(
- 'html_editor',
- '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');
- $form->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters'));
- $form->addElement('html', '<div id="id_qualify_options" style="display:none">');
- if ((api_is_course_admin() || api_is_course_coach() || api_is_course_tutor()) && !($my_thread)) {
-
- if (Gradebook::is_active()) {
-
- 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'),
- 'value="0.00" Style="width:40px" onfocus="javascript: this.select();"'
- );
- $form->applyFilter('weight_calification', 'html_filter');
- $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('static', null, null, get_lang('AddAnAttachment'));
- $form->addElement('file', 'user_upload', get_lang('FileName'), '');
- $form->addElement('textarea', 'file_comment', get_lang('FileComment'), array('rows' => 4, 'cols' => 34));
- $form->applyFilter('file_comment', 'html_filter');
- $form->addElement('html', '</div>');
- $form->addElement('style_submit_button', 'SubmitPost', $text, 'class="'.$class.'"');
- $form->add_real_progress_bar('DocumentUpload', 'user_upload');
- 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']));
- }
-
-
- if (($action == 'quote' || $action == 'replymessage') && isset($my_post)) {
-
- $form->addElement('hidden', 'post_parent_id', strval(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 ($values['thread_qualify_gradebook'] == '1' && empty($values['weight_calification'])) {
- Display::display_error_message(
- get_lang('YouMustAssignWeightOfQualification').' <a href="javascript:window.back()">'.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));
- $iframe = null;
- if ($forum_setting['show_thread_iframe_on_reply'] && $action != 'newthread') {
- $iframe = "<iframe style=\"border: 1px solid black\" src=\"iframe_thread.php?forum=".Security::remove_XSS(
- $my_forum
- )."&thread=".Security::remove_XSS($my_thread)."#".Security::remove_XSS(
- $my_post
- )."\" width=\"100%\"></iframe>";
- }
- if (!empty($iframe)) {
- $form->addElement('label', get_lang('Thread'), $iframe);
- }
- $form->display();
- }
- }
- function store_theme_qualify(
- $user_id,
- $thread_id,
- $thread_qualify = 0,
- $qualify_user_id = 0,
- $qualify_time,
- $session_id = null
- ) {
- $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();
- if ($user_id == strval(intval($user_id)) && $thread_id == strval(intval($thread_id)) && $thread_qualify == strval(
- floatval($thread_qualify)
- )
- ) {
-
- $sql_string = "SELECT thread_qualify_max FROM ".$table_threads." WHERE c_id = $course_id AND thread_id=".$thread_id.";";
- $res_string = Database::query($sql_string);
- $row_string = Database::fetch_array($res_string);
- if ($thread_qualify <= $row_string[0]) {
- $sql1 = "SELECT COUNT(*) FROM ".$table_threads_qualify." WHERE c_id = $course_id AND user_id=".$user_id." and thread_id=".$thread_id.";";
- $res1 = Database::query($sql1);
- $row = Database::fetch_array($res1);
- 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.", '".$qualify_user_id."','".$qualify_time."','".$session_id."')";
- $res = Database::query($sql);
- return $res;
- } else {
- $sql1 = "SELECT qualify FROM ".$table_threads_qualify." WHERE c_id = $course_id AND user_id=".$user_id." and thread_id=".$thread_id.";";
- $rs = Database::query($sql1);
- $row = Database::fetch_array($rs);
- $row[1] = "update";
- return $row;
- }
- } else {
- return null;
- }
- }
- }
- function show_qualify($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;
- }
- 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;
- }
- $rs = Database::query($sql);
- $row = Database::fetch_array($rs);
- return $row[0];
- }
- function get_historical_qualify($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();
- $my_qualify_log = array();
- 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);
- while ($row = Database::fetch_array($rs, 'ASSOC')) {
- $my_qualify_log[] = $row;
- }
- return $my_qualify_log;
- }
- function store_qualify_historical(
- $option,
- $couser_id,
- $forum_id,
- $user_id,
- $thread_id,
- $current_qualify,
- $qualify_user_id
- ) {
- $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
- $table_threads = Database::get_course_table(TABLE_FORUM_THREAD);
- $table_threads_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG);
- $current_date = date('Y-m-d H:i:s');
- $course_id = api_get_course_int_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.";";
- $rs = Database::query($sql);
- $row = Database::fetch_array($rs);
-
- $sql1 = "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($sql1);
-
- $sql2 = "UPDATE ".$table_threads_qualify." SET qualify=".$current_qualify.",qualify_time='".$current_date."' WHERE c_id = $course_id AND user_id=".$user_id." and thread_id=".$thread_id.";";
- Database::query($sql2);
- }
- }
- function current_qualify_of_thread($thread_id, $session_id)
- {
- $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY);
- $course_id = api_get_course_int_id();
- $res = Database::query(
- "SELECT qualify FROM $table_threads_qualify WHERE c_id = $course_id AND thread_id = $thread_id AND session_id = $session_id"
- );
- $row = Database::fetch_array($res, 'ASSOC');
- return $row['qualify'];
- }
- function store_reply($values)
- {
- $_course = api_get_course_info();
- global $current_forum;
- global $origin;
- $table_threads = Database :: get_course_table(TABLE_FORUM_THREAD);
- $forum_table_attachment = Database :: get_course_table(TABLE_FORUM_ATTACHMENT);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $gradebook = Security::remove_XSS($_GET['gradebook']);
- $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;
- $has_attachment = false;
- if (!empty($_FILES['user_upload']['name'])) {
- $upload_ok = FileManager::process_uploaded_file($_FILES['user_upload']);
- $has_attachment = true;
- }
- $return = array();
- if ($upload_ok) {
-
- $sql = "INSERT INTO $table_posts (c_id, post_title, post_text, thread_id, forum_id, poster_id, post_date, post_notification, post_parent_id, visible)
- VALUES (
- ".api_get_course_int_id().",
- '".Database::escape_string($values['post_title'])."',
- '".Database::escape_string(isset($values['post_text']) ? ($values['post_text']) : null)."',
- '".Database::escape_string($values['thread_id'])."',
- '".Database::escape_string($values['forum_id'])."',
- '".api_get_user_id()."',
- '".$post_date."',
- '".Database::escape_string(
- isset($values['post_notification']) ? $values['post_notification'] : null
- )."',
- '".Database::escape_string(isset($values['post_parent_id']) ? $values['post_parent_id'] : null)."',
- '".Database::escape_string($visible)."')";
- $result = Database::query($sql);
- $new_post_id = Database::insert_id();
- $values['new_post_id'] = $new_post_id;
- $message = get_lang('ReplyAdded');
- if ($has_attachment) {
- $course_dir = $_course['path'].'/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$course_dir;
-
- $new_file_name = FileManager::add_ext_on_mime(
- stripslashes($_FILES['user_upload']['name']),
- $_FILES['user_upload']['type']
- );
-
- $file_name = $_FILES['user_upload']['name'];
- if (!FileManager::filter_extension($new_file_name)) {
- $return['msg'] = get_lang('UplUnableToSaveFileFilteredExtension');
- $return['type'] = 'error';
- } else {
- $new_file_name = uniqid('');
- $new_path = $updir.'/'.$new_file_name;
- $result = @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
- $comment = $values['file_comment'];
-
- if ($result) {
- $sql = 'INSERT INTO '.$forum_table_attachment.'(c_id, filename,comment, path, post_id,size) '.
- "VALUES (".api_get_course_int_id().", '".Database::escape_string(
- $file_name
- )."', '".Database::escape_string($comment)."', '".Database::escape_string(
- $new_file_name
- )."' , '".$new_post_id."', '".intval($_FILES['user_upload']['size'])."' )";
- $result = Database::query($sql);
- $message .= ' / '.get_lang('FileUploadSucces');
- $last_id = Database::insert_id();
- api_item_property_update(
- $_course,
- TOOL_FORUM_ATTACH,
- $last_id,
- 'ForumAttachmentAdded',
- api_get_user_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);
- 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($current_post, $current_thread, $current_forum, $form_values = '', $id_attach = 0)
- {
- global $forum_setting;
- global $origin;
- $gradebook = Security::remove_XSS($_GET['gradebook']);
-
- $form = new FormValidator('edit_post', 'post', api_get_self().'?forum='.Security::remove_XSS(
- $_GET['forum']
- ).'&gradebook='.$gradebook.'&origin='.$origin.'&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'), 'class="input_titles"');
- $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->addElement('advanced_settings', 'id_qualify', get_lang('AdvancedParameters'));
- $form->addElement('html', '<div id="id_qualify_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 = 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">');
- }
-
- load_gradebook_select_in_tool($form);
- $form->addElement(
- 'text',
- 'numeric_calification',
- get_lang('QualificationNumeric'),
- 'value="'.$current_thread['thread_qualify_max'].'" style="width:40px"'
- );
- $form->applyFilter('numeric_calification', 'html_filter');
- $form->addElement(
- 'text',
- 'calification_notebook_title',
- get_lang('TitleColumnGradebook'),
- 'value="'.$current_thread['thread_title_qualify'].'"'
- );
- $form->applyFilter('calification_notebook_title', 'html_filter');
- $form->addElement(
- 'text',
- 'weight_calification',
- array(get_lang('QualifyWeight'), null, ''),
- 'value="'.$current_thread['thread_weight'].'" style="width:40px"'
- );
- $form->applyFilter('weight_calification', 'html_filter');
- $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;
- }
- }
- $attachment_list = get_attachment($current_post['post_id']);
- $message = get_lang('AddAnAttachment');
- if (!empty($attachment_list)) {
-
- $form->addElement(
- 'label',
- get_lang('EditAnAttachment'),
- Display::return_icon(
- 'attachment.gif',
- get_lang('Attachment')
- ).' '.$attachment_list['filename'].(!empty($attachment_list['comment']) ? '('.$attachment_list['comment'].')' : '')
- );
- $form->addElement('checkbox', 'remove_attach', null, get_lang('DeleteAttachmentFile'));
- } else {
-
- $form->addElement('label', $message);
- $form->addElement('file', 'user_upload', get_lang('FileName'), '');
- $form->addElement('textarea', 'file_comment', get_lang('FileComment'), array('rows' => 4, 'cols' => 34));
- $form->applyFilter('file_comment', 'html_filter');
- }
- 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->addElement('style_submit_button', 'SubmitPost', get_lang('ModifyThread'), 'class="save"');
-
- $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']);
- }
- $form->setDefaults($defaults);
-
- $form->addRule('post_title', get_lang('ThisFieldIsRequired'), 'required');
-
- if ($form->validate()) {
- $values = $form->exportValues();
- if ($values['thread_qualify_gradebook'] == '1' && empty($values['weight_calification'])) {
- Display::display_error_message(
- get_lang('YouMustAssignWeightOfQualification').' <a href="javascript:window.back()">'.get_lang(
- 'Back'
- ).'</a>',
- false
- );
- return false;
- }
- return $values;
- } else {
- $form->display();
- }
- }
- function store_edit_post($values)
- {
- global $origin;
- $table_threads = 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 = get_posts($values['thread_id']);
- $first_post = null;
- if (!empty($posts)) {
- $first_post = $posts[0];
- }
- if (!empty($first_post) && $first_post['post_id'] == $values['post_id']) {
- $sql = "UPDATE $table_threads SET
- thread_title ='".Database::escape_string($values['post_title'])."',
- thread_sticky ='".Database::escape_string(isset($values['thread_sticky']) ? $values['thread_sticky'] : null)."'," .
- "thread_title_qualify ='".Database::escape_string($values['calification_notebook_title'])."',".
- "thread_qualify_max ='".Database::escape_string($values['numeric_calification'])."',".
- "thread_weight ='".Database::escape_string($values['weight_calification'])."'".
- " WHERE c_id = $course_id AND thread_id='".intval($values['thread_id'])."'";
- Database::query($sql);
- }
-
-
- $sql = "UPDATE $table_posts SET
- post_title ='".Database::escape_string($values['post_title'])."',
- post_text ='".Database::escape_string($values['post_text'])."',
- post_notification ='".Database::escape_string(isset($values['post_notification'])?$values['post_notification']:null)."'
- WHERE c_id = $course_id AND post_id='".intval($values['post_id'])."'";
- Database::query($sql);
- if (!empty($values['remove_attach'])) {
- delete_attachment($values['post_id']);
- }
- if (empty($values['id_attach'])) {
- add_forum_attachment_file($values['file_comment'], $values['post_id']);
- } else {
- edit_forum_attachment_file($values['file_comment'], $values['post_id'], $values['id_attach']);
- }
- if (api_is_course_admin() == true) {
- $ccode = api_get_course_id();
- $sid = api_get_session_id();
- $link_info = 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) {
- remove_resource_from_course_gradebook($link_id);
- }
- } else {
- if ($link_info === false && !$_GET['thread']) {
- $weigthqualify = $values['weight_calification'];
- 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']
- ).'&gidReq='.$_SESSION['toolgroup'].'&origin='.$origin.'">'.get_lang('Forum').'</a><br />';
- $message .= get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&forum='.Security::remove_XSS(
- $_GET['forum']
- ).'&gidReq='.$_SESSION['toolgroup'].'&origin='.$origin.'&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) {
- return '<a title="'.api_htmlentities(
- $in_title,
- ENT_QUOTES
- ).'" href="../user/userInfo.php?uInfo='.$user_id.'" '.(!empty($origin) ? 'target="_self"' : '').'>'.$name.'</a>';
- } else {
- return $name.' ('.get_lang('Anonymous').')';
- }
- }
- function display_user_image($user_id, $name, $origin = '')
- {
- $link = '<a href="../user/userInfo.php?uInfo='.$user_id.'" '.(!empty($origin) ? 'target="_self"' : '').'>';
- $attrb = array();
- if ($user_id != 0) {
- $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
- $image_repository = $image_path['dir'];
- $existing_image = $image_path['file'];
- $friends_profile = UserManager::get_picture_user(
- $user_id,
- $image_path['file'],
- 0,
- USER_IMAGE_SIZE_MEDIUM,
- 'width="96" height="96" '
- );
- return $link.'<img src="'.$friends_profile['file'].'" '.$friends_profile['style'].' alt="'.$name.'" title="'.$name.'" /></a>';
- } else {
- return $link.Display::return_icon('unknown.jpg', $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
- )."'";
- $result = 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
- )."'";
- $result = Database::query($sql);
- }
- function forum_not_allowed_here()
- {
- Display :: display_error_message(get_lang('NotAllowedHere'));
- Display :: display_footer();
- return false;
- }
- function get_whats_new()
- {
- global $_user;
- $_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();
- if (!$_SESSION['last_forum_access']) {
- $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'];
- }
- if (!$_SESSION['whatsnew_post_info']) {
- if ($_SESSION['last_forum_access'] != '') {
- $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();
- $sql = "SELECT count(*) as number_of_posts FROM $table_posts WHERE forum_id='".$forum_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_mailcue = 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 = 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) {
- send_notifications($current_thread['forum_id'], $thread_id);
- } else {
- $table_notification = Database::get_course_table(TABLE_FORUM_NOTIFICATION);
- $sql = "SELECT * FROM $table_notification WHERE c_id = ".api_get_course_int_id(
- )." AND (forum_id = '".Database::escape_string(
- $current_forum['forum_id']
- )."' OR thread_id = '".Database::escape_string($thread_id)."' ) ";
- $result = Database::query($sql);
- $user_id = api_get_user_id();
- while ($row = Database::fetch_array($result)) {
- $sql_mailcue = "INSERT INTO $table_mailcue (c_id, thread_id, post_id, user_id)
- VALUES (".api_get_course_int_id().", '".Database::escape_string(
- $thread_id
- )."', '".Database::escape_string($reply_info['new_post_id'])."', '$user_id' )";
- Database::query($sql_mailcue);
- }
- }
- }
- 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 = Database::escape_string($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']));
- }
-
- $sql_delete_mailcue = "DELETE FROM $table_mailcue WHERE c_id = $course_id AND post_id='".Database::escape_string(
- $id
- )."' AND thread_id='".Database::escape_string($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='".Database::escape_string($id)."'
- AND posts.post_notification='1'
- AND mailcue.thread_id='".Database::escape_string($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_mailcue = "DELETE FROM $table_mailcue WHERE c_id = $course_id AND thread_id='".Database::escape_string(
- $id
- )."'";
- $result = Database::query($sql_delete_mailcue);
- } 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()
- {
- global $origin;
- $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']
- ).'&origin='.$origin);
-
- $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->addElement('style_submit_button', 'SubmitForum', get_lang('MoveThread'), 'class="save"');
-
- if ($form->validate()) {
- $values = $form->exportValues();
- if (isset($_POST['forum'])) {
- store_move_thread($values);
- }
- } else {
- $form->display();
- }
- }
- function move_post_form()
- {
- global $origin;
- $gradebook = Security::remove_XSS($_GET['gradebook']);
-
- $form = new FormValidator('movepost', 'post', api_get_self().'?forum='.Security::remove_XSS(
- $_GET['forum']
- ).'&thread='.Security::remove_XSS(
- $_GET['thread']
- ).'&origin='.$origin.'&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', strval(intval($_GET['post'])));
-
- $threads = get_threads(strval(intval($_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->addElement('style_submit_button', 'submit', get_lang('MovePost'), 'class="save"');
-
- $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();
- $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);
- $course_id = api_get_course_int_id();
- if ($values['thread'] == '0') {
- $current_post = get_post_information($values['post_id']);
-
- $sql = "INSERT INTO $table_threads (c_id, thread_title, forum_id, thread_poster_id, thread_poster_name, thread_last_post, thread_date)
- VALUES (
- ".$course_id.",
- '".Database::escape_string($current_post['post_title'])."',
- '".Database::escape_string($current_post['forum_id'])."',
- '".Database::escape_string($current_post['poster_id'])."',
- '".Database::escape_string($current_post['poster_name'])."',
- '".Database::escape_string($values['post_id'])."',
- '".Database::escape_string($current_post['post_date'])."'
- )";
- $result = Database::query($sql);
- $new_thread_id = Database::insert_id();
- api_item_property_update($_course, TOOL_FORUM_THREAD, $new_thread_id, 'visible', $current_post['poster_id']);
-
- $sql = "UPDATE $table_posts SET thread_id='".Database::escape_string(
- $new_thread_id
- )."', post_parent_id='0' WHERE c_id = $course_id AND post_id='".Database::escape_string($values['post_id'])."'";
- $result = Database::query($sql);
-
- $sql = "UPDATE $table_posts SET post_parent_id='0' WHERE c_id = $course_id AND post_parent_id='".Database::escape_string(
- $values['post_id']
- )."'";
- $result = Database::query($sql);
-
- $sql = "UPDATE $table_forums SET forum_threads=forum_threads+1 WHERE c_id = $course_id AND forum_id='".Database::escape_string(
- $current_post['forum_id']
- )."'";
- $result = Database::query($sql);
-
- $sql = "SELECT * FROM $table_posts WHERE c_id = $course_id AND thread_id='".Database::escape_string(
- $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='".Database::escape_string(
- $current_post['thread_id']
- )."'";
- $result = 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."' ";
- $result = Database::query($sql);
- }
- $sql = "UPDATE $table_threads SET thread_replies=thread_replies-1 WHERE c_id = $course_id AND thread_id='".$original_thread_id."'";
- $result = 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'])."'";
- $result = 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']
- )."'";
- $result = Database::query($sql);
- $sql = "UPDATE $table_threads SET thread_replies=thread_replies+1 WHERE c_id = $course_id AND thread_id='".intval(
- $_POST['thread']
- )."'";
- $result = Database::query($sql);
- }
- return get_lang('ThreadMoved');
- }
- function store_move_thread($values)
- {
- $_course = api_get_course_info();
- $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);
- $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'])."'";
- $result = 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'])."'";
- $result = 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()
- {
- global $origin;
-
- $form = new FormValidator('forumsearch', 'post', 'forumsearch.php?origin='.$origin.'');
-
- $form->addElement('header', '', get_lang('ForumSearch'));
- $form->addElement('text', 'search_term', get_lang('SearchTerm'), 'class="input_titles" id="search_title"');
- $form->applyFilter('search_term', 'html_filter');
- $form->addElement(
- 'static',
- 'search_information',
- '',
- get_lang('ForumSearchInformation')
- );
- $form->addElement('style_submit_button', null, get_lang('Search'), 'class="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)
- {
- global $origin;
- $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);
- $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
- $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 $key => $value) {
- $search_restriction[] = "(posts.post_title LIKE '%".Database::escape_string(trim($value))."%'
- OR posts.post_text LIKE '%".Database::escape_string(trim($value))."%')";
- }
- $sql = "SELECT * FROM $table_posts posts
- WHERE c_id = $course_id 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[$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?forumcategory='.$forum_list[$row['forum_id']]['forum_category'].'&origin='.$origin.'&search='.urlencode(
- $search_term
- ).'">'.prepare4display(
- $forum_categories_list[$row['forum_id']['forum_category']]['cat_title']
- ).'</a> > ';
- $search_results_item .= '<a href="viewforum.php?forum='.$row['forum_id'].'&origin='.$origin.'&search='.urlencode(
- $search_term
- ).'">'.prepare4display($forum_list[$row['forum_id']]['forum_title']).'</a> > ';
-
- $search_results_item .= '<a href="viewthread.php?forum='.$row['forum_id'].'&gradebook='.$gradebook.'&origin='.$origin.'&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()
- {
- global $origin;
- $return = '';
- if ($origin != 'learnpath') {
- $return = '<a href="forumsearch.php?'.api_get_cidreq().'&gidReq='.api_get_group_id(
- ).'&action=search&origin='.$origin.'"> ';
- $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 (!empty($_FILES['user_upload']['name'])) {
- $upload_ok = FileManager::process_uploaded_file($_FILES['user_upload']);
- }
- if (!empty($upload_ok)) {
- $course_dir = $_course['path'].'/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$course_dir;
-
- $new_file_name = FileManager::add_ext_on_mime(
- stripslashes($_FILES['user_upload']['name']),
- $_FILES['user_upload']['type']
- );
-
- $file_name = $_FILES['user_upload']['name'];
- if (!FileManager::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($_FILES['user_upload']['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) {
- $sql = "INSERT INTO $agenda_forum_attachment (c_id, filename, comment, path, post_id, size)
- VALUES (".api_get_course_int_id(
- ).", '$safe_file_name', '$safe_file_comment', '$safe_new_file_name' , '$last_id', '".intval(
- $_FILES['user_upload']['size']
- )."' )";
- $result = Database::query($sql);
- $message .= ' / '.get_lang('FileUploadSucces').'<br />';
- $last_id_file = Database::insert_id();
- 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();
-
- if (!empty($_FILES['user_upload']['name'])) {
- $upload_ok = FileManager::process_uploaded_file($_FILES['user_upload']);
- }
- if (!empty($upload_ok)) {
- $course_dir = $_course['path'].'/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$course_dir;
-
- $new_file_name = FileManager::add_ext_on_mime(
- stripslashes($_FILES['user_upload']['name']),
- $_FILES['user_upload']['type']
- );
-
- $file_name = $_FILES['user_upload']['name'];
- if (!FileManager::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($_FILES['user_upload']['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 ='".$_FILES['user_upload']['size']."'
- WHERE c_id = $course_id AND id = '$safe_id_attach'";
- $result = 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 id, 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 delete_attachment($post_id, $id_attach = 0)
- {
- $_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)) ? " id = ".(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);
- $last_id_file = Database::insert_id();
-
- api_item_property_update($_course, TOOL_FORUM_ATTACH, $id_attach, 'ForumAttachmentDelete', api_get_user_id());
- if (!empty($result) && !empty($id_attach)) {
- $message = get_lang(get_lang('AttachmentFileDeleteSuccess'));
- Display::display_confirmation_message($message);
- }
- }
- 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);
- $table_users = Database :: get_main_table(TABLE_MAIN_USER);
- $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 (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);
- 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 (is_array($forum_list)) {
- foreach ($forum_list as $key => $value) {
- $last_post_info_of_forum = get_last_post_information($key, 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)
- {
- global $_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 * FROM $table_notification WHERE c_id = $course_id AND $database_field = '".Database::escape_string(
- $id
- )."' AND user_id = '".Database::escape_string($_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
- )."','".Database::escape_string($_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 = '".Database::escape_string($_user['user_id'])."'";
- $result = 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)
- {
- global $_user;
- $_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) {
- if ($value['email'] != $_user['email']) {
- $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(
- $value['user_id'],
- $subject,
- $email_body,
- null,
- null,
- null,
- null,
- null,
- null,
- $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='".Database::escape_string(
- $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='".Database::escape_string(
- $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=".Database::escape_string($thread_id)." AND
- poster_id = ".Database::escape_string($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_course_rel_user = Database::get_main_table('course_rel_user');
- $sql = "SELECT * FROM $table_course_rel_user WHERE course_code ='".Database::escape_string($course_id)."' ";
- $result = Database::query($sql);
- return count(Database::store_result($result));
- }
- function get_statistical_information($thread_id, $user_id, $course_id)
- {
- $stadistic = array();
- $stadistic['user_course'] = count_number_of_user_in_course($course_id);
- $stadistic['post'] = count_number_of_post_in_thread($thread_id);
- $stadistic['user_post'] = count_number_of_post_for_user_thread($thread_id, $user_id);
-
- return $stadistic;
- }
- 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);
- while ($row = Database::fetch_array($result)) {
- $row['status'] = '1';
- $post_list[] = $row;
- }
- return $post_list;
- }
- 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;
- _phorum_recursive_sort($rows, $sorted_rows);
- unset($sorted_rows[0]);
- }
- return $sorted_rows;
- }
- function _phorum_recursive_sort($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) {
- _phorum_recursive_sort($rows, $threads, $child, $indent);
- }
- }
- }
|