12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641 |
- <?php
-
-
- require_once(api_get_path(INCLUDE_PATH).'/lib/mail.lib.inc.php');
- require_once(api_get_path(INCLUDE_PATH).'/conf/mail.conf.php');
- require_once(api_get_path(INCLUDE_PATH).'/lib/usermanager.lib.php');
- get_notifications_of_user();
- function handle_forum_and_forumcategories() {
- $action_forum_cat = isset($_GET['action']) ? $_GET['action'] : '';
- $post_submit_cat= isset($_POST['SubmitForumCategory']) ? $_POST['SubmitForumCategory'] : '';
- $post_submit_forum= isset($_POST['SubmitForum']) ? $_POST['SubmitForum'] : '';
- $get_id=isset($_GET['id']) ? $_GET['id'] : '';
-
- if (($action_forum_cat=='add' && $_GET['content']=='forumcategory') || $post_submit_cat ) {
- show_add_forumcategory_form();
- }
-
- 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(strval(intval($get_id)));
- } else {
- $inputvalues='';
- }
- show_add_forum_form($inputvalues);
- }
-
- if (($action_forum_cat=='edit' && $_GET['content']=='forumcategory' && isset($_GET['id'])) || $_POST['SubmitEditForumCategory'] )
- {
- $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=Security::remove_XSS($get_id);
- $list_threads=get_threads($id_forum);
-
- for ( $i=0; $i < count($list_threads); $i++ ) {
- $messaje=delete_forum_forumcategory_thread('thread',$list_threads[$i]['thread_id']);
- $table_link = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
- $sql_link='DELETE FROM '.$table_link.' WHERE ref_id='.$list_threads[$i]['thread_id'].' and type=5 and course_code="'.api_get_course_id().'";';
- api_sql_query($sql_link,__FILE__,__LINE__);
- }
- $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()) {
-
- $form = new FormValidator('forumcategory','post');
-
- $form->addElement('header', '', get_lang('AddForumCategory'));
- $form->addElement('text', 'forum_category_title', get_lang('Title'),'class="input_titles"');
- $form->addElement('html_editor', 'forum_category_comment', get_lang('Comment'));
- $form->addElement('submit', 'SubmitForumCategory', get_lang('Ok'));
-
- $form->addRule('forum_category_title', '<div class="required">'.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()) {
- global $_course;
-
- $form = new FormValidator('forumcategory', 'post', 'index.php');
-
- $session_header = isset($_SESSION['session_name']) ? ' ('.$_SESSION['session_name'].') ' : '';
- $form->addElement('header', '', get_lang('AddForum').$session_header);
-
- if (is_array($inputvalues)) {
- $my_forum_id=isset($inputvalues['forum_id']) ? $inputvalues['forum_id'] : null;
- $form->addElement('hidden', 'forum_id', $my_forum_id);
- }
-
- $form->addElement('text', 'forum_title', get_lang('Title'),'class="input_titles"');
-
- $form->addElement('html_editor', 'forum_comment', get_lang('Comment'));
-
- $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);
- if ($_course['visibility']==COURSE_VISIBILITY_OPEN_WORLD) {
-
-
-
-
- $group='';
- $group[] =& HTML_QuickForm::createElement('radio', 'allow_anonymous',null,get_lang('Yes'),1);
- $group[] =& HTML_QuickForm::createElement('radio', 'allow_anonymous',null,get_lang('No'),0);
- $form->addGroup($group, 'allow_anonymous_group', get_lang('AllowAnonymousPosts'), ' ');
- }
-
-
-
-
-
-
-
- $form->addElement('static','Group','<div id="plus"><a href="javascript://" onclick="advanced_parameters()" ><br /><span id="plus_minus"> <img src="../img/nolines_plus.gif" alt="" /> '.get_lang('AdvancedParameters').'</span></a></div>');
- $form->addElement('html','<div id="options" style="display:none">');
-
- $group='';
- $group[] =& HTML_QuickForm::createElement('radio', 'students_can_edit',null,get_lang('Yes'),1);
- $group[] =& HTML_QuickForm::createElement('radio', 'students_can_edit',null,get_lang('No'),0);
- $form->addGroup($group, 'students_can_edit_group', get_lang('StudentsCanEdit'), ' ');
-
-
-
-
- $group='';
- $group[] =& HTML_QuickForm::createElement('radio', 'approval_direct',null,get_lang('Approval'),1);
- $group[] =& HTML_QuickForm::createElement('radio', 'approval_direct',null,get_lang('Direct'),0);
-
-
-
-
-
- $group='';
- $group[] =& HTML_QuickForm::createElement('radio', 'allow_attachments',null,get_lang('Yes'),1);
- $group[] =& HTML_QuickForm::createElement('radio', 'allow_attachments',null,get_lang('No'),0);
-
-
-
-
-
- $group='';
- $group[] =& HTML_QuickForm::createElement('radio', 'allow_new_threads',null, get_lang('Yes'),1);
- $group[] =& HTML_QuickForm::createElement('radio', 'allow_new_threads',null, get_lang('No'),0);
- $form->addGroup($group, 'allow_new_threads_group', get_lang('AllowNewThreads'), ' ');
- $group='';
- $group[] =& HTML_QuickForm::createElement('radio', 'default_view_type', null, get_lang('Flat'), 'flat');
- $group[] =& HTML_QuickForm::createElement('radio', 'default_view_type', null, get_lang('Threaded'), 'threaded');
- $group[] =& HTML_QuickForm::createElement('radio', 'default_view_type', null, get_lang('Nested'), 'nested');
- $form->addGroup($group, 'default_view_type_group', get_lang('DefaultViewType'), ' ');
- $form->addElement('static','Group', '<br /><strong>'.get_lang('GroupSettings').'</strong>');
-
- $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='';
- $group[] =& HTML_QuickForm::createElement('radio', 'public_private_group_forum', null, get_lang('Public'), 'public');
- $group[] =& HTML_QuickForm::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 = @getimagesize($image_path);
- $img_attributes = '';
- if (!empty($image_size)) {
- if ($image_size[0] > 100 || $image_size[1] > 100) {
-
- $img_attributes = 'width="100" height="100"';
- }
- $show_preview_image='<img src="'.$image_path.'" '.$img_attributes.'>';
- $div = '<div class="row">
- <div class="label">'.get_lang('PreviewImage').'</div>
- <div class="formw">
- '.$show_preview_image.'
- </div>
- </div>';
-
- $form->addElement('html', $div .'<br/>');
- $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'), 'mimetype', array('image/gif', 'image/jpeg', 'image/png'));
- $form->addElement('html','</div>');
-
- $form->addElement('submit', 'SubmitForum', get_lang('Ok'));
-
- $form->addRule('forum_title', get_lang('ThisFieldIsRequired'), 'required');
- $form->addRule('forum_category', get_lang('ThisFieldIsRequired'), 'required');
- global $charset;
-
-
- if (!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(html_entity_decode(isset($inputvalues['forum_title']) ? $inputvalues['forum_title'] : null,ENT_QUOTES,$charset));
- $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();
- store_forum($values);
- }
- 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);
- echo '<br />';
- $sql="SELECT forum_image FROM $table_forums WHERE forum_id = '".$forum_id."' ";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $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()) {
-
- $form = new FormValidator('forumcategory','post');
-
- $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'));
- $form->addElement('submit', 'SubmitEditForumCategory',get_lang('Ok'));
- global $charset;
-
- $defaultvalues['forum_category_id']=$inputvalues['cat_id'];
- $defaultvalues['forum_category_title']=prepare4display(html_entity_decode($inputvalues['cat_title'],ENT_QUOTES,$charset));
- $defaultvalues['forum_category_comment']=prepare4display($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) {
- global $table_categories;
- global $_course;
- global $_user;
-
- $sql="SELECT MAX(cat_order) as sort_max FROM ".Database::escape_string($table_categories);
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $row=Database::fetch_array($result);
- $new_max=$row['sort_max']+1;
-
- $clean_cat_title=Security::remove_XSS(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 cat_id='".Database::escape_string($values['forum_category_id'])."'";
- api_sql_query($sql,__FILE__,__LINE__);
- $last_id=Database::get_last_insert_id();
- api_item_property_update($_course, TOOL_FORUM_CATEGORY, $values['forum_category_id'],"ForumCategoryAdded", api_get_user_id());
- $return_message=get_lang('ForumCategoryEdited');
- } else {
- $sql="INSERT INTO ".$table_categories." (cat_title, cat_comment, cat_order) VALUES ('".$clean_cat_title."','".Database::escape_string($values['forum_category_comment'])."','".Database::escape_string($new_max)."')";
- api_sql_query($sql,__FILE__,__LINE__);
- $last_id=Database::get_last_insert_id();
- api_item_property_update($_course, TOOL_FORUM_CATEGORY, $last_id,"ForumCategoryAdded", api_get_user_id());
- $return_message=get_lang('ForumCategoryAdded');
- }
- Display :: display_confirmation_message($return_message);
- }
- function store_forum($values) {
- global $_course;
- global $_user;
-
- $table_forums = Database::get_course_table(TABLE_FORUM);
-
- $sql="SELECT MAX(forum_order) as sort_max FROM ".$table_forums." WHERE forum_category=".Database::escape_string($values['forum_category']);
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $row=Database::fetch_array($result);
- $new_max=$row['sort_max']+1;
- $session_id = isset($_SESSION['id_session']) ? $_SESSION['id_session'] : 0;
-
- $clean_title=Security::remove_XSS(Database::escape_string(htmlspecialchars($values['forum_title'])));
-
-
- $image_moved=false;
- if (!empty($_FILES['picture']['name'])) {
- $upload_ok = process_uploaded_file($_FILES['picture']);
- $has_attachment=true;
- } else {
- $image_moved=true;
- }
-
-
- if (!empty($_POST['remove_picture'])) {
- delete_forum_image($values['forum_id']);
- }
-
- if (isset($upload_ok)) {
- if ($has_attachment) {
- $courseDir = $_course['path'].'/upload/forum/images';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$courseDir;
-
- $new_file_name = add_ext_on_mime(Database::escape_string($_FILES['picture']['name']), $_FILES['picture']['type']);
-
- $file_name =$_FILES['picture']['name'];
-
- if (!filter_extension($new_file_name)) {
-
- $image_moved=false;
- } else {
- $file_extension = explode('.', $_FILES['picture']['name']);
- $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
- $new_file_name = uniqid('').'.'.$file_extension;
- $new_path=$updir.'/'.$new_file_name;
- $result= @move_uploaded_file($_FILES['picture']['tmp_name'], $new_path);
-
- if ($result) {
- $image_moved=true;
- }
- }
- }
- }
-
- if (isset($values['forum_id'])) {
- $sql_image=isset($sql_image)?$sql_image:'';
- $new_file_name=isset($new_file_name) ? $new_file_name:'';
- if ($image_moved) {
- if(empty($_FILES['picture']['name'])){
- $sql_image=" ";
- } else {
- $sql_image=" 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($values['forum_comment'])."',
- forum_category='".Database::escape_string($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 forum_id='".Database::escape_string($values['forum_id'])."'";
- api_sql_query($sql,__FILE__,__LINE__);
- $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."', ";
- }
-
- $sql="INSERT INTO ".$table_forums."
- (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 ('".$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).")";
- api_sql_query($sql,__FILE__,__LINE__);
- $last_id=Database::get_last_insert_id();
- api_item_property_update($_course, TOOL_FORUM, $last_id,"ForumCategoryAdded", api_get_user_id());
- $return_message=get_lang('ForumAdded');
- }
- return $return_message;
- }
- function delete_forum_forumcategory_thread($content, $id) {
- global $_course;
- $table_forums = Database::get_course_table(TABLE_FORUM);
- $table_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD);
- 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 forum_category='".$id."'";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $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 forum_id='".$id."'";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $row = mysql_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) {
- global $table_posts;
- global $table_threads;
- $sql="DELETE FROM $table_posts WHERE post_id='".Database::escape_string($post_id)."'";
- api_sql_query($sql,__FILE__,__LINE__);
-
- delete_attachment($post_id);
-
- $last_post_of_thread=check_if_last_post_of_thread(strval(intval($_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 thread_id='".Database::escape_string($_GET['thread'])."'";
- api_sql_query($sql,__FILE__,__LINE__);
- return 'PostDeleted';
- }
- if ($last_post_of_thread==false) {
-
- $sql="DELETE FROM $table_threads WHERE thread_id='".Database::escape_string($_GET['thread'])."'";
- api_sql_query($sql,__FILE__,__LINE__);
- return 'PostDeletedSpecial';
- }
- }
- function check_if_last_post_of_thread($thread_id) {
- global $table_posts;
- $sql="SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."' ORDER BY post_date DESC";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- 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;
- $id = Security::remove_XSS($id);
- if ($current_visibility_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=invisible&content='.$content.'&id='.$id.'&origin='.$origin.'">'.icon('../img/visible.gif',get_lang('MakeInvisible')).'</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.'&origin='.$origin.'">'.icon('../img/invisible.gif',get_lang('MakeVisible')).'</a>';
- }
- }
- function display_lock_unlock_icon($content, $id, $current_lock_status, $additional_url_parameters='')
- {
- $id = Security::remove_XSS($id);
- 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.'">'.icon('../img/lock.gif',get_lang('Unlock')).'</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.'">'.icon('../img/unlock.gif',get_lang('Lock')).'</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().'&action=move&direction=up&content='.$content.'&forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&id='.$id.'" title="'.get_lang('MoveUp').'"><img src="../img/up.gif" /></a>';
- } else {
- $return_value='<img src="../img/up_na.gif" />';
- }
-
- if ($position<$total_items) {
- $return_value.='<a href="'.api_get_self().'?'.api_get_cidreq().'&action=move&direction=down&content='.$content.'&forumcategory='.Security::remove_XSS($_GET['forumcategory']).'&id='.$id.'" title="'.get_lang('MoveDown').'" ><img src="../img/down.gif" /></a>';
- } else {
-
- $return_value.='<img src="../img/down_na.gif" />';
- }
- echo $return_value;
- }
- function change_visibility($content, $id, $target_visibility) {
- global $_course;
- $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) {
- global $table_categories;
- global $table_forums;
- global $table_threads;
- global $table_posts;
-
- 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');
- }
-
- $sql="UPDATE $table SET locked='".Database::escape_string($db_locked)."' WHERE $id_field='".Database::escape_string($id)."'";
- if (api_sql_query($sql,__FILE__,__LINE__)) {
- return $return_message;
- } else {
- return get_lang('Error');
- }
- }
- function move_up_down($content, $direction, $id) {
- global $table_categories;
- global $table_forums;
- global $table_item_property;
-
- 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 forum_id=".Database::escape_string($id);
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $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.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 forum_category='".Database::escape_string($forum_category)."' ORDER BY forum_order $sort_direction";
- }
-
-
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $found=false;
- while ($row=Database::fetch_array($result)) {
-
- if ($found==true) {
- $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 $id_column='".Database::escape_string($next_id)."'";
- $sql_update2="UPDATE $table SET $sort_column='".Database::escape_string($next_sort)."' WHERE $id_column='".Database::escape_string($this_id)."'";
- api_sql_query($sql_update1,__FILE__,__LINE__);
- api_sql_query($sql_update2,__FILE__,__LINE__);
- }
- 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();
- 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."'
- 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."'
- 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)."'
- ORDER BY forum_categories.cat_order ASC";
- }
- $result=api_sql_query($sql,__FILE__,__LINE__);
- 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)
- {
- global $table_forums;
- global $table_item_property;
- $forum_list=array();
- $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.tool='".TOOL_FORUM."'
- 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."'
- ORDER BY forum_order ASC";
- }
- $result=api_sql_query($sql,__FILE__,__LINE__);
- while ($row=Database::fetch_array($result)) {
- $forum_list[$row['forum_id']]=$row;
- }
- return $forum_list;
- }
- function get_forums($id='') {
- global $table_forums;
- global $table_threads;
- global $table_posts;
- global $table_item_property;
- global $table_users;
-
-
- $session_condition = isset($_SESSION['id_session']) ? 'AND forum.session_id IN (0,'.intval($_SESSION['id_session']).')' : '';
- $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."'
- $session_condition
- 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."'
- 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."'
- 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."'
- $session_condition
- 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."'
- GROUP BY threads.forum_id";
-
-
- $sql3="SELECT count(*) AS number_of_posts, forum_id FROM $table_posts GROUP BY 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."'
- $session_condition
- ORDER BY forum_order ASC";
-
- $sql2="SELECT count(*) AS number_of_threads, forum_id FROM $table_threads WHERE forum_id=".Database::escape_string($id)." GROUP BY forum_id";
-
- $sql3="SELECT count(*) AS number_of_posts, forum_id FROM $table_posts WHERE forum_id=".Database::escape_string($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
- GROUP BY post.forum_id
- ORDER BY post.post_id ASC";
- }
-
- $result=api_sql_query($sql,__FILE__,__LINE__);
- while ($row=Database::fetch_array($result)) {
- if ($id=='') {
- $forum_list[$row['forum_id']]=$row;
- } else {
- $forum_list=$row;
- }
- }
-
- $result2=api_sql_query($sql2,__FILE__,__LINE__);
- 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=api_sql_query($sql3,__FILE__,__LINE__);
- 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,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'];
- }
- } else {
- $forum_list = array();
- }
- } else {
- $last_post_info_of_forum=get_last_post_information($id,is_allowed_to_edit());
- $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_information($forum_id, $show_invisibles=false) {
- global $table_forums;
- global $table_threads;
- global $table_posts;
- global $table_item_property;
- global $table_users;
- $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."'
- ORDER BY post.post_id DESC";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- if ($show_invisibles==true) {
- $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' AND $row['thread_visibility']=='1' AND $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) {
- global $table_item_property;
- global $table_threads;
- global $table_posts;
- global $table_users;
- $thread_list=array();
-
-
-
-
-
- $sql = "SELECT thread.*, item_properties.*, post.*, users.firstname, users.lastname, users.user_id,
- last_poster_users.firstname as last_poster_firstname , last_poster_users.lastname as last_poster_lastname, last_poster_users.user_id as last_poster_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.visibility='1'
- AND item_properties.tool='".TOOL_FORUM_THREAD."'
- LEFT JOIN $table_users users
- ON thread.thread_poster_id=users.user_id
- LEFT JOIN $table_posts post
- ON thread.thread_last_post = post.post_id
- LEFT JOIN $table_users last_poster_users
- ON post.poster_id= last_poster_users.user_id
- WHERE 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.*, post.*, users.firstname, users.lastname, users.user_id,
- last_poster_users.firstname as last_poster_firstname , last_poster_users.lastname as last_poster_lastname, last_poster_users.user_id as last_poster_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.visibility<>2
- AND item_properties.tool='".TOOL_FORUM_THREAD."'
- LEFT JOIN $table_users users
- ON thread.thread_poster_id=users.user_id
- LEFT JOIN $table_posts post
- ON thread.thread_last_post = post.post_id
- LEFT JOIN $table_users last_poster_users
- ON post.poster_id= last_poster_users.user_id
- WHERE thread.forum_id='".Database::escape_string($forum_id)."'
- ORDER BY thread.thread_sticky DESC, thread.thread_date DESC";
- }
- $result=api_sql_query($sql, __FILE__, __LINE__);
- while ( $row=Database::fetch_array($result,'ASSOC') ) {
- $thread_list[]=$row;
- }
- return $thread_list;
- }
- function get_posts($thread_id) {
- global $table_posts;
- global $table_users;
-
- if (api_is_allowed_to_edit()) {
- $sql = "SELECT * FROM $table_posts posts
- LEFT JOIN $table_users users
- ON posts.poster_id=users.user_id
- WHERE 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 posts.thread_id='".Database::escape_string($thread_id)."'
- AND posts.visible='1'
- ORDER BY posts.post_id ASC";
- }
- $result=api_sql_query($sql, __FILE__, __LINE__);
- while ($row=Database::fetch_array($result)) {
- $post_list[]=$row;
- }
- return $post_list;
- }
- function icon($image_url,$alt='',$title='') {
- if ($title=='') {
- $title=$alt;
- }
- return '<img src="'.$image_url.'" alt="'.$alt.'" title="'.$title.'" />';
- }
- function get_post_information($post_id) {
- global $table_posts;
- global $table_users;
- $sql="SELECT * FROM ".$table_posts."posts, ".$table_users." users WHERE posts.poster_id=users.user_id AND posts.post_id='".Database::escape_string($post_id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- $row=Database::fetch_array($result);
- return $row;
- }
- function get_thread_information($thread_id) {
- global $table_threads;
- global $table_item_property;
- $sql="SELECT * FROM ".$table_threads." threads, ".$table_item_property." item_properties
- WHERE item_properties.tool='".TOOL_FORUM_THREAD."'
- AND item_properties.ref='".Database::escape_string($thread_id)."'
- AND threads.thread_id='".Database::escape_string($thread_id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- $row=Database::fetch_array($result);
- return $row;
- }
- function get_thread_users_details($thread_id, $db_name = null) {
- $t_posts = Database :: get_course_table(TABLE_FORUM_POST, (empty($db_name)?null:$db_name));
- $t_users = Database :: get_main_table(TABLE_MAIN_USER);
- $sql = "SELECT DISTINCT user_id, lastname, firstname, thread_id
- FROM $t_posts , $t_users
- WHERE poster_id = user_id
- AND thread_id = '".Database::escape_string($thread_id)."'
- AND status not in('1')";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- return $result;
- }
- function get_thread_users_qualify($thread_id, $db_name = null) {
- $t_posts = Database :: get_course_table(TABLE_FORUM_POST, (empty($db_name)?null:$db_name));
- $t_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY, (empty($db_name)?null:$db_name));
- $t_users = Database :: get_main_table(TABLE_MAIN_USER);
-
-
- $sql = "SELECT 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
- WHERE
- post.poster_id = user.user_id
- AND post.poster_id = qualify.user_id
- AND qualify.thread_id = '".Database::escape_string($thread_id)."'
- AND user.status not in('1')
- GROUP BY post.poster_id ";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- return $result;
- }
- function get_thread_users_not_qualify($thread_id, $db_name = null) {
- $t_posts = Database :: get_course_table(TABLE_FORUM_POST, (empty($db_name)?null:$db_name));
- $t_qualify = Database :: get_course_table(TABLE_FORUM_THREAD_QUALIFY, (empty($db_name)?null:$db_name));
- $t_users = Database :: get_main_table(TABLE_MAIN_USER);
-
- $sql1 = "select user_id FROM $t_qualify WHERE thread_id = '".$thread_id."'";
- $result1 = api_sql_query($sql1,__FILE__,__LINE__);
- $cad='';
- while ($row=Database::fetch_array($result1)) {
- $cad .= $row['user_id'].',';
- }
- if($cad=='') {
- $cad='0';
- } else {
- $cad=substr($cad,0,strlen($cad)-1);
- }
- $sql = "SELECT DISTINCT user.user_id, user.lastname, user.firstname, post.thread_id
- FROM $t_posts post, $t_users user
- WHERE post.poster_id = user.user_id
- AND user.user_id NOT IN (".$cad.")
- AND post.thread_id = '".Database::escape_string($thread_id)."'
- AND user.status not in('1')";
-
- $result = api_sql_query($sql, __FILE__, __LINE__);
- return $result;
- }
- function get_forum_information($forum_id) {
- global $table_forums;
- global $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 forums.forum_id='".Database::escape_string($forum_id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- $row=Database::fetch_array($result);
- $row['approval_direct_post'] = 0;
- return $row;
- }
- function get_forumcategory_information($cat_id) {
- global $table_categories;
- global $table_item_property;
- $sql="SELECT * FROM ".$table_categories." forumcategories, ".$table_item_property." item_properties
- WHERE 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=api_sql_query($sql, __FILE__, __LINE__);
- $row=Database::fetch_array($result);
- return $row;
- }
- function count_number_of_forums_in_category($cat_id) {
- global $table_forums;
- $sql="SELECT count(*) AS number_of_forums FROM ".$table_forums." WHERE forum_category='".Database::escape_string($cat_id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- $row=Database::fetch_array($result);
- return $row['number_of_forums'];
- }
- function store_thread($values) {
- global $table_threads;
- global $table_posts;
- global $_user;
- global $_course;
- global $current_forum;
- global $origin;
- global $forum_table_attachment;
- $upload_ok=1;
- $has_attachment=false;
-
- if(!empty($_FILES['user_upload']['name'])) {
- $upload_ok = process_uploaded_file($_FILES['user_upload']);
- $has_attachment=true;
- }
- if($upload_ok) {
-
- $post_date=date('Y-m-d H:i:s');
-
- if ($current_forum['approval_direct_post']=='1' AND !api_is_allowed_to_edit()) {
- $visible=0;
- } else {
- $visible=1;
- }
-
- $clean_post_title=Security::remove_XSS(Database::escape_string(htmlspecialchars($values['post_title'])));
-
-
- $sql="INSERT INTO $table_threads (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 ('".$clean_post_title."',
- '".Database::escape_string($values['forum_id'])."',
- '".Database::escape_string($_user['user_id'])."',
- '".Database::escape_string(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($values['calification_notebook_title'])."'," .
- "'".Database::escape_string($values['numeric_calification'])."'," .
- "'".Database::escape_string($values['weight_calification'])."'," .
- "'".api_get_session_id()."')";
- $result=api_sql_query($sql, __LINE__, __FILE__);
- $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=$values['calification_notebook_title'];
- $maxqualify=$values['numeric_calification'];
- $weigthqualify=$values['weight_calification'];
- $resourcedescription='';
- $date=time();
-
- add_resource_to_course_gradebook($coursecode,$resourcetype,$resourceid,$resourcename,$weigthqualify,$maxqualify,$resourcedescription,$date,0,api_get_session_id());
-
- }
-
- api_item_property_update($_course, TOOL_FORUM_THREAD, $last_thread_id,"ForumThreadAdded", api_get_user_id());
-
-
-
-
-
- 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 (post_title, post_text, thread_id, forum_id, poster_id, poster_name, post_date, post_notification, post_parent_id, visible)
- VALUES ('".$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(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)."')";
- api_sql_query($sql, __FILE__,__LINE__);
- $last_post_id=Database::insert_id();
-
-
- $sql="UPDATE $table_threads SET thread_last_post='".Database::escape_string($last_post_id)."' WHERE thread_id='".Database::escape_string($last_thread_id)."'";
- $result=api_sql_query($sql, __LINE__, __FILE__);
- $message=get_lang('NewThreadStored');
-
- if ($has_attachment) {
- $courseDir = $_course['path'].'/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$courseDir;
-
-
- $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
-
-
- $file_name =$_FILES['user_upload']['name'];
-
- if (!filter_extension($new_file_name)) {
- Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
- } else {
- $new_file_name = uniqid('');
- $new_path=$updir.'/'.$new_file_name;
- $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
- $comment=$values['file_comment'];
-
-
- if ($result) {
- $sql='INSERT INTO '.$forum_table_attachment.'(filename,comment, path, post_id,size) '.
- "VALUES ( '".Database::escape_string($file_name)."', '".Database::escape_string($comment)."', '".Database::escape_string($new_file_name)."' , '".$last_post_id."', '".$_FILES['user_upload']['size']."' )";
- $result=api_sql_query($sql, __LINE__, __FILE__);
- $message.=' / '.get_lang('FileUploadSucces').'<br />';
-
- $last_id=Database::insert_id();
- api_item_property_update($_course, TOOL_FORUM_ATTACH, $last_id ,'ForumAttachmentAdded', api_get_user_id());
-
- }
- }
- } else {
- $message.='<br />';
- }
- if ($current_forum['approval_direct_post']=='1' AND !api_is_allowed_to_edit()) {
- $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'].'&origin='.$origin.'&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_unregister('formelements');
- session_unregister('origin');
- session_unregister('breadcrumbs');
- session_unregister('addedresource');
- session_unregister('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;
- global $charset;
-
- $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']) ? $_GET['gradebook']:'';
- $form = new FormValidator('thread', 'post', api_get_self().'?forum='.Security::remove_XSS($my_forum).'&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('hidden', 'forum_id', strval(intval($my_forum)));
- $form->addElement('hidden', 'thread_id', strval(intval($my_thread)));
- $form->addElement('hidden', 'gradebook', $my_gradebook);
-
- if ($current_forum['allow_anonymous']==1 AND !isset($_user['user_id'])) {
- $form->addElement('text', 'poster_name', get_lang('Name'));
- }
- $form->addElement('text', 'post_title', get_lang('Title'),'class="input_titles"');
- $form->addElement('html_editor', 'post_text', get_lang('Text'));
- if ($forum_setting['allow_post_notificiation'] AND isset($_user['user_id'])) {
- $form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail').' ('.$_user['mail'].')');
- }
- if ($forum_setting['allow_sticky'] AND api_is_allowed_to_edit() AND $action=='newthread') {
- $form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
- }
- if ($current_forum['allow_attachments']=='1' OR api_is_allowed_to_edit()) {
-
- $values = $form->exportValues();
- }
-
-
- $form->addElement('html','<br /><b><div class="row"><div class="label">'.get_lang('AddAnAttachment').'</div></div></b><br /><br />');
- $form->addElement('file','user_upload',get_lang('FileName'),'');
- $form->addElement('textarea','file_comment',get_lang('FileComment'),array ('rows' => 4, 'cols' => 34));
-
- $userid =api_get_user_id();
- $info =api_get_user_info($userid);
- $courseid=api_get_course_id();
-
- if( (api_is_course_admin() || api_is_course_coach() || api_is_course_tutor()) && !($my_thread) ){
-
-
- $form->addElement('static','Group','<a href="javascript://" onclick="return advanced_parameters()"><span id="img_plus_and_minus"><img src="../img/nolines_plus.gif" alt="" />'.get_lang('AdvancedParameters').'</span></a>');
- $form->addElement('html','<div id="id_qualify" style="display:none">');
- $form->addElement('static','Group', '<br /><strong>'.get_lang('AlterQualifyThread').'</strong>');
- $form->addElement('text', 'numeric_calification', get_lang('QualifyNumeric'),'Style="width:40px"');
- $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\';}"');
- $form -> addElement('html','<div id="options_field" style="display:none">');
- $form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'));
- $form->addElement('text', 'weight_calification', get_lang('QualifyWeight'),'value="0.00" Style="width:40px" onfocus="this.select();"');
- $form->addElement('html','</div>');
-
- $form->addElement('html','</div>');
- }
-
- $form->addElement('submit', 'SubmitPost', get_lang('Ok'));
- $form->add_real_progress_bar('DocumentUpload','user_upload');
- if ( !empty($form_values) ) {
- $defaults['post_title']=prepare4display(Security::remove_XSS($form_values['post_title']));
- $defaults['post_text']=prepare4display(Security::remove_XSS($form_values['post_text']));
- $defaults['post_notification']=Security::remove_XSS($form_values['post_notification']);
- $defaults['thread_sticky']=Security::remove_XSS($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').html_entity_decode($values['post_title'],ENT_QUOTES,$charset);
-
-
- if($action=='quote') {
- $defaults['post_text']='<div> </div><div style="margin: 5px;"><div style="font-size: 90%; font-style: italic;">'.get_lang('Quoting').' '.$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', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
- if ($current_forum['allow_anonymous']==1 AND !isset($_user['user_id'])) {
- $form->addRule('poster_name', '<div class="required">'.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));
- $form->display();
- echo '<br />';
- if ($forum_setting['show_thread_iframe_on_reply'] and $action<>'newthread') {
- echo "<iframe src=\"iframe_thread.php?forum=".Security::remove_XSS($my_forum)."&thread=".Security::remove_XSS($my_thread)."#".Security::remove_XSS($my_post)."\" width=\"80%\"></iframe>";
-
- }
- }
- }
- 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,'');
- 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 thread_id=".$thread_id.";";
- $res_string=api_sql_query($sql_string,__FILE__,__LINE__);
- $row_string=Database::fetch_array($res_string);
- if ($thread_qualify<=$row_string[0]) {
-
- $sql1="SELECT COUNT(*) FROM ".$table_threads_qualify." WHERE user_id=".$user_id." and thread_id=".$thread_id.";";
- $res1=api_sql_query($sql1);
- $row=Database::fetch_array($res1);
-
- if ($row[0]==0) {
- $sql="INSERT INTO $table_threads_qualify (user_id," .
- "thread_id,qualify,qualify_user_id,qualify_time,session_id)" .
- "VALUES('".$user_id."','".$thread_id."',".(float)$thread_qualify."," .
- "'".$qualify_user_id."','".$qualify_time."','".$session_id."')";
- $res=api_sql_query($sql,__FILE__,__LINE__);
-
- return $res;
- } else {
-
- $sql1="SELECT qualify FROM ".$table_threads_qualify." WHERE user_id=".$user_id." and thread_id=".$thread_id.";";
- $rs=api_sql_query($sql1,__FILE__,__LINE__);
- $row=Database::fetch_array($rs);
- $row[1]="update";
- return $row;
-
- }
-
- }else{
- return null;
- }
- }
- }
- function show_qualify($option,$couser_id,$forum_id,$user_id,$thread_id){
- $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY,'');
- $table_threads =Database::get_course_table(TABLE_FORUM_THREAD,'');
- if ($user_id==strval(intval($user_id)) && $thread_id==strval(intval($thread_id)) && $option==1) {
-
- $sql="SELECT qualify FROM ".$table_threads_qualify." WHERE user_id=".$user_id." and thread_id=".$thread_id.";";
- $rs=api_sql_query($sql,__FILE__,__LINE__);
- $row=Database::fetch_array($rs);
- return $row[0];
- }
-
- if ($user_id==strval(intval($user_id)) && $option==2) {
-
- $sql="SELECT thread_qualify_max FROM ".$table_threads." WHERE thread_id=".$thread_id.";";
- $rs=api_sql_query($sql,__FILE__,__LINE__);
- $row=Database::fetch_array($rs);
- return $row[0];
- }
-
- }
-
- function get_historical_qualify($user_id,$thread_id,$opt) {
- $my_qualify_log=array();
- $table_threads_qualify_log = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY_LOG,'');
- $opt = Database::escape_string($opt);
- if ($opt=='false') {
- $sql="SELECT * FROM ".$table_threads_qualify_log." WHERE 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 thread_id='".Database::escape_string($thread_id)."' and user_id='".Database::escape_string($user_id)."' ORDER BY qualify_time DESC";
- }
- $rs=api_sql_query($sql,__FILE__,__LINE__);
- 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');
-
-
- 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 user_id=".$user_id." and thread_id=".$thread_id.";";
- $rs=api_sql_query($sql,__FILE__,__LINE__);
- $row=Database::fetch_array($rs);
-
-
- $sql1="INSERT INTO $table_threads_qualify_log (user_id," .
- "thread_id,qualify,qualify_user_id,qualify_time,session_id)" .
- "VALUES('".$user_id."','".$thread_id."',".(float)$row[0]."," .
- "'".$qualify_user_id."','".$row[1]."','')";
- api_sql_query($sql1,__FILE__,__LINE__);
-
-
- $sql2="UPDATE ".$table_threads_qualify." SET qualify=".$current_qualify.",qualify_time='".$current_date."' WHERE user_id=".$user_id." and thread_id=".$thread_id.";";
- api_sql_query($sql2,__FILE__,__LINE__);
- }
- }
- function current_qualify_of_thread($thread_id,$session_id) {
- $table_threads_qualify = Database::get_course_table(TABLE_FORUM_THREAD_QUALIFY,'');
- $res=api_sql_query('SELECT qualify FROM '.$table_threads_qualify.' WHERE thread_id='.$thread_id.' AND session_id='.$session_id);
- $row=Database::fetch_array($res,'ASSOC');
- return $row['qualify'];
- }
- function store_reply($values) {
- global $table_threads;
- global $table_posts;
- global $forum_table_attachment;
- global $_user;
- global $_course;
- global $current_forum;
- global $origin;
- $post_date=date('Y-m-d H:i:s');
- if ($current_forum['approval_direct_post']=='1' AND !api_is_allowed_to_edit()) {
- $visible=0;
- } else {
- $visible=1;
- }
-
- $upload_ok=1;
- $has_attachment=false;
- if (!empty($_FILES['user_upload']['name'])) {
- $upload_ok = process_uploaded_file($_FILES['user_upload']);
- $has_attachment=true;
- }
-
- if ($upload_ok) {
-
- $sql="INSERT INTO $table_posts (post_title, post_text, thread_id, forum_id, poster_id, post_date, post_notification, post_parent_id, visible)
- VALUES ('".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'])."',
- '".Database::escape_string($_user['user_id'])."',
- '".Database::escape_string($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=api_sql_query($sql, __LINE__, __FILE__);
- $new_post_id=Database::insert_id();
- $values['new_post_id']=$new_post_id;
-
- $message=get_lang('ReplyAdded');
-
- if ($has_attachment) {
- $courseDir = $_course['path'].'/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$courseDir;
-
-
- $new_file_name = add_ext_on_mime(stripslashes($_FILES['user_upload']['name']), $_FILES['user_upload']['type']);
-
-
- $file_name =$_FILES['user_upload']['name'];
-
- if (!filter_extension($new_file_name)) {
- Display :: display_error_message(get_lang('UplUnableToSaveFileFilteredExtension'));
- } else {
- $new_file_name = uniqid('');
- $new_path=$updir.'/'.$new_file_name;
- $result= @move_uploaded_file($_FILES['user_upload']['tmp_name'], $new_path);
- $comment=$values['file_comment'];
-
-
- if ($result) {
- $sql='INSERT INTO '.$forum_table_attachment.'(filename,comment, path, post_id,size) '.
- "VALUES ( '".Database::escape_string($file_name)."', '".Database::escape_string($comment)."', '".Database::escape_string($new_file_name)."' , '".$new_post_id."', '".$_FILES['user_upload']['size']."' )";
- $result=api_sql_query($sql, __LINE__, __FILE__);
- $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' AND !api_is_allowed_to_edit()) {
- $message.='<br />'.get_lang('MessageHasToBeApproved').'<br />';
- }
-
- $message.='<br />'.get_lang('ReturnTo').' <a href="viewforum.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'&origin='.$origin.'">'.get_lang('Forum').'</a><br />';
- $message.=get_lang('ReturnTo').' <a href="viewthread.php?'.api_get_cidreq().'&forum='.$values['forum_id'].'&thread='.$values['thread_id'].'&origin='.$origin.'">'.get_lang('Message').'</a>';
-
-
- $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_unregister('formelements');
- session_unregister('origin');
- session_unregister('breadcrumbs');
- session_unregister('addedresource');
- session_unregister('addedresourceid');
-
- Display :: display_confirmation_message($message,false);
-
- } else {
- Display::display_error_message(get_lang('UplNoFileUploaded')." ". get_lang('UplSelectFileFirst'));
- }
-
- }
- function show_edit_post_form($current_post, $current_thread, $current_forum, $form_values='') {
- global $forum_setting;
- global $_user;
- global $origin;
-
- $form = new FormValidator('edit_post', 'post', api_get_self().'?forum='.Security::remove_XSS($_GET['forum']).'&origin='.$origin.'&thread='.Security::remove_XSS($_GET['thread']).'&post='.Security::remove_XSS($_GET['post']));
-
- $form->addElement('hidden', 'post_id', $current_post['post_id']);
- $form->addElement('hidden', 'thread_id', $current_thread['thread_id']);
- 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->addElement('html_editor', 'post_text', get_lang('Text'));
- if (!isset($_GET['edit'])) {
-
- $form->addElement('static','Group','<a href="javascript://" onclick="return advanced_parameters()"><span id="img_plus_and_minus"><img src="../img/nolines_plus.gif" alt="" />'.get_lang('AdvancedParameters').'</span></a>');
- $form->addElement('html','<div id="id_qualify" style="display:none">');
- $form->addElement('static','Group','<strong>'.get_lang('AlterQualifyThread').'</strong>');
- $form->addElement('text', 'numeric_calification', get_lang('QualifyNumeric'),'value="'.$current_thread['thread_qualify_max'].'" Style="width:40px"');
- $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\';}"');
- $defaults['thread_qualify_gradebook']=is_resource_in_course_gradebook(api_get_course_id(),5,$_GET['thread'],api_get_session_id());
-
- 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">');
- }
- $form->addElement('text', 'calification_notebook_title', get_lang('TitleColumnGradebook'),'value="'.$current_thread['thread_title_qualify'].'"');
- $form->addElement('text', 'weight_calification', get_lang('QualifyWeight'),'value="'.$current_thread['thread_weight'].'" Style="width:40px"');
- $form->addElement('html','</div>');
-
- $form->addElement('html','</div>');
-
- }
-
- if ($forum_setting['allow_post_notificiation']) {
- $form->addElement('checkbox', 'post_notification', '', get_lang('NotifyByEmail').' ('.$current_post['email'].')');
- }
- if ($forum_setting['allow_sticky'] and api_is_allowed_to_edit() and $current_post['post_parent_id']==0) {
- $form->addElement('checkbox', 'thread_sticky', '', get_lang('StickyPost'));
- if ( $current_thread['thread_sticky']==1 ) {
- $defaults['thread_sticky']=true;
- }
- }
- if ($current_forum['allow_attachments']=='1' OR api_is_allowed_to_edit()) {
- if (empty($form_values) AND !isset($_POST['SubmitPost'])) {
-
- }
-
- $values = $form->exportValues();
- }
- $form->addElement('submit', 'SubmitPost', get_lang('Ok'));
- global $charset;
-
- $defaults['post_title']=prepare4display(html_entity_decode($current_post['post_title'],ENT_QUOTES,$charset));
- $defaults['post_text']=prepare4display($current_post['post_text']);
- if ( $current_post['post_notification']==1 ) {
- $defaults['post_notification']=true;
- }
- if (!empty($form_values)) {
- $defaults['post_title']=Security::remove_XSS($form_values['post_title']);
- $defaults['post_text']=Security::remove_XSS($form_values['post_text']);
- $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', '<div class="required">'.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 $table_threads;
- global $table_posts;
- global $origin;
-
-
- $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 thread_id='".Database::escape_string($values['thread_id'])."'";
-
- api_sql_query($sql,__FILE__, __LINE__);
-
-
- $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 post_id='".Database::escape_string($values['post_id'])."'";
-
- api_sql_query($sql,__FILE__, __LINE__);
- if (api_is_course_admin()==true) {
- $ccode = api_get_course_id();
- $sid = api_get_session_id();
- $link_id = is_resource_in_course_gradebook($ccode,5,$values['thread_id'],$sid);
- $thread_qualify_gradebook=isset($values['thread_qualify_gradebook']) ? $values['thread_qualify_gradebook'] : null;
- if ($thread_qualify_gradebook!=1) {
- if ($link_id !== false) {
- remove_resource_from_course_gradebook($link_id);
- }
- } else {
- if ($link_id === false && !$_GET['thread']) {
-
- $date_in_gradebook=null;
- $weigthqualify=$values['weight_calification'];
- add_resource_to_course_gradebook($ccode,5,$values['thread_id'],Database::escape_string($values['calification_notebook_title']),$weigthqualify,$values['numeric_calification'],null,$date_in_gradebook,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.'&thread='.$values['thread_id'].'&post='.Security::remove_XSS($_GET['post']).'">'.get_lang('Message').'</a>';
- session_unregister('formelements');
- session_unregister('origin');
- session_unregister('breadcrumbs');
- session_unregister('addedresource');
- session_unregister('addedresourceid');
- Display :: display_confirmation_message($message,false);
- }
- function display_user_link($user_id, $name, $origin='') {
- if ($user_id<>0) {
- return '<a href="../user/userInfo.php?uInfo='.$user_id.'" '. (!empty($origin)? 'target="_top"': '') .'>'.$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="_top"': '') .'>';
- $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'];
- return $link.'<img src="'.$image_repository.$existing_image.'" alt="'.$name.'" title="'.$name.'" /></a>';
-
- } else {
- return $link.'<img src="'.api_get_path(WEB_CODE_PATH)."img/unknown.jpg".'" alt="'.$name.'" title="'.$name.'" /></a>';
- }
-
- }
- function increase_thread_view($thread_id) {
- global $table_threads;
- $sql="UPDATE $table_threads SET thread_views=thread_views+1 WHERE thread_id='".Database::escape_string($thread_id)."'";
- $result=api_sql_query($sql, __LINE__, __FILE__);
- }
- function update_thread($thread_id, $last_post_id,$post_date) {
- global $table_threads;
- $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 thread_id='".Database::escape_string($thread_id)."'";
- $result=api_sql_query($sql, __LINE__, __FILE__);
- }
- function forum_not_allowed_here() {
- Display :: display_error_message(get_lang('NotAllowedHere'));
- Display :: display_footer();
- exit;
- }
- function get_whats_new() {
- global $_user;
- global $_course;
- global $table_posts;
-
-
- $tool=TOOL_FORUM;
-
-
-
- if (!$_SESSION['last_forum_access']) {
- $tracking_last_tool_access=Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
- $sql="SELECT * FROM ".$tracking_last_tool_access." WHERE access_user_id='".Database::escape_string($_user['user_id'])."' AND access_cours_code='".Database::escape_string($_course['sysCode'])."' AND access_tool='".Database::escape_string($tool)."'";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- $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 post_date>'".Database::escape_string($_SESSION['last_forum_access'])."'";
- $result=api_sql_query($sql,__FILE__,__LINE__);
- 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) {
- global $table_posts;
- global $table_threads;
- global $table_item_property;
- $sql="SELECT count(*) as number_of_posts FROM $table_posts WHERE forum_id='".$forum_id."'";
- if (api_is_allowed_to_edit()) {
- $sql="SELECT count(*) as number_of_posts
- FROM $table_posts posts, $table_threads threads, $table_item_property item_property
- WHERE 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.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=api_sql_query($sql, __FILE__, __LINE__);
- $row=Database::fetch_array($result);
- $number_of_posts=$row['number_of_posts'];
-
- if (api_is_allowed_to_edit()) {
- $sql="SELECT count(*) as number_of_topics
- FROM $table_threads threads, $table_item_property item_property
- WHERE 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.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=api_sql_query($sql, __FILE__, __LINE__);
- $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) {
- global $table_posts;
- 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 post_id='".Database::escape_string($post_id)."'";
- $return=api_sql_query($sql, __FILE__, __LINE__);
- if ($return) {
- return 'PostVisibilityChanged';
- }
- }
- function get_unaproved_messages($forum_id) {
- global $table_posts;
-
- $return_array=array();
- $sql="SELECT DISTINCT thread_id FROM $table_posts WHERE forum_id='".Database::escape_string($forum_id)."' AND visible='0'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- while($row=Database::fetch_array($result)) {
- $return_array[]=$row['thread_id'];
- }
- return $return_array;
- }
- function send_notification_mails($thread_id, $reply_info) {
- global $table_posts;
- global $table_user;
- global $table_mailcue;
-
-
-
-
-
- $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' AND $current_forum['visibility']=='1' AND $current_forum_category['visibility']=='1' AND $current_forum['approval_direct_post']!='1') {
- $send_mails=true;
- } else {
- $send_mails=false;
- }
-
- if ($send_mails==true) {
- send_notifications($current_thread['forum_id'],$thread_id);
-
- } else {
-
- $table_notification = Database::get_course_table('forum_notification');
- $sql = "SELECT * FROM $table_notification WHERE forum_id = '".Database::escape_string($current_forum['forum_id'])."' OR thread_id = '".Database::escape_string($thread_id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- while ($row=Database::fetch_array($result)) {
- $sql_mailcue="INSERT INTO $table_mailcue (thread_id, post_id) VALUES ('".Database::escape_string($thread_id)."', '".Database::escape_string($reply_info['new_post_id'])."')";
- $result_mailcue=api_sql_query($sql_mailcue, __LINE__, __FILE__);
- }
- }
- }
- function handle_mail_cue($content, $id) {
- global $table_mailcue;
- global $table_forums;
- global $table_threads;
- global $table_posts;
- global $table_users;
-
- if ($content=='post') {
-
- $post_info=get_post_information($id);
-
- $sql="SELECT users.firstname, users.lastname, users.user_id, users.email FROM $table_mailcue mailcue, $table_posts posts, $table_users users
- WHERE posts.thread_id='".Database::escape_string($post_info['thread_id'])."'
- AND posts.post_notification='1'
- AND mailcue.thread_id='".Database::escape_string($post_info['thread_id'])."'
- AND users.user_id=posts.poster_id
- GROUP BY users.email";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- while ($row=Database::fetch_array($result)) {
- send_mail($row, get_thread_information($post_info['thread_id']));
- }
-
- $sql_delete_mailcue="DELETE FROM $table_mailcue WHERE 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.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
- GROUP BY users.email";
- $result=api_sql_query($sql,__FILE__, __LINE__);
- while ($row=Database::fetch_array($result)) {
- send_mail($row, get_thread_information($id));
- }
-
- $sql_delete_mailcue="DELETE FROM $table_mailcue WHERE thread_id='".Database::escape_string($id)."'";
- $result=api_sql_query($sql_delete_mailcue, __FILE__, __LINE__);
- } elseif ($content=='forum') {
- $sql="SELECT * FROM $table_threads WHERE forum_id='".Database::escape_string($id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- while ($row=Database::fetch_array($result)) {
- handle_mail_cue('thread',$row['thread_id']);
- }
- } elseif ($content=='forum_category') {
- $sql="SELECT * FROM $table_forums WHERE forum_category ='".Database::escape_string($id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- 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()) {
- global $_course;
- global $_user;
- $email_subject = get_lang('NewForumPost')." - ".$_course['official_code'];
- if (isset($thread_information) and 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= $user_info['firstname']." ".$user_info['lastname']."\n\r";
- $email_body .= '['.$_course['official_code'].'] - ['.$_course['name']."]<br>\n";
- $email_body .= get_lang('NewForumPost')."\n";
- $email_body .= get_lang('YouWantedToStayInformed')."<br><br>\n";
- $email_body .= get_lang('ThreadCanBeFoundHere')." : <a href=\"".$thread_link."\">".$thread_link."</a>\n";
-
-
- if(empty($charset)) {
- $charset='ISO-8859-1';
- }
- if ($user_info['user_id']<>$_user['user_id']) {
- $newmail = api_mail_html($user_info["lastname"].' '.$user_info["firstname"], $user_info["email"], $email_subject, $email_body, $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'], $_SESSION['_user']['mail']);
- }
- }
- function move_thread_form() {
- global $origin;
-
- $form = new FormValidator('movepost', 'post', api_get_self().'?forum='.Security::remove_XSS($_GET['forum']).'&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', strval(intval($_GET['thread'])));
-
- $forum_categories=get_forum_categories();
- $forums=get_forums();
- $htmlcontent="\n<tr>\n<td></td>\n<td>\n<SELECT NAME='forum'>\n";
- foreach ($forum_categories as $key=>$category) {
- $htmlcontent.="\t<OPTGROUP LABEL=\"".$category['cat_title']."\">\n";
- foreach ($forums as $key=>$forum) {
- if ($forum['forum_category']==$category['cat_id']) {
- $htmlcontent.="\t\t<OPTION VALUE='".$forum['forum_id']."'>".$forum['forum_title']."</OPTION>\n";
- }
- }
- $htmlcontent.="\t</OPTGROUP>\n";
- }
- $htmlcontent.="</SELECT>\n</td></tr>";
- $form->addElement('html',$htmlcontent);
-
- $form->addElement('submit', 'SubmitForum',get_lang('Ok'));
-
- if( $form->validate()) {
- $values = $form->exportValues();
- if (isset($_POST['forum'])) {
- store_move_thread($values);
- }
- } else {
- $form->display();
- }
- }
- function move_post_form() {
- global $origin;
-
- $form = new FormValidator('movepost', 'post', api_get_self().'?forum='.Security::remove_XSS($_GET['forum']).'&thread='.Security::remove_XSS($_GET['thread']).'&origin='.$origin.'&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->addElement('submit', '',get_lang('Ok'));
-
- $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) {
- global $table_posts;
- global $table_threads;
- global $table_forums;
- global $_course;
- if ($values['thread']=='0') {
- $current_post=get_post_information($values['post_id']);
-
- $sql="INSERT INTO $table_threads (thread_title, forum_id, thread_poster_id, thread_poster_name, thread_last_post, thread_date)
- VALUES (
- '".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=api_sql_query($sql, __FILE__, __LINE__);
- $new_thread_id=Database::get_last_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 post_id='".Database::escape_string($values['post_id'])."'";
- $result=api_sql_query($sql,__FILE__, __LINE__);
-
-
- $sql="UPDATE $table_posts SET post_parent_id='0' WHERE post_parent_id='".Database::escape_string($values['post_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
-
-
- $sql="UPDATE $table_forums SET forum_threads=forum_threads+1 WHERE forum_id='".Database::escape_string($current_post['forum_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
-
-
- $sql="SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($current_post['thread_id'])."' ORDER BY post_id DESC";
-
- $result=api_sql_query($sql, __FILE__, __LINE__);
- $row=Database::fetch_array($result);
-
- $sql="UPDATE $table_threads SET thread_last_post='".$row['post_id']."', thread_replies=thread_replies-1 WHERE thread_id='".Database::escape_string($current_post['thread_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
-
- } else {
-
- $sql="UPDATE $table_posts SET thread_id='".Database::escape_string($_POST['thread'])."', post_parent_id='0' WHERE post_id='".Database::escape_string($values['post_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
-
- $sql="UPDATE $table_posts SET post_parent_id='0' WHERE post_parent_id='".Database::escape_string($values['post_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- }
- return get_lang('ThreadMoved');
- }
- function store_move_thread($values) {
- global $table_posts;
- global $table_threads;
- global $table_forums;
- global $_course;
-
- $sql="UPDATE $table_threads SET forum_id='".Database::escape_string($_POST['forum'])."' WHERE thread_id='".Database::escape_string($_POST['thread_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
-
- $sql="UPDATE $table_posts SET forum_id='".Database::escape_string($_POST['forum'])."' WHERE thread_id='".Database::escape_string($_POST['thread_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- return get_lang('ThreadMoved');
- }
- function prepare4display($input='') {
- $highlightcolors = array('yellow', '#33CC33','#3399CC', '#9999FF', '#33CC33');
- if (!is_array($input)) {
- if (!empty($_GET['search'])) {
- if (strstr($_GET['search'],'+')) {
- $search_terms = explode('+',$_GET['search']);
- } else {
- $search_terms[] = trim($_GET['search']);
- }
- $counter = 0;
- foreach ($search_terms as $key=>$search_term) {
- $input = str_replace(trim(html_entity_decode($search_term)),'<span style="background-color: '.$highlightcolors[$counter].'">'.trim(html_entity_decode($search_term)).'</span>',$input);
- $counter++;
- }
- }
- return html_entity_decode(stripslashes($input));
- } else {
-
- $returnarray=array_walk($input, 'html_entity_decode');
- $returnarray=array_walk($input, 'stripslashes');
- return $returnarray;
- }
- }
- 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"');
- $form->addElement('static', 'search_information', '', get_lang('ForumSearchInformation'));
- $form->addElement('submit', 'SubmitForumCategory', get_lang('Search'));
-
- $form->addRule('search_term', '<div class="required">'.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($values['search_term']);
- } else {
- $form->display();
- }
- }
- function display_forum_search_results($search_term) {
- global $table_categories, $table_forums, $table_threads, $table_posts;
- global $origin;
-
-
- 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 ".implode(' AND ',$search_restriction)."
- /*AND posts.thread_id = threads.thread_id*/
- GROUP BY posts.post_id";
-
- $forum_categories_list=get_forum_categories();
-
-
- $forum_list=get_forums();
- $result = api_sql_query($sql, __FILE__, __LINE__);
- while ($row = Database::fetch_array($result,'ASSOC')) {
- $display_result = false;
-
- if (!api_is_allowed_to_edit()) {
- 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 == true) {
- $search_results_item = '<li><a href="viewforumcategory.php?forumcategory='.$forum_list[$row['forum_id']]['forum_category'].'&origin='.$origin.'&search='.urlencode($search_term).'">'.$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).'">'.$forum_list[$row['forum_id']]['forum_title'].'</a> > ';
-
- $search_results_item .= '<a href="viewthread.php?forum='.$row['forum_id'].'&origin='.$origin.'&thread='.$row['thread_id'].'&search='.urlencode($search_term).'">'.$row['post_title'].'</a>';
- $search_results_item .= '<br />';
- if (strlen($row['post_title']) > 200 ) {
- $search_results_item .= substr(strip_tags($row['post_title']),0,200).'...';
- } else {
- $search_results_item .= $row['post_title'];
- }
- $search_results_item .= '</li>';
- $search_results[] = $search_results_item;
- }
- }
- echo '<div class="row"><div class="form_header">'.count($search_results).' '.get_lang('ForumSearchResults').'</div></div>';
- echo '<ol>';
- if($search_results) {
- echo implode($search_results);
- }
- echo '</ol>';
- }
- function search_link() {
- global $origin;
- $return = '<a href="forumsearch.php?'.api_get_cidreq().'&action=search&origin='.$origin.'"> '.Display::return_icon('search.gif', get_lang('Search')).' '.get_lang('Search').'</a>';
- if (!empty($_GET['search'])) {
- $return .= ': '.Security::remove_XSS($_GET['search']).' ';
- $url = api_get_self().'?';
- 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 get_attachment($post_id) {
- global $forum_table_attachment;
- $row=array();
- $sql = 'SELECT path, filename,comment FROM '. $forum_table_attachment.' WHERE post_id ="'.$post_id.'"';
- $result=api_sql_query($sql, __FILE__, __LINE__);
- if (Database::num_rows($result)!=0) {
- $row=Database::fetch_array($result);
- }
- return $row;
- }
-
- function delete_attachment($id) {
- global $forum_table_attachment;
- global $_course;
-
- $attach_list=get_attachment($id);
- $sql = 'DELETE FROM '. $forum_table_attachment.' WHERE post_id ="'.$id.'"';
- $result=api_sql_query($sql, __FILE__, __LINE__);
-
- $courseDir = $_course['path'].'/upload/forum';
- $sys_course_path = api_get_path(SYS_COURSE_PATH);
- $updir = $sys_course_path.$courseDir;
- $my_path =isset($attach_list['path']) ? $attach_list['path'] : null;
- $file =$updir.'/'.$my_path;
-
- api_item_property_update($_course, TOOL_FORUM_ATTACH, $id ,'ForumAttachmentDelete', api_get_user_id());
-
- if (Security::check_abs_path($file,$updir) ) {
- @ unlink($file);
- }
- }
- function get_forums_of_group($group_id) {
- global $table_forums;
- global $table_threads;
- global $table_posts;
- global $table_item_property;
- global $table_users;
-
-
- $sql="SELECT * FROM ".$table_forums." forum , ".$table_item_property." item_properties
- WHERE forum.forum_of_group = '".Database::escape_string($group_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 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.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.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 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 GROUP BY forum_id";
-
- }
-
- $result=api_sql_query($sql, __FILE__, __LINE__);
- while ($row=Database::fetch_array($result,'ASSOC')) {
- $forum_list[$row['forum_id']]=$row;
- }
-
- $result2=api_sql_query($sql2, __FILE__, __LINE__);
- 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=api_sql_query($sql3, __FILE__, __LINE__);
- 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;
-
-
- if ($content == 'forum') {
- $database_field = 'forum_id';
- } else {
- $database_field = 'thread_id';
- }
-
-
- $table_notification = Database::get_course_table('forum_notification');
-
-
- $sql = "SELECT * FROM $table_notification WHERE $database_field = '".Database::escape_string($id)."' AND user_id = '".Database::escape_string($_user['user_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- $total = mysql_num_rows($result);
-
-
- if ($total <= 0) {
- $sql = "INSERT INTO $table_notification ($database_field, user_id) VALUES ('".Database::escape_string($id)."','".Database::escape_string($_user['user_id'])."')";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- api_session_unregister('forum_notification');
- get_notifications_of_user(0,true);
- return get_lang('YouWillBeNotifiedOfNewPosts');
- } else {
- if (!$add_only) {
- $sql = "DELETE FROM $table_notification WHERE $database_field = '".Database::escape_string($id)."' AND user_id = '".Database::escape_string($_user['user_id'])."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- api_session_unregister('forum_notification');
- get_notifications_of_user(0,true);
- return get_lang('YouWillNoLongerBeNotifiedOfNewPosts');
- }
-
- }
- }
- function get_notifications($content,$id) {
- global $table_users;
-
- if ($content == 'forum') {
- $database_field = 'forum_id';
- } else {
- $database_field = 'thread_id';
- }
-
- $table_notification = Database::get_course_table('forum_notification');
- $sql = "SELECT user.user_id, user.firstname, user.lastname, user.email, user.user_id user FROM $table_users user, $table_notification notification
- WHERE user.user_id = notification.user_id
- AND notification.$database_field= '".Database::escape_string($id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- $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 $_course;
-
-
- $email_subject = get_lang('NewForumPost')." - ".$_course['official_code'];
- $thread_link= api_get_path('WEB_CODE_PATH').'forum/viewthread.php?'.api_get_cidreq().'&forum='.$forum_id.'&thread='.$thread_id;
- $my_link=isset($link)?$link:'';
- $my_message=isset($message)?$message:'';
- $my_message .= $my_link;
-
-
- if ($forum_id<>0) {
- $users_to_be_notified_by_forum = get_notifications('forum',$forum_id);
- } else {
- return false;
- }
-
-
- 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);
-
- if (is_array($users_to_be_notified)) {
- foreach ($users_to_be_notified as $key=>$value) {
- if ($value['email'] <> $_user['email']) {
- $email_body= $value['firstname']." ".$value['lastname']."\n\r";
- $email_body .= '['.$_course['official_code'].'] - ['.$_course['name']."]<br>\n";
- $email_body .= get_lang('NewForumPost')."\n";
- $email_body .= get_lang('YouWantedToStayInformed')."<br><br>\n";
- $email_body .= get_lang('ThreadCanBeFoundHere')." : <a href=\"".$thread_link."\">".$thread_link."</a>\n";
-
-
-
- if(empty($charset)) {
- $charset='ISO-8859-1';
- }
-
- $newmail = api_mail_html($value['lastname'].' '.$value['firstname'], $value['email'], $email_subject, $email_body, $_SESSION['_user']['lastName'].' '.$_SESSION['_user']['firstName'], $_SESSION['_user']['mail']);
- }
- }
- }
- }
- function get_notifications_of_user($user_id = 0, $force = false) {
- global $_course;
- $course = api_get_course_id();
- if (empty($course) OR $course==-1) {
- return null;
- }
- if ($user_id == 0) {
- global $_user;
- $user_id = $_user['user_id'];
- }
-
-
- $table_notification = Database::get_course_table('forum_notification');
- $my_code = isset($_course['code']) ? $_course['code'] : '';
- if (!isset($_SESSION['forum_notification']) OR $_SESSION['forum_notification']['course'] <> $my_code OR $force=true) {
- $_SESSION['forum_notification']['course'] = $my_code;
-
- $sql = "SELECT * FROM $table_notification WHERE user_id='".Database::escape_string($user_id)."'";
- $result=api_sql_query($sql, __FILE__, __LINE__);
- 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) {
- global $table_posts;
- $sql = "SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."' ";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- return count(api_store_result($result));
- }
- function count_number_of_post_for_user_thread($thread_id, $user_id) {
- global $table_posts;
- $sql = "SELECT * FROM $table_posts WHERE thread_id='".Database::escape_string($thread_id)."'
- AND poster_id = '".Database::escape_string($user_id)."' ";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- return count(api_store_result($result));
- }
- 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 = api_sql_query($sql, __FILE__, __LINE__);
- return count(api_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($thread_id, $user_id ) {
- global $table_posts;
- global $table_users;
-
- $sql = "SELECT * FROM $table_posts posts
- LEFT JOIN $table_users users
- ON posts.poster_id=users.user_id
- WHERE posts.thread_id='".Database::escape_string($thread_id)."'
- AND posts.poster_id='".Database::escape_string($user_id)."'
- ORDER BY posts.post_id ASC";
-
- $result=api_sql_query($sql, __FILE__, __LINE__);
-
- 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.thread_id='".Database::escape_string($thread_id)."'
- AND posts.post_parent_id='".$row['post_id']."'
- ORDER BY posts.post_id ASC";
- $result2=api_sql_query($sql, __FILE__, __LINE__);
- while ($row2=Database::fetch_array($result2))
- {
- $row2['status'] = '0';
- $post_list[] = $row2;
- }
- }
- return $post_list;
- }
- function get_name_user_by_id($user_id) {
- $t_users = Database :: get_main_table(TABLE_MAIN_USER);
- $sql ="SELECT CONCAT(firstname,' ',lastname) FROM ".$t_users." WHERE user_id = '".$user_id."' ";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
- return $row[0];
- }
-
-
- function get_name_thread_by_id($thread_id) {
- $t_forum_thread = Database::get_course_table(TABLE_FORUM_THREAD,'');
- $sql ="SELECT thread_title FROM ".$t_forum_thread." WHERE thread_id = '".$thread_id."' ";
- $result = api_sql_query($sql, __FILE__, __LINE__);
- $row = Database::fetch_array($result);
- return $row[0];
- }
|