diff --git a/main/newscorm/aicc_api.php b/main/newscorm/aicc_api.php index 5d2b59dd0b..bcadcdbd12 100644 --- a/main/newscorm/aicc_api.php +++ b/main/newscorm/aicc_api.php @@ -153,7 +153,7 @@ function LMSGetValue(param) { result=''; }else if(param == 'cmi.core.student_name'){ }else if(param == 'cmi.core.lesson_location'){ @@ -209,7 +209,7 @@ function LMSGetValue(param) { break; case 'cmi.core.student_name' : break; case 'cmi.core.lesson_location' : @@ -605,7 +605,7 @@ function update_message_frame(msg_msg) * @param string This parameter can be a string specifying the next * item (like 'next', 'previous', 'first' or 'last') or the id to the next item */ -function switch_item(current_item, next_item){ +function switch_item(current_item, next_item){ /* if(!current_item){ logit_lms('In switch - no current_item defined',0); diff --git a/main/newscorm/aicc_hacp.php b/main/newscorm/aicc_hacp.php index 1316f48911..7c6aa2c597 100644 --- a/main/newscorm/aicc_hacp.php +++ b/main/newscorm/aicc_hacp.php @@ -106,7 +106,7 @@ if(!empty($_REQUEST['command'])) $result = $s_ec.$error_code.$crlf.$s_et.$error_text.$crlf.$s_ad.$crlf; $result .= '[Core]'.$crlf; $result .= $tab.'Student_ID='.$_user['user_id'].$crlf; - $result .= $tab.'Student_Name='.$_user['lastName'].', '.$_user['firstName'].$_user['user_id'].$crlf; + $result .= $tab.'Student_Name='.api_get_person_name($_user['firstName'], $_user['lastName']).$crlf; $result .= $tab.'Lesson_Location='.$oItem->get_lesson_location().$crlf; $result .= $tab.'Credit='.$oItem->get_credit().$crlf; $result .= $tab.'Lesson_Status='.$oItem->get_status().$crlf; diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index 4ab4a63073..b059d3db53 100755 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -7,7 +7,7 @@ Copyright (c) Denes Nagy (darkden@freemail.hu) For a full list of contributors, see "credits.txt". - The full license can be read in "license.txt". + The full license can be read in "license.txt". This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -65,7 +65,7 @@ if(!is_object($oItem)){ error_log('New LP - scorm_api - Could not load oItem item',0); exit; } -$autocomplete_when_80pct = 0; +$autocomplete_when_80pct = 0; /* ============================================================================== @@ -108,18 +108,18 @@ api_1484_11 = API_1484_11; //api_1484_11 = new APIobject(); //for scorm 1.3 // Error codes -var G_NoError = 0; -var G_GeneralException = 101; +var G_NoError = 0; +var G_GeneralException = 101; var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document -var G_InvalidArgumentError = 201; +var G_InvalidArgumentError = 201; var G_ElementCannotHaveChildren = 202; -var G_ElementIsNotAnArray = 203; -var G_NotInitialized = 301; -var G_NotImplementedError = 401; -var G_InvalidSetValue = 402; -var G_ElementIsReadOnly = 403; -var G_ElementIsWriteOnly = 404; -var G_IncorrectDataType = 405; +var G_ElementIsNotAnArray = 203; +var G_NotInitialized = 301; +var G_NotImplementedError = 401; +var G_InvalidSetValue = 402; +var G_ElementIsReadOnly = 403; +var G_ElementIsWriteOnly = 404; +var G_IncorrectDataType = 405; // Error messages var G_NoErrorMessage = ''; @@ -170,7 +170,7 @@ $(document).ready( function() { info_lms_item[1]='get_id();?>'; $("#current_item_id").attr("value",get_id();?>); - $("#old_item").attr("value",get_id();?>); + $("#old_item").attr("value",get_id();?>); //var myiframe=document.getElementById('content_id'); //myiframe.Events.AttachEvent("onclick", update_lp_item_id); @@ -187,7 +187,7 @@ $(document).ready( function() { }); }); - + //Dokeos internal variables var saved_lesson_status = 'not attempted'; var lms_lp_id = get_id();?>; @@ -224,49 +224,49 @@ var lms_old_item_id = 0; var execute_stats='false'; - + /** * Function called mandatorily by the SCORM content to start the SCORM communication */ function LMSInitialize() { //this is the initialize function of all APIobjects - + /* load info for this new item by calling the js_api_refresh command in * the message frame. The message frame will update the JS variables by * itself, in JS, by doing things like top.lesson_status = 'not attempted' * and that kind of stuff, so when the content loads in the content frame * it will have all the correct variables set - */ + */ G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; + G_LastErrorMessage = 'No error'; //reinit to list reinit_update_table_list () lms_initialized=0; - // if there are more parameters than "" + // if there are more parameters than "" if (arguments.length>1) { G_LastError = G_InvalidArgumentError; G_LastErrorMessage = G_InvalidArgumentErrorMessage; logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0); - return('false'); - } else { + return('false'); + } else { logit_scorm('LMSInitialise()',0); - lms_initialized=1; - return('true'); - } + lms_initialized=1; + return('true'); + } } function Initialize() { //this is the initialize function of all APIobjects - return LMSInitialize(); + return LMSInitialize(); } function LMSGetValue(param) -{ +{ //logit_scorm("LMSGetValue('"+param+"')",1); G_LastError = G_NoError ; G_LastErrorMessage = 'No error'; - var result=''; - + var result=''; + // the LMSInitialize is missing if (lms_initialized == 0) { G_LastError = G_NotInitialized; @@ -274,9 +274,9 @@ function LMSGetValue(param) logit_scorm('Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0); return ''; } - + //Dokeos does not support this SCO object properties - + if (param == 'cmi.student_preference.text' || param == 'cmi.student_preference.language' || param == 'cmi.student_preference.speed' || @@ -290,13 +290,13 @@ function LMSGetValue(param) G_lastErrorString = G_NotImplementedErrorMessage; logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1); result = ''; - return result; + return result; } // ---- cmi.core._children - if(param=='cmi.core._children' || param=='cmi.core_children') { + if(param=='cmi.core._children' || param=='cmi.core_children'){ result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time'; - } else if(param == 'cmi.core.entry'){ + }else if(param == 'cmi.core.entry'){ // ---- cmi.core.entry if(lms_item_core_exit=='none') { result='ab-initio'; @@ -305,48 +305,48 @@ function LMSGetValue(param) } else { result=''; } - } else if(param == 'cmi.core.exit'){ - // ---- cmi.core.exit + }else if(param == 'cmi.core.exit'){ + // ---- cmi.core.exit result=''; G_LastError = G_ElementIsWriteOnly; }else if(param == 'cmi.core.session_time'){ result=''; - G_LastError = G_ElementIsWriteOnly; + G_LastError = G_ElementIsWriteOnly; }else if(param == 'cmi.core.lesson_status'){ // ---- cmi.core.lesson_status if(lesson_status != '') { result=lesson_status; - } else { + } else { //result='not attempted'; } - } else if(param == 'cmi.core.student_id'){ + }else if(param == 'cmi.core.student_id'){ // ---- cmi.core.student_id result=''; - } else if(param == 'cmi.core.student_name'){ + }else if(param == 'cmi.core.student_name'){ // ---- cmi.core.student_name - } else if(param == 'cmi.core.lesson_location'){ + }else if(param == 'cmi.core.lesson_location'){ // ---- cmi.core.lesson_location result=lesson_location; - } else if(param == 'cmi.core.total_time'){ + }else if(param == 'cmi.core.total_time'){ // ---- cmi.core.total_time result=total_time; - } else if(param == 'cmi.core.score._children'){ + }else if(param == 'cmi.core.score._children'){ // ---- cmi.core.score._children result='raw,min,max'; - } else if(param == 'cmi.core.score.raw'){ + }else if(param == 'cmi.core.score.raw'){ // ---- cmi.core.score.raw result=score; - } else if(param == 'cmi.core.score.max'){ + }else if(param == 'cmi.core.score.max'){ // ---- cmi.core.score.max result=max; - } else if(param == 'cmi.core.score.min'){ + }else if(param == 'cmi.core.score.min'){ // ---- cmi.core.score.min result=min; - } else if(param == 'cmi.core.score'){ + }else if(param == 'cmi.core.score'){ // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case result=score; }else if(param == 'cmi.core.credit'){ @@ -457,22 +457,22 @@ function LMSGetValue(param) } } }else if(param == 'cmi.student_data._children'){ - // ---- cmi.student_data._children + // ---- cmi.student_data._children result = 'mastery_score,max_time_allowed'; }else if(param == 'cmi.student_data.mastery_score'){ - // ---- cmi.student_data.mastery_score + // ---- cmi.student_data.mastery_score result = mastery_score; }else if(param == 'cmi.student_data.max_time_allowed'){ - // ---- cmi.student_data.max_time_allowed + // ---- cmi.student_data.max_time_allowed result = max_time_allowed; }else if(param == 'cmi.interactions._count'){ - // ---- cmi.interactions._count + // ---- cmi.interactions._count result = interactions.length; }else if(param == 'cmi.interactions._children'){ - // ---- cmi.interactions._children + // ---- cmi.interactions._children result = 'id,time,type,correct_responses,weighting,student_response,result,latency'; - } else { - // ---- anything else + }else{ + // ---- anything else // Invalid argument error G_lastError = G_InvalidArgumentError ; G_lastErrorString = G_InvalidArgumentErrorMessage; @@ -489,7 +489,7 @@ function GetValue(param) { } function LMSSetValue(param, val) { - + logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0); commit = true; //value has changed, need to re-commit G_LastError = G_NoError ; @@ -521,11 +521,11 @@ function LMSSetValue(param, val) { updatetable_to_list['cmi.completion_status']='true'; return_value='true'; //1.3 } else if ( param == "cmi.core.session_time" ) { - session_time = val; + session_time = val; updatetable_to_list['cmi.core.session_time']='true'; return_value='true'; } else if ( param == "cmi.score.scaled") { //1.3 - if(val<=1 && val>=-1) { + if(val<=1 && val>=-1) { score = val ; updatetable_to_list['cmi.score.scaled']='true'; return_value='true'; @@ -550,22 +550,22 @@ function LMSSetValue(param, val) { G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.credit" ) { G_LastError = G_ElementIsReadOnly; - } else if ( param == "cmi.core.entry" ) { + } else if ( param == "cmi.core.entry" ) { G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.total_time" ) { - G_LastError = G_ElementIsReadOnly; + G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.lesson_mode" ) { G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.comments_from_lms" ) { - G_LastError = G_ElementIsReadOnly; + G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_data.time_limit_action" ) { - G_LastError = G_ElementIsReadOnly; + G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_data.mastery_score" ) { - G_LastError = G_ElementIsReadOnly; + G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_data.max_time_allowed" ) { G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_preference._children" ) { - G_LastError = G_ElementIsReadOnly; + G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.launch_data" ) { G_LastError = G_ElementIsReadOnly; } else { @@ -576,13 +576,13 @@ function LMSSetValue(param, val) { if(elem_id > interactions.length) //interactions setting should start at 0 { /* - G_LastError = G_InvalidArgumentError; + G_LastError = G_InvalidArgumentError; G_LastErrorString = 'Invalid argument (interactions)'; return_value = false; */ interactions[0] = ['0','','','','','','','']; - } - if(interactions[elem_id] == null) { + } + if(interactions[elem_id] == null){ interactions[elem_id] = ['','','','','','','','']; //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7) interactions[elem_id][4] = new Array(); @@ -634,7 +634,7 @@ function LMSSetValue(param, val) { G_lastError = G_NotImplementedError; G_lastErrorString = 'Not implemented yet'; } - } else if(param.substring(0,15)== 'cmi.objectives.'){ + }else if(param.substring(0,15)== 'cmi.objectives.'){ var myres = ''; updatetable_to_list['objectives']='true'; if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/)) @@ -697,7 +697,7 @@ function LMSSetValue(param, val) { } } } - } else { + }else{ G_lastError = G_NotImplementedError; G_lastErrorString = G_NotImplementedErrorMessage; } @@ -742,15 +742,15 @@ function reinit_update_table_list () { function savedata(origin) { //origin can be 'commit', 'finish' or 'terminate' if ((lesson_status != 'completed') && (lesson_status != 'passed') && (mastery_score >=0) && (score >= mastery_score)) { - lesson_status = 'passed'; + lesson_status = 'passed'; updatetable_to_list['cmi.core.lesson_status']='true'; } else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ) { - //the status cannot be modified automatically by the LMS under SCORM 1.2's rules - + //the status cannot be modified automatically by the LMS under SCORM 1.2's rules + lesson_status = 'completed'; updatetable_to_list['cmi.core.lesson_status']='true'; - - ; + + ; } else { /* * See notes in switch_item for why this has been disabled @@ -776,7 +776,7 @@ function savedata(origin) { my_get_value_scorm=new Array(); my_get_value_scorm=ProcessValueScorm(); - + logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1); old_item_id=info_lms_item[0]; @@ -805,14 +805,14 @@ function savedata_onunload() { */ function LMSCommit(val) { - logit_scorm('LMSCommit()',0); - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - - savedata('commit'); + logit_scorm('LMSCommit()',0); + G_LastError = G_NoError ; + G_LastErrorMessage = 'No error'; + + savedata('commit'); reinit_update_table_list(); //commit = 'false' ; //now changes have been commited, no need to update until next SetValue() - return('true'); + return('true'); } function Commit(val) { @@ -820,13 +820,13 @@ function Commit(val) { } function LMSFinish(val) { - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - // why commit==false? - if (( commit == false )) { - logit_scorm('LMSFinish() (no LMSCommit())',1); - - } + G_LastError = G_NoError ; + G_LastErrorMessage = 'No error'; + // why commit==false? + if (( commit == false )) { + logit_scorm('LMSFinish() (no LMSCommit())',1); + + } //if ( commit == true ) { logit_scorm('LMSFinish() called',1); @@ -876,8 +876,8 @@ function Terminate() G_LastError = G_NotInitialized; G_LastErrorMessage = G_NotInitializedMessage; logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0); - return('false'); - } else { + return('false'); + } else { logit_scorm('Terminate()',0); G_LastError = G_NoError ; G_LastErrorMessage = 'No error'; @@ -956,7 +956,7 @@ function addListeners(){ /* See notes in switch_item() for why this has been disabled if (lms_lp_type==2) { addEvent(window,'unload',savedata_onunload,false); - } + } */ logit_lms('Quitting addListeners()',2); } @@ -976,7 +976,7 @@ function load_item(item_id,url){ lms_old_item_id = lms_item_id; var lms_new_item_id = item_id; //load new content page into content frame - if(lms_lp_type==1 || lms_item_type=='asset') { + if(lms_lp_type==1 || lms_item_type=='asset'){ dokeos_save_asset(); } cont_f.src = url; @@ -994,7 +994,7 @@ function load_item(item_id,url){ * Save a Dokeos learnpath item's time and mark as completed upon * leaving it */ -function dokeos_save_asset() { +function dokeos_save_asset(){ // only for dokeos lps if (execute_stats=='true') { execute_stats='false'; @@ -1032,13 +1032,13 @@ function dokeos_void_save_asset(myscore,mymax) * @param integer Priority (0 for top priority, 3 for lowest) */ function logit_scorm(message,priority){ - + if(scorm_logs>priority){ if($("#lp_log_name") && $("#log_content")){ $("#log_content").append("SCORM: " + message + "
"); } } - + } /** @@ -1047,7 +1047,7 @@ function logit_scorm(message,priority){ * @param integer Priority (0 for top priority, 3 for lowest) */ function logit_lms(message,priority){ - if(lms_logs>priority){ + if(lms_logs>priority){ if ($("#lp_log_name") && $("#log_content")) { $("#log_content").append("LMS: " + message + "
"); } @@ -1066,7 +1066,7 @@ function update_toc(update_action,update_id,change_ids) } var myelem = $("#toc_"+update_id); var myelemimg = $("#toc_img_"+update_id); - logit_lms('update_toc("'+update_action+'",'+update_id+')',2); + logit_lms('update_toc("'+update_action+'",'+update_id+')',2); if(update_id != 0) { @@ -1074,11 +1074,11 @@ function update_toc(update_action,update_id,change_ids) { case 'unhighlight': if (update_id%2==0) - { + { myelem.attr('class',"scorm_item_2"); } else - { + { myelem.attr('class',"scorm_item_1"); } break; @@ -1089,37 +1089,37 @@ function update_toc(update_action,update_id,change_ids) } myelem.attr('class',"scorm_item_highlight"); break; - case 'not attempted': + case 'not attempted': if( myelemimg.attr('src') != '../img/notattempted.gif') { myelemimg.attr('src','../img/notattempted.gif'); myelemimg.attr('alt','n'); } break; - case 'incomplete': + case 'incomplete': if( myelemimg.attr('src') != '../img/incomplete.gif') { myelemimg.attr('src','../img/incomplete.gif'); myelemimg.attr('alt','i'); } break; - case 'completed': + case 'completed': if( myelemimg.attr('src') != '../img/completed.gif') { myelemimg.attr('src','../img/completed.gif'); myelemimg.attr('alt','c'); } break; - case 'failed': + case 'failed': if( myelemimg.attr('src') != '../img/failed.gif') { myelemimg.attr('src','../img/failed.gif'); myelemimg.attr('alt','f'); } break; - case 'passed': + case 'passed': if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'passed') { myelemimg.attr('src','../img/completed.gif'); myelemimg.attr('alt','p'); } break; - case 'browsed': + case 'browsed': if( myelemimg.attr('src') != '../img/completed.gif' && myelemimg.attr('alt') != 'browsed') { myelemimg.attr('src','../img/completed.gif'); myelemimg.attr('alt','b'); @@ -1133,7 +1133,7 @@ function update_toc(update_action,update_id,change_ids) return true; } -function update_stats() { +function update_stats() { if (execute_stats=='true') { try { cont_f = document.getElementById('content_id'); @@ -1156,11 +1156,11 @@ function update_progress_bar(nbr_complete, nbr_total, mode) logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2); logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2); - if(mode == ''){mode='%';} - if(nbr_total == 0){nbr_total=1;} - var percentage = (nbr_complete/nbr_total)*100; - percentage = Math.round(percentage); - + if(mode == ''){mode='%';} + if(nbr_total == 0){nbr_total=1;} + var percentage = (nbr_complete/nbr_total)*100; + percentage = Math.round(percentage); + var pr_text = $("#progress_text"); var pr_full = $("#progress_img_full"); var pr_empty = $("#progress_img_empty"); @@ -1168,16 +1168,16 @@ function update_progress_bar(nbr_complete, nbr_total, mode) pr_full.attr('width',percentage*1.2); pr_empty.attr('width',(100-percentage)*1.2); - var mytext = ''; - switch(mode){ - case 'abs': - mytext = nbr_complete + '/' + nbr_total; - break; - case '%': - default: - mytext = percentage + '%'; - break; - } + var mytext = ''; + switch(mode){ + case 'abs': + mytext = nbr_complete + '/' + nbr_total; + break; + case '%': + default: + mytext = percentage + '%'; + break; + } pr_text.html(mytext); return true; @@ -1201,7 +1201,7 @@ function update_stats_page() */ function update_message_frame(msg_msg) { - if(msg_msg==null){msg_msg='';} + if(msg_msg==null){msg_msg='';} if(!($("#msg_div_id"))){ logit_lms('In update_message_frame() - message frame has no document property',0); }else{ @@ -1211,10 +1211,10 @@ function update_message_frame(msg_msg) } /** * Function that handles the saving of an item and switching from an item to another. - * Once called, this function should be able to do the whole process of - * (1) saving the current item, - * (2) refresh all the values inside the SCORM API object, - * (3) open the new item into the content_id frame, + * Once called, this function should be able to do the whole process of + * (1) saving the current item, + * (2) refresh all the values inside the SCORM API object, + * (3) open the new item into the content_id frame, * (4) refresh the table of contents * (5) refresh the progress bar (completion) * (6) refresh the message frame @@ -1222,26 +1222,26 @@ function update_message_frame(msg_msg) * @param string This parameter can be a string specifying the next * item (like 'next', 'previous', 'first' or 'last') or the id to the next item */ - -function switch_item(current_item, next_item) { + +function switch_item(current_item, next_item){ //backup these params var orig_current_item = current_item; var orig_next_item = next_item; var orig_lesson_status = lesson_status; - //(1) save the current item + //(1) save the current item logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0); - if (lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){ + if(lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){ if (lms_lp_type==1) { - xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, asset_timer, suspend_data, lesson_location,interactions, lms_item_core_exit); + xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, asset_timer, suspend_data, lesson_location,interactions, lms_item_core_exit); } else { my_get_value_scorm=new Array(); my_get_value_scorm=ProcessValueScorm(); xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,my_get_value_scorm); } if(item_objectives.length>0) { - xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives); - } - } else { + xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives); + } + }else{ /** * Because of SCORM 1.2's special rule about unsent commits and the fact * that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and @@ -1267,13 +1267,13 @@ function switch_item(current_item, next_item) { */ //savedata('finish'); //} - // xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location,interactions, lms_item_core_exit); + // xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location,interactions, lms_item_core_exit); } execute_stats=false; //(2) Refresh all the values inside this SCORM API object - use AJAX - xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item); - + xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item); + status_info.push(lesson_status); //current item @@ -1300,7 +1300,7 @@ function switch_item(current_item, next_item) { info_lms_item[1]=next_item; } } - + //(3) open the new item in the content_id frame switch(next_item){ case 'next': @@ -1315,11 +1315,11 @@ function switch_item(current_item, next_item) { break; default: break; - } + } var mysrc = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item; - var cont_f = $("#content_id"); + var cont_f = $("#content_id"); - mode == 'fullscreen'){ ?> + mode == 'fullscreen'){ ?> cont_f = window.open(''+mysrc,'content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1'); cont_f.onload=function(){ info_lms_item[0]=info_lms_item[1]; @@ -1331,23 +1331,23 @@ function switch_item(current_item, next_item) { info_lms_item[1]= info_lms_item[1]; } - - cont_f.attr("src",mysrc); + + cont_f.attr("src",mysrc); - + if(lms_lp_type==1 || lms_item_type=='asset'){ xajax_start_timer(); } - - //(4) refresh the audio player if needed + + //(4) refresh the audio player if needed $.ajax({ type: "GET", url: "lp_nav.php", data: "", success: function(tmp_data) { $("#media").html(tmp_data); - } - }); + } + }); /* if ( lms_lp_type==2 && (orig_lesson_status == 'not attempted' || orig_lesson_status == '') && orig_current_item != orig_next_item) { params = 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+orig_current_item; @@ -1454,16 +1454,16 @@ function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, is_interactions='false'; } } - + if (is_interactions=='true') { - interact_string = ''; + interact_string = ''; temp = ''; for (i in interactions){ interact_string += '&interact['+i+']='; interact_temp = '['; - for (j in interactions[i]) { + for (j in interactions[i]) { temp = interactions[i][j]; temp = ''+temp; // if temp == 1 there are problems with indexOf and an integer number //this fix when an interaction have ',' i.e: {a,b,c,d} is replace to {a@.|@b@.|@c@.|@d} see DT#4444 @@ -1478,8 +1478,8 @@ function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, interact_string += interact_temp; } - //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1))); - params += interact_string; + //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1))); + params += interact_string; is_interactions='false'; } diff --git a/main/online/online_whoisonline.php b/main/online/online_whoisonline.php index b87155b742..f7d763a785 100644 --- a/main/online/online_whoisonline.php +++ b/main/online/online_whoisonline.php @@ -79,7 +79,7 @@ foreach($Users as $enreg) name="user_" href="?showPic=#user_"> - + diff --git a/main/reservation/rsys.php b/main/reservation/rsys.php index 3a850fb401..10f5d3353a 100644 --- a/main/reservation/rsys.php +++ b/main/reservation/rsys.php @@ -1237,7 +1237,7 @@ class Rsys { $sql = "SELECT i1.name as col0,c.name as col1, DATE_FORMAT(r1.start_at ,'%Y-%m-%d %H:%i') as col2, - DATE_FORMAT(r1.end_at ,'%Y-%m-%d %H:%i') as col3, CONCAT(u.lastname,' ',u.firstname) as col4, + DATE_FORMAT(r1.end_at ,'%Y-%m-%d %H:%i') as col3, ".(api_is_western_name_order() ? "CONCAT(u.firstname,' ',u.lastname)" : "CONCAT(u.lastname,' ',u.firstname)")." as col4, DATE_FORMAT(s.start_at ,'%Y-%m-%d %H:%i') as col5, DATE_FORMAT(s.end_at ,'%Y-%m-%d %H:%i') as col6, s.accepted as col7 FROM ".Rsys :: getTable('subscription')." s, ".Rsys :: getTable('reservation')." r1, ".Database :: get_main_table(TABLE_MAIN_USER)." u," .Rsys :: getTable('item')." i1,".Rsys :: getTable('category')." c @@ -1315,14 +1315,14 @@ class Rsys { } - /*$sql = "SELECT dummy AS col0, CONCAT(u.lastname,' ',u.firstname) AS col1, s.user_id AS col2, accepted AS col3 + /*$sql = "SELECT dummy AS col0, ".(api_is_western_name_order() ? "CONCAT(u.firstname,' ',u.lastname)" : "CONCAT(u.lastname,' ',u.firstname)")." AS col1, s.user_id AS col2, accepted AS col3 FROM ".Rsys :: getTable('subscription')." s INNER JOIN ".Database :: get_main_table(TABLE_MAIN_USER)." u ON s.user_id = u.user_id "; if (!empty ($_GET['rid'])) { $sql .= " WHERE s.reservation_id = '".$_GET['rid']."'"; } $sql .= " ORDER BY col".$column." ".$direction." LIMIT ".$from.",".$per_page;*/ - $sql = "SELECT dummy AS col0, CONCAT(u.lastname,' ',u.firstname) AS col1, s.user_id AS col2, accepted AS col3, r.start_at, r.end_at, s.start_at, s.end_at + $sql = "SELECT dummy AS col0, ".(api_is_western_name_order() ? "CONCAT(u.firstname,' ',u.lastname)" : "CONCAT(u.lastname,' ',u.firstname)")." AS col1, s.user_id AS col2, accepted AS col3, r.start_at, r.end_at, s.start_at, s.end_at FROM ".Rsys :: getTable('subscription')." s,".Database :: get_main_table(TABLE_MAIN_USER)." u,".Database :: get_main_table(TABLE_MAIN_RESERVATION_RESERVATION)." r where u.user_id = s.user_id and s.reservation_id = r.id"; diff --git a/main/social/contacts.inc.php b/main/social/contacts.inc.php index a853e0a7df..b4fc332c5a 100755 --- a/main/social/contacts.inc.php +++ b/main/social/contacts.inc.php @@ -29,7 +29,7 @@ $image_path = UserManager::get_user_picture_path_by_id ($user_id,'web',false,tru echo '  Dokeos  -  '; $user_id=api_get_user_id(); $user_info=api_get_user_info($user_id); - echo $name_user=api_xml_http_response_encode($user_info['firstName'].' '.$user_info['lastName']) ; + echo $name_user=api_xml_http_response_encode(api_get_person_name($user_info['firstName'], $user_info['lastName'])); ?> diff --git a/main/social/data_personal.inc.php b/main/social/data_personal.inc.php index f0f81068e6..e50feac7ca 100755 --- a/main/social/data_personal.inc.php +++ b/main/social/data_personal.inc.php @@ -103,10 +103,17 @@ $language_variable=api_xml_http_response_encode(get_lang('PersonalData')); echo '
'; echo '
'.api_xml_http_response_encode(get_lang('UserName')).'
'. api_xml_http_response_encode($user_info['username']).'
'; - echo '
'.api_xml_http_response_encode(get_lang('FirstName')).'
-
'. api_xml_http_response_encode($user_info['firstname']).'
'; - echo '
'.api_xml_http_response_encode(get_lang('LastName')).'
-
'. api_xml_http_response_encode($user_info['lastname']).'
'; + if (api_is_western_name_order()) { + echo '
'.api_xml_http_response_encode(get_lang('FirstName')).'
+
'. api_xml_http_response_encode($user_info['firstname']).'
'; + echo '
'.api_xml_http_response_encode(get_lang('LastName')).'
+
'. api_xml_http_response_encode($user_info['lastname']).'
'; + } else { + echo '
'.api_xml_http_response_encode(get_lang('LastName')).'
+
'. api_xml_http_response_encode($user_info['lastname']).'
'; + echo '
'.api_xml_http_response_encode(get_lang('FirstName')).'
+
'. api_xml_http_response_encode($user_info['firstname']).'
'; + } echo '
'.api_xml_http_response_encode(get_lang('OfficialCode')).'
'. api_xml_http_response_encode($user_info['official_code']).'
'; echo '
'.api_xml_http_response_encode(get_lang('Email')).'
diff --git a/main/social/group_contact.inc.php b/main/social/group_contact.inc.php index c6fe4e4c45..ac80209635 100755 --- a/main/social/group_contact.inc.php +++ b/main/social/group_contact.inc.php @@ -59,7 +59,7 @@ for ($p=0;$p"") { $user_info=api_get_user_info($list_friends_id[$j]); - $user_name=api_xml_http_response_encode($user_info['firstName'].' '.$user_info['lastName']) ; + $user_name=api_xml_http_response_encode(api_get_person_name($user_info['firstName'], $user_info['lastName'])); if($list_friends_file[$j]==='unknown.jpg') { $big=''; } else { diff --git a/main/social/profile.php b/main/social/profile.php index ba92e7f171..e403ab5fae 100644 --- a/main/social/profile.php +++ b/main/social/profile.php @@ -1,924 +1,930 @@ - -* @author Isaac Flores Paz -* @package dokeos.social -*/ - -/** - * Init - */ -$language_file = array('registration','messages','userInfo','admin','forum','blog'); -$cidReset = true; -require '../inc/global.inc.php'; -require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; -require_once api_get_path(LIBRARY_PATH).'social.lib.php'; -require_once api_get_path(LIBRARY_PATH).'array.lib.php'; -$user_id = api_get_user_id(); -$show_full_profile = true; - -//I'm your friend? I can see your profile? -if (isset($_GET['u'])) { - $user_id = (int) Database::escape_string($_GET['u']); - // It's me! - if (api_get_user_id() != $user_id) { - $user_info = UserManager::get_user_info_by_id($user_id); - $show_full_profile = false; - if ($user_info==false) { - // user does no exist !! - api_not_allowed(); - } else { - //checking the relationship between me and my friend - $my_status= UserFriend::get_relation_between_contacts(api_get_user_id(), $user_id); - if (in_array($my_status, array(SOCIALPARENT, SOCIALFRIEND, SOCIALGOODFRIEND))) { - $show_full_profile = true; - } - //checking the relationship between my friend and me - $my_friend_status = UserFriend::get_relation_between_contacts($user_id, api_get_user_id()); - if (in_array($my_friend_status, array(SOCIALPARENT, SOCIALFRIEND, SOCIALGOODFRIEND))) { - $show_full_profile = true; - } else { - // im probably not a good friend - $show_full_profile = false; - } - } - } else { - $user_info = UserManager::get_user_info_by_id($user_id); - } -} else { - $user_info = UserManager::get_user_info_by_id($user_id); -} - -$libpath = api_get_path(LIBRARY_PATH); -require_once api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php'; -require_once api_get_path(SYS_CODE_PATH).'announcements/announcements.inc.php'; -require_once $libpath.'course.lib.php'; -require_once $libpath.'formvalidator/FormValidator.class.php'; -require_once $libpath.'magpierss/rss_fetch.inc'; - -api_block_anonymous_users(); - -$htmlHeadXtra[] = ''; //jQuery -$htmlHeadXtra[] = ''; //jQuery corner -$htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ''; -$htmlHeadXtra[] = ' -'; -$htmlHeadXtra[] = ''; -if (isset($_GET['shared'])) { - $my_link='../social/index.php'; - $link_shared='shared='.Security::remove_XSS($_GET['shared']); -} else { - $my_link='../auth/profile.php'; - $link_shared=''; -} -$interbreadcrumb[]= array ('url' =>$my_link,'name' => get_lang('ModifyProfile') ); - -$interbreadcrumb[]= array ( - 'url' => '../social/profile.php?'.$link_shared.'#remote-tab-1', - 'name' => get_lang('ViewMySharedProfile') -); - -if (isset($_GET['u']) && is_numeric($_GET['u'])) { - $info_user=api_get_user_info($_GET['u']); - $interbreadcrumb[]= array ( - 'url' => '#', - 'name' => $info_user['firstName'].' '.$info_user['lastName'] - ); -} -if (isset($_GET['u'])) { - $param_user='u='.Security::remove_XSS($_GET['u']); -}else { - $info_user=api_get_user_info(api_get_user_id()); - $param_user=''; -} -$_SESSION['social_user_id'] = $user_id; -/** - * Helper functions definition - */ -function get_logged_user_course_html($my_course, $count) { - global $nosession; - if (api_get_setting('use_session_mode')=='true' && !$nosession) { - global $now, $date_start, $date_end; - } - //initialise - $result = ''; - // Table definitions - $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); - $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); - $course_database = $my_course['db']; - $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database); - $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database); - $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database); - - $user_id = api_get_user_id(); - $course_system_code = $my_course['k']; - $course_visual_code = $my_course['c']; - $course_title = $my_course['i']; - $course_directory = $my_course['d']; - $course_teacher = $my_course['t']; - $course_teacher_email = isset($my_course['email'])?$my_course['email']:''; - $course_info = Database :: get_course_info($course_system_code); - //error_log(print_r($course_info,true)); - $course_access_settings = CourseManager :: get_access_settings($course_system_code); - - $course_visibility = $course_access_settings['visibility']; - - $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code); - //function logic - act on the data - $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']); - if ($is_virtual_course) { - // If the current user is also subscribed in the real course to which this - // virtual course is linked, we don't need to display the virtual course entry in - // the course list - it is combined with the real course entry. - $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code); - $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code); - if ($is_subscribed_in_target_course) { - return; //do not display this course entry - } - } - $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id()); - if ($has_virtual_courses) { - $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info); - $course_display_title = $return_result['title']; - $course_display_code = $return_result['code']; - } else { - $course_display_title = $course_title; - $course_display_code = $course_visual_code; - } - $s_course_status=$my_course['s']; - $s_htlm_status_icon=""; - - if ($s_course_status==1) { - $s_htlm_status_icon=Display::return_icon('teachers.gif', get_lang('Teacher')); - } - if ($s_course_status==2) { - $s_htlm_status_icon=Display::return_icon('coachs.gif', get_lang('GeneralCoach')); - } - if ($s_course_status==5) { - $s_htlm_status_icon=Display::return_icon('students.gif', get_lang('Student')); - } - - //display course entry - $result .= '
'; - //$result .= ''; - $result .= '

'; - $result .= $s_htlm_status_icon; - - //show a hyperlink to the course, unless the course is closed and user is not course admin - if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { - $result .= ' '.$course_title.'

'; - /* - if(api_get_setting('use_session_mode')=='true' && !$nosession) { - if(empty($my_course['id_session'])) { - $my_course['id_session'] = 0; - } - if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') { - //$result .= ''.$course_display_title.''; - $result .= ''.$course_display_title.''; - } - } else { - //$result .= ''.$course_display_title.''; - $result .= ''.$course_display_title.''; - }*/ - } else { - $result .= $course_display_title." "." ".get_lang('CourseClosed').""; - } - // show the course_code and teacher if chosen to display this - // we dont need this! - /* - if (api_get_setting('display_coursecode_in_courselist') == 'true' OR api_get_setting('display_teacher_in_courselist') == 'true') { - $result .= '
'; - } - if (api_get_setting('display_coursecode_in_courselist') == 'true') { - $result .= $course_display_code; - } - if (api_get_setting('display_coursecode_in_courselist') == 'true' AND api_get_setting('display_teacher_in_courselist') == 'true') { - $result .= ' – '; - } - if (api_get_setting('display_teacher_in_courselist') == 'true') { - $result .= $course_teacher; - if(!empty($course_teacher_email)) { - $result .= ' ('.$course_teacher_email.')'; - } - } - */ - $current_course_settings = CourseManager :: get_access_settings($my_course['k']); - // display the what's new icons - // $result .= show_notification($my_course); - if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) { - reset($digest); - $result .= '
    '; - while (list ($key2) = each($digest[$thisCourseSysCode])) { - $result .= '
  • '; - if ($orderKey[1] == 'keyTools') { - $result .= ""; - $result .= "$toolsList[$key2][\"name\"]"; - } else { - $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2)); - } - $result .= '
  • '; - $result .= '
      '; - reset($digest[$thisCourseSysCode][$key2]); - while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) { - $result .= '
    • '; - if ($orderKey[2] == 'keyTools') { - $result .= ""; - $result .= "$toolsList[$key3][\"name\"]"; - } else { - $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3)); - } - $result .= '
        '; - reset($digest[$thisCourseSysCode][$key2][$key3]); - while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) { - $result .= '
      • '; - $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT)); - $result .= '
      • '; - } - $result .= '
      '; - $result .= '
    • '; - } - $result .= '
    '; - $result .= ''; - } - $result .= '
'; - } - $result .= ''; - $result .= '
'; - - if (api_get_setting('use_session_mode')=='true' && !$nosession) { - $session = ''; - $active = false; - if (!empty($my_course['session_name'])) { - - // Request for the name of the general coach - $sql = 'SELECT lastname, firstname - FROM '.$tbl_session.' ts LEFT JOIN '.$main_user_table .' tu - ON ts.id_coach = tu.user_id - WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1'; - $rs = api_sql_query($sql, __FILE__, __LINE__); - $sessioncoach = api_store_result($rs); - $sessioncoach = $sessioncoach[0]; - - $session = array(); - $session['title'] = $my_course['session_name']; - if ( $my_course['date_start']=='0000-00-00' ) { - $session['dates'] = get_lang('WithoutTimeLimits'); - if ( api_get_setting('show_session_coach') === 'true' ) { - $session['coach'] = get_lang('GeneralCoach').': '.$sessioncoach['lastname'].' '.$sessioncoach['firstname']; - } - $active = true; - } else { - $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end']; - if ( api_get_setting('show_session_coach') === 'true' ) { - $session['coach'] = get_lang('GeneralCoach').': '.$sessioncoach['lastname'].' '.$sessioncoach['firstname']; - } - $active = ($date_start <= $now && $date_end >= $now)?true:false; - } - } - $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active); - } else { - $output = array ($my_course['user_course_cat'], $result); - } - //$my_course['creation_date']; - return $output; -} -/** - * Get user's feeds - * @param int User ID - * @param int Limit of posts per feed - * @return string HTML section with all feeds included - * @author Yannick Warnier - * @since Dokeos 1.8.6.1 - */ -function get_user_feeds($user,$limit=5) { - if (!function_exists('fetch_rss')) { return '';} - $fields = UserManager::get_extra_fields(); - $feed_fields = array(); - $feeds = array(); - $res = '
'.get_lang('RSSFeeds').'
'; - $res .= ''; - $res .= '

'; - return $res; -} -/** - * Display - */ -Display :: display_header(null); - -// @todo here we must show the user information as read only -//User picture size is calculated from SYSTEM path - -$img_array= UserManager::get_user_picture_path_by_id($user_id,'web',true,true); - -//print_r($user_info); -echo $s=""; - -//echo ''; - -//Setting some course info -$my_user_id=isset($_GET['u']) ? Security::remove_XSS($_GET['u']) : api_get_user_id(); -$personal_course_list = UserManager::get_personal_session_course_list($my_user_id); -$course_list_code = array(); -$i=1; -//print_r($personal_course_list); - - - -if (is_array($personal_course_list)) { - foreach ($personal_course_list as $my_course) { - if ($i<=10) { - $list[] = get_logged_user_course_html($my_course,$i); - //$course_list_code[] = array('code'=>$my_course['c'],'dbName'=>$my_course['db'], 'title'=>$my_course['i']); cause double - $course_list_code[] = array('code'=>$my_course['c'],'dbName'=>$my_course['db']); - - } else { - break; - } - $i++; - } - //to avoid repeted courses - $course_list_code = array_unique_dimensional($course_list_code); -} - -echo '
'; -if ($user_id == api_get_user_id()) - echo get_lang('ViewMySharedProfile'); -else - echo get_lang('ViewSharedProfile').' - '.ucfirst($user_info['firstname']).' '.$user_info['lastname']; - -echo '
'; - -echo '
'; -// RIGHT COLUMN - echo '
'; - //---- FRIENDS - - if ($show_full_profile) { - $list_path_friends= $list_path_normal_friends = $list_path_parents = array(); - - $list_path_good_friends = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALGOODFRIEND); - $list_path_normal_friends = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALFRIEND); - $list_path_parents = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALPARENT); - - $list_path_friends = array_merge_recursive($list_path_good_friends, $list_path_normal_friends, $list_path_parents); - - $friend_html=''; - $number_of_images=3; - $number_friends=0; - $list_friends_id=array(); - $list_friends_dir=array(); - $list_friends_file=array(); - - if (count($list_path_friends)!=0) { - $friends_count = count($list_path_friends['id_friend']); - - for ($z=0;$z< $friends_count ;$z++) { - $list_friends_id[] = $list_path_friends['id_friend'][$z]['friend_user_id']; - $list_friends_dir[] = $list_path_friends['path_friend'][$z]['dir']; - $list_friends_file[]= $list_path_friends['path_friend'][$z]['file']; - } - $number_friends= count($list_friends_dir); - $number_loop = ($number_friends/$number_of_images); - $loop_friends = ceil($number_loop); - $j=0; - $friend_html .= '
'.get_lang('SocialFriend').'
'; - $friend_html.= ''; // end of content section - - -echo '
'; - // LEFT COLUMN - echo '
'; - - //--- User image - echo ''; - echo '
'; - echo '
'; - if (api_get_user_id() == $user_id) { - // if i'm me - echo '
'; - echo Display::return_icon('email.gif'); - echo ' '.get_lang('MyInbox').' '; - echo '
'; - echo '
'; - echo Display::return_icon('edit.gif'); - echo ' '.get_lang('EditInformation').' '; - echo '
'; - } else { - echo ' '.Display::return_icon('message_new.png').'  '.get_lang('SendMessage').'
'; - //echo '  '.get_lang('SendMessage').''; - } - echo '
'; - echo '
'; - - // Send message or Add to friend links - /*if (!$show_full_profile) { - echo '  '.Display::return_icon('message_new.png').'  '.get_lang('SendMessage').'
'; - }*/ - - // Extra information - - if ($show_full_profile) { - //-- Extra Data - $t_uf = Database :: get_main_table(TABLE_MAIN_USER_FIELD); - $t_ufo = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS); - $extra_user_data = UserManager::get_extra_user_data($user_id); - $extra_information = ''; - if (is_array($extra_user_data) && count($extra_user_data)>0 ) { - $extra_information = '
'; - $extra_information .= get_lang('ExtraInformation'); - $extra_information .= '

'; - $extra_information .=''; - $extra_information .= '

'; - } - // if there are information to show - if (!empty($extra_information_value)) - echo $extra_information; - - - // ---- My Agenda Items - $my_agenda_items = show_simple_personal_agenda($user_id); - if (!empty($my_agenda_items)) { - echo '
'; - echo get_lang('MyAgenda'); - echo '
'; - $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA); - echo ''; - } - - //-----Announcements - $announcement_content = ''; - $my_announcement_by_user_id=isset($_GET['u']) ? Security::remove_XSS($_GET['u']) : api_get_user_id(); - - foreach ($course_list_code as $course) { - $content = get_all_annoucement_by_user_course($course['dbName'],$my_announcement_by_user_id); - $course_info=api_get_course_info($course['code']); - if (!empty($content)) { - $announcement_content.= ''; - $announcement_content.= '
'; - } - - } - - if(!empty($announcement_content)) { - echo '
'; - echo get_lang('Announcements'); - echo '

'; - echo ''; - } - } - echo '
'; - - - // CENTER COLUMN - - - echo '
'; - - //--- Basic Information - echo '
'; - echo get_lang('Information'); //class="social-profile-info" - echo '
'; - echo ''; - // COURSES LIST - if ($show_full_profile) { - //print_r($personal_course_list); - //echo '
';
-				if (is_array($list)) {
-					echo '
'; - echo api_ucfirst(get_lang('MyCourses')); - echo '
'; - echo ''; - } - echo '
'; - echo '
'; - echo '
'; -echo '
'; //from the main -echo '
 
'; -Display :: display_footer(); + +* @author Isaac Flores Paz +* @package dokeos.social +*/ + +/** + * Init + */ +$language_file = array('registration','messages','userInfo','admin','forum','blog'); +$cidReset = true; +require '../inc/global.inc.php'; +require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php'; +require_once api_get_path(LIBRARY_PATH).'social.lib.php'; +require_once api_get_path(LIBRARY_PATH).'array.lib.php'; +$user_id = api_get_user_id(); +$show_full_profile = true; + +//I'm your friend? I can see your profile? +if (isset($_GET['u'])) { + $user_id = (int) Database::escape_string($_GET['u']); + // It's me! + if (api_get_user_id() != $user_id) { + $user_info = UserManager::get_user_info_by_id($user_id); + $show_full_profile = false; + if ($user_info==false) { + // user does no exist !! + api_not_allowed(); + } else { + //checking the relationship between me and my friend + $my_status= UserFriend::get_relation_between_contacts(api_get_user_id(), $user_id); + if (in_array($my_status, array(SOCIALPARENT, SOCIALFRIEND, SOCIALGOODFRIEND))) { + $show_full_profile = true; + } + //checking the relationship between my friend and me + $my_friend_status = UserFriend::get_relation_between_contacts($user_id, api_get_user_id()); + if (in_array($my_friend_status, array(SOCIALPARENT, SOCIALFRIEND, SOCIALGOODFRIEND))) { + $show_full_profile = true; + } else { + // im probably not a good friend + $show_full_profile = false; + } + } + } else { + $user_info = UserManager::get_user_info_by_id($user_id); + } +} else { + $user_info = UserManager::get_user_info_by_id($user_id); +} + +$libpath = api_get_path(LIBRARY_PATH); +require_once api_get_path(SYS_CODE_PATH).'calendar/myagenda.inc.php'; +require_once api_get_path(SYS_CODE_PATH).'announcements/announcements.inc.php'; +require_once $libpath.'course.lib.php'; +require_once $libpath.'formvalidator/FormValidator.class.php'; +require_once $libpath.'magpierss/rss_fetch.inc'; + +api_block_anonymous_users(); + +$htmlHeadXtra[] = ''; //jQuery +$htmlHeadXtra[] = ''; //jQuery corner +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ''; +$htmlHeadXtra[] = ' +'; +$htmlHeadXtra[] = ''; +if (isset($_GET['shared'])) { + $my_link='../social/index.php'; + $link_shared='shared='.Security::remove_XSS($_GET['shared']); +} else { + $my_link='../auth/profile.php'; + $link_shared=''; +} +$interbreadcrumb[]= array ('url' =>$my_link,'name' => get_lang('ModifyProfile') ); + +$interbreadcrumb[]= array ( + 'url' => '../social/profile.php?'.$link_shared.'#remote-tab-1', + 'name' => get_lang('ViewMySharedProfile') +); + +if (isset($_GET['u']) && is_numeric($_GET['u'])) { + $info_user=api_get_user_info($_GET['u']); + $interbreadcrumb[]= array ( + 'url' => 'javascript: void(0);', + 'name' => api_get_person_name($info_user['firstName'], $info_user['lastName']) + ); +} +if (isset($_GET['u'])) { + $param_user='u='.Security::remove_XSS($_GET['u']); +}else { + $info_user=api_get_user_info(api_get_user_id()); + $param_user=''; +} +$_SESSION['social_user_id'] = $user_id; +/** + * Helper functions definition + */ +function get_logged_user_course_html($my_course, $count) { + global $nosession; + if (api_get_setting('use_session_mode')=='true' && !$nosession) { + global $now, $date_start, $date_end; + } + //initialise + $result = ''; + // Table definitions + $main_user_table = Database :: get_main_table(TABLE_MAIN_USER); + $tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION); + $course_database = $my_course['db']; + $course_tool_table = Database :: get_course_table(TABLE_TOOL_LIST, $course_database); + $tool_edit_table = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_database); + $course_group_user_table = Database :: get_course_table(TOOL_USER, $course_database); + + $user_id = api_get_user_id(); + $course_system_code = $my_course['k']; + $course_visual_code = $my_course['c']; + $course_title = $my_course['i']; + $course_directory = $my_course['d']; + $course_teacher = $my_course['t']; + $course_teacher_email = isset($my_course['email'])?$my_course['email']:''; + $course_info = Database :: get_course_info($course_system_code); + //error_log(print_r($course_info,true)); + $course_access_settings = CourseManager :: get_access_settings($course_system_code); + + $course_visibility = $course_access_settings['visibility']; + + $user_in_course_status = CourseManager :: get_user_in_course_status(api_get_user_id(), $course_system_code); + //function logic - act on the data + $is_virtual_course = CourseManager :: is_virtual_course_from_system_code($my_course['k']); + if ($is_virtual_course) { + // If the current user is also subscribed in the real course to which this + // virtual course is linked, we don't need to display the virtual course entry in + // the course list - it is combined with the real course entry. + $target_course_code = CourseManager :: get_target_of_linked_course($course_system_code); + $is_subscribed_in_target_course = CourseManager :: is_user_subscribed_in_course(api_get_user_id(), $target_course_code); + if ($is_subscribed_in_target_course) { + return; //do not display this course entry + } + } + $has_virtual_courses = CourseManager :: has_virtual_courses_from_code($course_system_code, api_get_user_id()); + if ($has_virtual_courses) { + $return_result = CourseManager :: determine_course_title_from_course_info(api_get_user_id(), $course_info); + $course_display_title = $return_result['title']; + $course_display_code = $return_result['code']; + } else { + $course_display_title = $course_title; + $course_display_code = $course_visual_code; + } + $s_course_status=$my_course['s']; + $s_htlm_status_icon=""; + + if ($s_course_status==1) { + $s_htlm_status_icon=Display::return_icon('teachers.gif', get_lang('Teacher')); + } + if ($s_course_status==2) { + $s_htlm_status_icon=Display::return_icon('coachs.gif', get_lang('GeneralCoach')); + } + if ($s_course_status==5) { + $s_htlm_status_icon=Display::return_icon('students.gif', get_lang('Student')); + } + + //display course entry + $result .= '
'; + //$result .= ''; + $result .= '

'; + $result .= $s_htlm_status_icon; + + //show a hyperlink to the course, unless the course is closed and user is not course admin + if ($course_visibility != COURSE_VISIBILITY_CLOSED || $user_in_course_status == COURSEMANAGER) { + $result .= ' '.$course_title.'

'; + /* + if(api_get_setting('use_session_mode')=='true' && !$nosession) { + if(empty($my_course['id_session'])) { + $my_course['id_session'] = 0; + } + if($user_in_course_status == COURSEMANAGER || ($date_start <= $now && $date_end >= $now) || $date_start=='0000-00-00') { + //$result .= ''.$course_display_title.''; + $result .= ''.$course_display_title.''; + } + } else { + //$result .= ''.$course_display_title.''; + $result .= ''.$course_display_title.''; + }*/ + } else { + $result .= $course_display_title." "." ".get_lang('CourseClosed').""; + } + // show the course_code and teacher if chosen to display this + // we dont need this! + /* + if (api_get_setting('display_coursecode_in_courselist') == 'true' OR api_get_setting('display_teacher_in_courselist') == 'true') { + $result .= '
'; + } + if (api_get_setting('display_coursecode_in_courselist') == 'true') { + $result .= $course_display_code; + } + if (api_get_setting('display_coursecode_in_courselist') == 'true' AND api_get_setting('display_teacher_in_courselist') == 'true') { + $result .= ' – '; + } + if (api_get_setting('display_teacher_in_courselist') == 'true') { + $result .= $course_teacher; + if(!empty($course_teacher_email)) { + $result .= ' ('.$course_teacher_email.')'; + } + } + */ + $current_course_settings = CourseManager :: get_access_settings($my_course['k']); + // display the what's new icons + // $result .= show_notification($my_course); + if ((CONFVAL_showExtractInfo == SCRIPTVAL_InCourseList || CONFVAL_showExtractInfo == SCRIPTVAL_Both) && $nbDigestEntries > 0) { + reset($digest); + $result .= '
    '; + while (list ($key2) = each($digest[$thisCourseSysCode])) { + $result .= '
  • '; + if ($orderKey[1] == 'keyTools') { + $result .= ""; + $result .= "$toolsList[$key2][\"name\"]"; + } else { + $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key2)); + } + $result .= '
  • '; + $result .= '
      '; + reset($digest[$thisCourseSysCode][$key2]); + while (list ($key3, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2])) { + $result .= '
    • '; + if ($orderKey[2] == 'keyTools') { + $result .= ""; + $result .= "$toolsList[$key3][\"name\"]"; + } else { + $result .= format_locale_date(CONFVAL_dateFormatForInfosFromCourses, strtotime($key3)); + } + $result .= '
        '; + reset($digest[$thisCourseSysCode][$key2][$key3]); + while (list ($key4, $dataFromCourse) = each($digest[$thisCourseSysCode][$key2][$key3])) { + $result .= '
      • '; + $result .= htmlspecialchars(substr(strip_tags($dataFromCourse), 0, CONFVAL_NB_CHAR_FROM_CONTENT)); + $result .= '
      • '; + } + $result .= '
      '; + $result .= '
    • '; + } + $result .= '
    '; + $result .= ''; + } + $result .= '
'; + } + $result .= ''; + $result .= '
'; + + if (api_get_setting('use_session_mode')=='true' && !$nosession) { + $session = ''; + $active = false; + if (!empty($my_course['session_name'])) { + + // Request for the name of the general coach + $sql = 'SELECT lastname, firstname + FROM '.$tbl_session.' ts LEFT JOIN '.$main_user_table .' tu + ON ts.id_coach = tu.user_id + WHERE ts.id='.(int) $my_course['id_session']. ' LIMIT 1'; + $rs = api_sql_query($sql, __FILE__, __LINE__); + $sessioncoach = api_store_result($rs); + $sessioncoach = $sessioncoach[0]; + + $session = array(); + $session['title'] = $my_course['session_name']; + if ( $my_course['date_start']=='0000-00-00' ) { + $session['dates'] = get_lang('WithoutTimeLimits'); + if ( api_get_setting('show_session_coach') === 'true' ) { + $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); + } + $active = true; + } else { + $session ['dates'] = ' - '.get_lang('From').' '.$my_course['date_start'].' '.get_lang('To').' '.$my_course['date_end']; + if ( api_get_setting('show_session_coach') === 'true' ) { + $session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($sessioncoach['firstname'], $sessioncoach['lastname']); + } + $active = ($date_start <= $now && $date_end >= $now)?true:false; + } + } + $output = array ($my_course['user_course_cat'], $result, $my_course['id_session'], $session, 'active'=>$active); + } else { + $output = array ($my_course['user_course_cat'], $result); + } + //$my_course['creation_date']; + return $output; +} +/** + * Get user's feeds + * @param int User ID + * @param int Limit of posts per feed + * @return string HTML section with all feeds included + * @author Yannick Warnier + * @since Dokeos 1.8.6.1 + */ +function get_user_feeds($user,$limit=5) { + if (!function_exists('fetch_rss')) { return '';} + $fields = UserManager::get_extra_fields(); + $feed_fields = array(); + $feeds = array(); + $res = '
'.get_lang('RSSFeeds').'
'; + $res .= ''; + $res .= '

'; + return $res; +} +/** + * Display + */ +Display :: display_header(null); + +// @todo here we must show the user information as read only +//User picture size is calculated from SYSTEM path + +$img_array= UserManager::get_user_picture_path_by_id($user_id,'web',true,true); + +//print_r($user_info); +// Added by Ivan Tcholakov, 03-APR-2009. +if (USE_JQUERY_CORNERS_SCRIPT) { +// +echo $s=""; +// +} +// + +//echo ''; + +//Setting some course info +$my_user_id=isset($_GET['u']) ? Security::remove_XSS($_GET['u']) : api_get_user_id(); +$personal_course_list = UserManager::get_personal_session_course_list($my_user_id); +$course_list_code = array(); +$i=1; +//print_r($personal_course_list); + + + +if (is_array($personal_course_list)) { + foreach ($personal_course_list as $my_course) { + if ($i<=10) { + $list[] = get_logged_user_course_html($my_course,$i); + //$course_list_code[] = array('code'=>$my_course['c'],'dbName'=>$my_course['db'], 'title'=>$my_course['i']); cause double + $course_list_code[] = array('code'=>$my_course['c'],'dbName'=>$my_course['db']); + + } else { + break; + } + $i++; + } + //to avoid repeted courses + $course_list_code = array_unique_dimensional($course_list_code); +} + +echo '
'; +if ($user_id == api_get_user_id()) + echo get_lang('ViewMySharedProfile'); +else + echo get_lang('ViewSharedProfile').' - '.api_get_person_name($user_info['firstname'], $user_info['lastname']); + +echo '
'; + +echo '
'; +// RIGHT COLUMN + echo '
'; + //---- FRIENDS + + if ($show_full_profile) { + $list_path_friends= $list_path_normal_friends = $list_path_parents = array(); + + $list_path_good_friends = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALGOODFRIEND); + $list_path_normal_friends = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALFRIEND); + $list_path_parents = UserFriend::get_list_path_web_by_user_id($user_id, SOCIALPARENT); + + $list_path_friends = array_merge_recursive($list_path_good_friends, $list_path_normal_friends, $list_path_parents); + + $friend_html=''; + $number_of_images=3; + $number_friends=0; + $list_friends_id=array(); + $list_friends_dir=array(); + $list_friends_file=array(); + + if (count($list_path_friends)!=0) { + $friends_count = count($list_path_friends['id_friend']); + + for ($z=0;$z< $friends_count ;$z++) { + $list_friends_id[] = $list_path_friends['id_friend'][$z]['friend_user_id']; + $list_friends_dir[] = $list_path_friends['path_friend'][$z]['dir']; + $list_friends_file[]= $list_path_friends['path_friend'][$z]['file']; + } + $number_friends= count($list_friends_dir); + $number_loop = ($number_friends/$number_of_images); + $loop_friends = ceil($number_loop); + $j=0; + $friend_html .= '
'.get_lang('SocialFriend').'
'; + $friend_html.= ''; // end of content section + + +echo '
'; + // LEFT COLUMN + echo '
'; + + //--- User image + echo ''; + echo '
'; + echo '
'; + if (api_get_user_id() == $user_id) { + // if i'm me + echo '
'; + echo Display::return_icon('email.gif'); + echo ' '.get_lang('MyInbox').' '; + echo '
'; + echo '
'; + echo Display::return_icon('edit.gif'); + echo ' '.get_lang('EditInformation').' '; + echo '
'; + } else { + echo ' '.Display::return_icon('message_new.png').'  '.get_lang('SendMessage').'
'; + //echo '  '.get_lang('SendMessage').''; + } + echo '
'; + echo '
'; + + // Send message or Add to friend links + /*if (!$show_full_profile) { + echo '  '.Display::return_icon('message_new.png').'  '.get_lang('SendMessage').'
'; + }*/ + + // Extra information + + if ($show_full_profile) { + //-- Extra Data + $t_uf = Database :: get_main_table(TABLE_MAIN_USER_FIELD); + $t_ufo = Database :: get_main_table(TABLE_MAIN_USER_FIELD_OPTIONS); + $extra_user_data = UserManager::get_extra_user_data($user_id); + $extra_information = ''; + if (is_array($extra_user_data) && count($extra_user_data)>0 ) { + $extra_information = '
'; + $extra_information .= get_lang('ExtraInformation'); + $extra_information .= '

'; + $extra_information .=''; + $extra_information .= '

'; + } + // if there are information to show + if (!empty($extra_information_value)) + echo $extra_information; + + + // ---- My Agenda Items + $my_agenda_items = show_simple_personal_agenda($user_id); + if (!empty($my_agenda_items)) { + echo '
'; + echo get_lang('MyAgenda'); + echo '
'; + $tbl_personal_agenda = Database :: get_user_personal_table(TABLE_PERSONAL_AGENDA); + echo ''; + } + + //-----Announcements + $announcement_content = ''; + $my_announcement_by_user_id=isset($_GET['u']) ? Security::remove_XSS($_GET['u']) : api_get_user_id(); + + foreach ($course_list_code as $course) { + $content = get_all_annoucement_by_user_course($course['dbName'],$my_announcement_by_user_id); + $course_info=api_get_course_info($course['code']); + if (!empty($content)) { + $announcement_content.= ''; + $announcement_content.= '
'; + } + + } + + if(!empty($announcement_content)) { + echo '
'; + echo get_lang('Announcements'); + echo '

'; + echo ''; + } + } + echo '
'; + + + // CENTER COLUMN + + + echo '
'; + + //--- Basic Information + echo '
'; + echo get_lang('Information'); //class="social-profile-info" + echo '
'; + echo ''; + // COURSES LIST + if ($show_full_profile) { + //print_r($personal_course_list); + //echo '
';
+				if ( is_array($list) ) {
+					echo '
'; + echo api_ucfirst(get_lang('MyCourses')); + echo '
'; + echo ''; + } + echo '
'; + echo '
'; + echo '
'; +echo '
'; //from the main +echo '
 
'; +Display :: display_footer(); \ No newline at end of file diff --git a/main/social/qualify_contact.inc.php b/main/social/qualify_contact.inc.php index 85f2c9a494..d460f682f7 100755 --- a/main/social/qualify_contact.inc.php +++ b/main/social/qualify_contact.inc.php @@ -27,7 +27,7 @@ $user_friend_relation=UserFriend::get_relation_between_contacts(api_get_user_id(

'.$name_user=api_xml_http_response_encode($user_info['firstName'].' '.$user_info['lastName']); + echo '

'.$name_user=api_xml_http_response_encode(api_get_person_name($user_info['firstName'], $user_info['lastName'])); ?>
diff --git a/main/social/select_friend_response.php b/main/social/select_friend_response.php index a4bda13aab..01ecb1097b 100755 --- a/main/social/select_friend_response.php +++ b/main/social/select_friend_response.php @@ -60,7 +60,7 @@ cellpadding="0" cellspacing="0" bgcolor="#9DACBF"> diff --git a/main/social/select_options.php b/main/social/select_options.php index c9e813b54c..d9c512086e 100755 --- a/main/social/select_options.php +++ b/main/social/select_options.php @@ -10,16 +10,17 @@ $search=Database::escape_string(Security::remove_XSS($_POST['search'])); $current_date=date('Y-m-d H:i:s',time()); $html_form=''; - while ($row = Database :: fetch_array($result, 'ASSOC')) + while ($row=Database::fetch_array($result,'ASSOC')) { - echo ''; + echo ''; } echo ''; //echo ' '; echo ''; echo ''; - display :: display_footer(); + display::display_footer(); exit(); } -} -else +} +else { - $row = Database :: fetch_array($result, 'ASSOC'); + $row=Database::fetch_array($result,'ASSOC'); $survey_invitation['survey_id'] = $row['survey_id']; } // getting the survey information -$survey_data = survey_manager :: get_survey($survey_invitation['survey_id']); +$survey_data = survey_manager::get_survey($survey_invitation['survey_id']); //echo '
';print_r($survey_data);echo '
'; //echo $survey_data['form_fields'];echo '-
-';echo $survey_data['show_form_profile']; $survey_data['survey_id'] = $survey_invitation['survey_id']; //print_r($survey_data); // storing the answers -if (count($_POST) > 0) +if (count($_POST)>0) { - if ($survey_data['survey_type'] === '0') + if ($survey_data['survey_type']==='0') { // getting all the types of the question (because of the special treatment of the score question type - $sql = "SELECT * FROM $table_survey_question WHERE survey_id = '" . Database :: escape_string($survey_invitation['survey_id']) . "'"; + $sql = "SELECT * FROM $table_survey_question WHERE survey_id = '".Database::escape_string($survey_invitation['survey_id'])."'"; $result = api_sql_query($sql, __FILE__, __LINE__); - - while ($row = Database :: fetch_array($result, 'ASSOC')) + + while ($row = Database::fetch_array($result,'ASSOC')) { $types[$row['question_id']] = $row['type']; - } - + } + // looping through all the post values - foreach ($_POST as $key => $value) + foreach ($_POST as $key=>$value) { // if the post value key contains the string 'question' then it is an answer on a question if (strstr($key, 'question')) { // finding the question id by removing 'question' - $survey_question_id = str_replace('question', '', $key); - + $survey_question_id = str_replace('question', '',$key); + // if the post value is an array then we have a multiple response question or a scoring question type // remark: when it is a multiple response then the value of the array is the option_id // when it is a scoring question then the key of the array is the option_id and the value is the value - if (is_array($value)) + if (is_array($value)) { - SurveyUtil :: remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); - foreach ($value as $answer_key => $answer_value) + SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); + foreach ($value as $answer_key => $answer_value) { - if ($types[$survey_question_id] == 'score') + if ($types[$survey_question_id] == 'score') { $option_id = $answer_key; $option_value = $answer_value; - } - else + } + else { $option_id = $answer_value; $option_value = ''; } - SurveyUtil :: store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $option_id, $option_value, $survey_data); + SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $option_id, $option_value, $survey_data); } } // all the other question types (open question, multiple choice, percentage, ...) - else + else { - if ($types[$survey_question_id] == 'percentage') + if ($types[$survey_question_id] == 'percentage') { - $sql = "SELECT * FROM $table_survey_question_option WHERE question_option_id='" . Database :: escape_string($value) . "'"; + $sql = "SELECT * FROM $table_survey_question_option WHERE question_option_id='".Database::escape_string($value)."'"; $result = api_sql_query($sql, __FILE__, __LINE__); - $row = Database :: fetch_array($result, 'ASSOC'); + $row = Database::fetch_array($result,'ASSOC'); $option_value = $row['option_text']; } else { $option_value = 0; @@ -232,79 +232,79 @@ if (count($_POST) > 0) //$value = 0; } } - + $survey_question_answer = $value; - SurveyUtil :: remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); - SurveyUtil :: store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data); + SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); + SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data); //SurveyUtil::store_answer($user,$survey_id,$question_id, $option_id, $option_value, $survey_data); } } } } - elseif ($survey_data['survey_type'] === '1') //conditional/personality-test type surveys - { - // getting all the types of the question (because of the special treatment of the score question type - $shuffle = ''; - if ($survey_data['shuffle'] == '1') + elseif ($survey_data['survey_type']==='1') //conditional/personality-test type surveys + { + // getting all the types of the question (because of the special treatment of the score question type + $shuffle=''; + if ($survey_data['shuffle']=='1') { - $shuffle = ' ORDER BY RAND() '; + $shuffle= ' ORDER BY RAND() ' ; } $sql = "SELECT * FROM $table_survey_question - WHERE survey_id = '" . Database :: escape_string($survey_invitation['survey_id']) . "' + WHERE survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' AND survey_group_pri='0' $shuffle "; $result = api_sql_query($sql, __FILE__, __LINE__); - // there is only one question type for conditional surveys - while ($row = Database :: fetch_array($result, 'ASSOC')) + // there is only one question type for conditional surveys + while ($row = Database::fetch_array($result,'ASSOC')) { $types[$row['question_id']] = $row['type']; - } - + } + // looping through all the post values - foreach ($_POST as $key => $value) + foreach ($_POST as $key=>$value) { // if the post value key contains the string 'question' then it is an answer to a question - if (strstr($key, 'question')) - { + if (strstr($key,'question')) + { // finding the question id by removing 'question' - $survey_question_id = str_replace('question', '', $key); + $survey_question_id = str_replace('question', '',$key); // we select the correct answer and the puntuacion $sql = "SELECT value FROM $table_survey_question_option " . - " WHERE question_option_id='" . Database :: escape_string($value) . "'"; + " WHERE question_option_id='".Database::escape_string($value)."'"; $result = api_sql_query($sql, __FILE__, __LINE__); - $row = Database :: fetch_array($result, 'ASSOC'); + $row = Database::fetch_array($result,'ASSOC'); $option_value = $row['value']; //$option_value = 0; $survey_question_answer = $value; - //we save the answer after making sure that a possible previous attempt is deleted - SurveyUtil :: remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); - SurveyUtil :: store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data); + //we save the answer after making sure that a possible previous attempt is deleted + SurveyUtil::remove_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id); + SurveyUtil::store_answer($survey_invitation['user'], $survey_invitation['survey_id'], $survey_question_id, $value, $option_value, $survey_data); //SurveyUtil::store_answer($user,$survey_id,$question_id, $option_id, $option_value, $survey_data); } - } - } - else //in case it's another type than 0 or 1 - { - die(get_lang('ErrorSurveyTypeUnknown')); + } } + else //in case it's another type than 0 or 1 + { + die(get_lang('ErrorSurveyTypeUnknown')); + } } // displaying the survey title and subtitle (appears on every page) -echo '
' . $survey_data['survey_title'] . '
'; -echo '
' . $survey_data['survey_subtitle'] . '
'; +echo '
'.$survey_data['survey_title'].'
'; +echo '
'.$survey_data['survey_subtitle'].'
'; // checking time availability check_time_availability($survey_data); // displaying the survey introduction -if (!isset ($_GET['show'])) +if (!isset($_GET['show'])) { // the first thing we do is delete the session unset($_SESSION['paged_questions']); unset($_SESSION['page_questions_sec']); $paged_questions_sec=array(); - - echo '
' . $survey_data['survey_introduction'] . '
'; + + echo '
'.$survey_data['survey_introduction'].'
'; $limit = 0; } @@ -330,37 +330,57 @@ if ($survey_data['form_fields']!='' && $survey_data['anonymous'] == 0 && is_arra } } } - + // we use the same form as in auth/profile.php require_once (api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php'); $form = new FormValidator('profile', 'post', api_get_self() . "?" . str_replace('&show_form=1', '&show_form=1', $_SERVER['QUERY_STRING']), null, array ( 'style' => 'width: 75%; float: ' . ($text_dir == 'rtl' ? 'right;' : 'left;') )); - if ($list['lastname'] == 1) { - // LAST NAME - $form->addElement('text', 'lastname', get_lang('LastName'), array ('size' => 40)); - - if (api_get_setting('profile', 'name') !== 'true') - $form->freeze(array ('lastname')); - - $form->applyFilter(array ('lastname'), 'stripslashes'); - $form->applyFilter(array ('lastname'), 'trim'); - $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required'); - } - - if ($list['firstname'] == 1 ) { - //FIRST NAME - $form->addElement('text', 'firstname', get_lang('FirstName'), array ('size' => 40)); - - if (api_get_setting('profile', 'name') !== 'true') - $form->freeze(array ('firstname')); - - $form->applyFilter(array ('firstname'), 'stripslashes'); - $form->applyFilter(array ('firstname'), 'trim'); - $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required'); + if (api_is_western_name_order()) { + if ($list['firstname'] == 1 ) { + //FIRST NAME + $form->addElement('text', 'firstname', get_lang('FirstName'), array ('size' => 40)); + if (api_get_setting('profile', 'name') !== 'true') { + $form->freeze(array ('firstname')); + } + $form->applyFilter(array ('firstname'), 'stripslashes'); + $form->applyFilter(array ('firstname'), 'trim'); + $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required'); + } + if ($list['lastname'] == 1) { + // LAST NAME + $form->addElement('text', 'lastname', get_lang('LastName'), array ('size' => 40)); + if (api_get_setting('profile', 'name') !== 'true') { + $form->freeze(array ('lastname')); + } + $form->applyFilter(array ('lastname'), 'stripslashes'); + $form->applyFilter(array ('lastname'), 'trim'); + $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required'); + } + } else { + if ($list['lastname'] == 1) { + // LAST NAME + $form->addElement('text', 'lastname', get_lang('LastName'), array ('size' => 40)); + if (api_get_setting('profile', 'name') !== 'true') { + $form->freeze(array ('lastname')); + } + $form->applyFilter(array ('lastname'), 'stripslashes'); + $form->applyFilter(array ('lastname'), 'trim'); + $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required'); + } + if ($list['firstname'] == 1 ) { + //FIRST NAME + $form->addElement('text', 'firstname', get_lang('FirstName'), array ('size' => 40)); + if (api_get_setting('profile', 'name') !== 'true') { + $form->freeze(array ('firstname')); + } + $form->applyFilter(array ('firstname'), 'stripslashes'); + $form->applyFilter(array ('firstname'), 'trim'); + $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required'); + } } - + if ($list['official_code'] == 1) { // OFFICIAL CODE if (CONFVAL_ASK_FOR_OFFICIAL_CODE) { @@ -472,7 +492,7 @@ if ($survey_data['form_fields']!='' && $survey_data['anonymous'] == 0 && is_arra break; case USER_FIELD_TYPE_DATE : $form->addElement('datepickerdate', 'extra_' . $field_details[1], $field_details[3],array('form_name'=>'profile')); - $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900); + $form->_elements[$form->_elementIndex['extra_' . $field_details[1]]]->setLocalOption('minYear', 1900); $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00'); $form -> setDefaults($defaults); if ($field_details[7] == 0) @@ -581,10 +601,10 @@ if ($survey_data['form_fields'] && $survey_data['anonymous'] == 0 && is_array($u } // displaying the survey thanks message -if (isset ($_POST['finish_survey'])) +if (isset($_POST['finish_survey'])) { - echo '
' . get_lang('SurveyFinished') . '
' . $survey_data['survey_thanks'] . '
'; - survey_manager :: update_survey_answered($survey_data['survey_id'], $survey_invitation['user'], $survey_invitation['survey_code']); + echo '
'.get_lang('SurveyFinished').'
'.$survey_data['survey_thanks'].'
'; + survey_manager::update_survey_answered($survey_data['survey_id'], $survey_invitation['user'], $survey_invitation['survey_code']); unset($_SESSION['paged_questions']); unset($_SESSION['page_questions_sec']); Display :: display_footer(); @@ -592,54 +612,54 @@ if (isset ($_POST['finish_survey'])) } // sets the random questions -$shuffle = ''; -if ($survey_data['shuffle'] == 1) +$shuffle=''; +if ($survey_data['shuffle']==1) { - $shuffle = ' BY RAND() '; -} + $shuffle= ' BY RAND() '; +} -if (isset ($_GET['show']) || isset ($_POST['personality'])) +if ( isset($_GET['show']) || isset($_POST['personality'])) { // Getting all the questions for this page and add them to a multidimensional array where the first index is the page. // as long as there is no pagebreak fount we keep adding questions to the page - $questions_displayed = array (); + $questions_displayed = array(); $counter = 0; - $paged_questions = array (); - + $paged_questions = array(); + // if non-conditional survey - if ($survey_data['survey_type'] === '0') + if ($survey_data['survey_type']==='0') { - if (empty ($_SESSION['paged_questions'])) - { - $sql = "SELECT * FROM $table_survey_question - WHERE survey_id = '" . Database :: escape_string($survey_invitation['survey_id']) . "' - ORDER BY sort ASC"; - $result = api_sql_query($sql, __FILE__, __LINE__); - while ($row = Database :: fetch_array($result, 'ASSOC')) - { - if ($row['type'] == 'pagebreak') - { - $counter++; - } - else - { - // ids from question of the current survey - $paged_questions[$counter][] = $row['question_id']; - } - } - $_SESSION['paged_questions'] = $paged_questions; - } - else - { - $paged_questions = $_SESSION['paged_questions']; - } - + if(empty($_SESSION['paged_questions'])) + { + $sql = "SELECT * FROM $table_survey_question + WHERE survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' + ORDER BY sort ASC"; + $result = api_sql_query($sql, __FILE__, __LINE__); + while ($row = Database::fetch_array($result,'ASSOC')) + { + if($row['type'] == 'pagebreak') + { + $counter++; + } + else + { + // ids from question of the current survey + $paged_questions[$counter][] = $row['question_id']; + } + } + $_SESSION['paged_questions'] = $paged_questions; + } + else + { + $paged_questions = $_SESSION['paged_questions']; + } + if (key_exists($_GET['show'], $paged_questions)) { if (isset($_GET['user_id'])) { - + // get the user into survey answer table (user or anonymus) $my_user_id=($survey_data['anonymous']==1) ? $_SESSION['surveyuser'] :api_get_user_id(); - + $sql = "SELECT survey_question.survey_group_sec1, survey_question.survey_group_sec2, survey_question.survey_group_pri, survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value, survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort @@ -650,24 +670,24 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) AND survey_question.question_id NOT IN (SELECT sa.question_id FROM ".$table_survey_answer." sa WHERE sa.user='".$my_user_id."') ORDER BY survey_question.sort, survey_question_option.sort ASC"; } else { - + $sql = "SELECT survey_question.survey_group_sec1, survey_question.survey_group_sec2, survey_question.survey_group_pri, survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value, survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort FROM $table_survey_question survey_question LEFT JOIN $table_survey_question_option survey_question_option ON survey_question.question_id = survey_question_option.question_id - WHERE survey_question.survey_id = '" . Database :: escape_string($survey_invitation['survey_id']) . "' - AND survey_question.question_id IN (" . implode(',', $paged_questions[$_GET['show']]) . ") + WHERE survey_question.survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' + AND survey_question.question_id IN (".implode(',',$paged_questions[$_GET['show']]).") ORDER BY survey_question.sort, survey_question_option.sort ASC"; - } - + } + $result = api_sql_query($sql, __FILE__, __LINE__); - $question_counter_max = Database :: num_rows($result); + $question_counter_max = Database::num_rows($result); $counter = 0; - $limit = 0; - $questions = array (); - + $limit=0; + $questions = array(); + while ($row = Database :: fetch_array($result, 'ASSOC')) { // if the type is not a pagebreak we store it in the $questions array @@ -678,7 +698,7 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) $questions[$row['sort']]['display'] = $row['display']; $questions[$row['sort']]['type'] = $row['type']; $questions[$row['sort']]['options'][$row['question_option_id']] = $row['option_text']; - $questions[$row['sort']]['maximum_score'] = $row['max_value']; + $questions[$row['sort']]['maximum_score'] = $row['max_value']; } // if the type is a pagebreak we are finished loading the questions for this page else { @@ -688,86 +708,86 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) } } } - elseif ($survey_data['survey_type'] === '1') - { - $my_survey_id = Database :: escape_string($survey_invitation['survey_id']); - $current_user = Database :: escape_string($survey_invitation['user']); - - if (isset ($_POST['personality']) ) + elseif ($survey_data['survey_type']==='1') + { + $my_survey_id=Database::escape_string($survey_invitation['survey_id']); + $current_user = Database::escape_string($survey_invitation['user']); + + if (isset($_POST['personality'])) { // Compute the results to get the 3 groups nearest to the user's personality - if ($shuffle == '') - $order = 'BY sort ASC '; + if ($shuffle=='') + $order = 'BY sort ASC '; else $order = $shuffle; - - $answer_list = array (); + + $answer_list=array(); // get current user results - $results = array (); + $results=array(); $sql = "SELECT survey_group_pri, user, SUM(value) as value FROM $table_survey_answer as survey_answer INNER JOIN $table_survey_question as survey_question ON (survey_question.question_id = survey_answer.question_id) - WHERE survey_answer.survey_id='" . $my_survey_id . "' AND - survey_answer.user='" . $current_user . "' + WHERE survey_answer.survey_id='".$my_survey_id."' AND + survey_answer.user='".$current_user."' GROUP BY survey_group_pri ORDER BY survey_group_pri - "; - + "; + $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = Database :: fetch_array($result)) { - $answer_list['value'] = $row['value']; - $answer_list['group'] = $row['survey_group_pri']; - $results[] = $answer_list; + $answer_list['value']=$row['value']; + $answer_list['group']=$row['survey_group_pri']; + $results[]=$answer_list; } - + //echo "
";print_r($results); echo "
"; - + // get the total score for each group of questions - $totals = array (); + $totals=array(); $sql = "SELECT SUM(temp.value) as value, temp.survey_group_pri FROM - (SELECT MAX(value) as value, survey_group_pri, survey_question.question_id - FROM $table_survey_question as survey_question - INNER JOIN $table_survey_question_option as survey_question_option - ON (survey_question.question_id = survey_question_option.question_id) - WHERE survey_question.survey_id='" . $my_survey_id . "' AND survey_group_sec1='0' AND survey_group_sec2='0' - GROUP BY survey_group_pri, survey_question.question_id) as temp - GROUP BY temp.survey_group_pri - ORDER BY temp.survey_group_pri"; - + (SELECT MAX(value) as value, survey_group_pri, survey_question.question_id + FROM $table_survey_question as survey_question + INNER JOIN $table_survey_question_option as survey_question_option + ON (survey_question.question_id = survey_question_option.question_id) + WHERE survey_question.survey_id='".$my_survey_id."' AND survey_group_sec1='0' AND survey_group_sec2='0' + GROUP BY survey_group_pri, survey_question.question_id) as temp + GROUP BY temp.survey_group_pri + ORDER BY temp.survey_group_pri"; + $result = api_sql_query($sql, __FILE__, __LINE__); - while ($row = Database :: fetch_array($result)) - { - $list['value'] = $row['value']; - $list['group'] = $row['survey_group_pri']; - $totals[] = $list; + while ($row = Database::fetch_array($result)) + { + $list['value']=$row['value']; + $list['group']=$row['survey_group_pri']; + $totals[]=$list; } //echo '
'; print_r($totals);
-
-			$final_results = array ();
-
-			//get a percentage score for each group
+			
+			$final_results=array();
+			
+            //get a percentage score for each group
 			for ($i = 0; $i < count($totals); $i++) {
 				for ($j = 0; $j < count($results); $j++) {
 					if ($totals[$i]['group'] == $results[$j]['group']) {
-						$group = $totals[$i]['group'];
-						$porcen = ($results[$j]['value'] / $totals[$i]['value']);
-						$final_results[$group] = $porcen;
-					}
-				}
+						$group=$totals[$i]['group'];
+						$porcen=($results[$j]['value'] / $totals[$i]['value'] );
+						$final_results[$group]=$porcen;
+					}					
+				}				
 			}
-
+							
 			// sort the results by score (getting a list of group IDs by score into $groups)
 			arsort($final_results);
-			$groups = array_keys($final_results);
+			$groups=array_keys($final_results);
 			/*
-			echo '
';
+            echo '
';
 			echo 'Group id =>  %';
 			echo "
"; print_r($final_results); - echo '
'; - */ - $result = array (); + echo '
'; + */ + $result=array(); $count_result=0; foreach ($final_results as $key => $sub_result) { $result[] = array ( @@ -776,7 +796,7 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) ); $count_result++; } - + /* //i.e 70% - 70% -70% 70% $equal_count =3 @@ -815,15 +835,15 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) $group_cant=-1; } */ - - //i.e 70% - 70% -70% 70% $equal_count =3 + //i.e 70% - 70% -70% 70% $equal_count =3 + $i = 0; $group_cant = 0; - $equal_count = 0; - // this is the case if the user does not select any question + $equal_count = 0; + // this is the case if the user does not select any question if ($count_result>0) - { + { // Count the number of scores equal to the first while (1) { @@ -845,13 +865,13 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) } //echo '
';
 			//print_r($result);
-			
-			// if we have only 3 or less equal scores (i.e. 0, 1 or 2 equalities), then we can use the three first groups
-			if ($equal_count < 4) 
+
+            // if we have only 3 or less equal scores (i.e. 0,1 or 2 equalities), then we can use the three first groups
+			if ($equal_count<4)
 			{
 				//if there is one or less score equalities
 				if ($equal_count === 0 || $equal_count === 1) 
-				{
+					{
 					//i.e 70% - 70% -60% - 60%  $equal_count = 1 we only get the first 2 options	
 					if (($result[0]['value'] == $result[1]['value']) && ($result[2]['value'] == $result[3]['value'])) 
 					{
@@ -859,138 +879,138 @@ if (isset ($_GET['show']) || isset ($_POST['personality']))
 					}
 					//i.e 70% - 70% -0% - 0% 	-	$equal_count = 0 we only get the first 2 options	
 					/*elseif (($result[0]['value'] == $result[1]['value']) && ($result[1]['value'] != $result[2]['value']) ) {
-						$group_cant = 0;
+						$group_cant=0;			
 					}*/
 					/*
 					//i.e 70% - 70% -60% - 60%  $equal_count = 0 we only get the first 2 options	
-					elseif (($result[0]['value'] == $result[1]['value']) && ($result[2]['value'] == $result[3]['value'])) 
+					elseif ( ($result[0]['value']  == $result[1]['value'])  &&  ($result[2]['value'] == $result[3]['value']) )
 					{
-						$group_cant = 0;
+						$group_cant=0;				
 					}*/
 					//i.e. 80% - 70% - 70% - 70%
 					elseif (($result[0]['value'] != $result[1]['value']) && ($result[1]['value'] == $result[2]['value']) && ($result[2]['value'] == $result[3]['value'])) {
 						$group_cant = 0;
-					} 
-					else 
+					}
+					else
 					{
 					//i.e. 80% - 70% - 70% - 50
 					//i.e. 80% - 80% - 70% - 50
 						 	 
 						// by default we choose the highest 3
-						$group_cant = 2;
-					}
-				}
-				else 
+						$group_cant=2;				
+					}		
+				} 
+				else
 				{
 					//if there are two score equalities
-					$group_cant = $equal_count;
+					$group_cant=$equal_count;
 				}
-				
+
 				//@todo
 				// conditional_status 
 				// 0 no determinado 
 				// 1 determinado 
 				// 2 un solo valor
 				// 3 valores iguales
-				
-				if ($group_cant > 0) 
-				{
+								
+				if ($group_cant>0)
+				{				
 					//echo '$equal_count'.$group_cant;
 					// we only get highest 3			
-					$secondary = '';
-					$combi = '';
-
+					$secondary ='';		
+					$combi='';
+					
 					for ($i = 0; $i <= $group_cant; $i++) {
-						$group1 = $groups[$i];
-						$group2 = $groups[$i +1];
+						$group1=$groups[$i];
+						$group2=$groups[$i+1];
 						// here we made all the posibilities with the 3 groups
 						if ($group_cant == 2 && $i == $group_cant) {
-							$group2 = $groups[0];
+							$group2=$groups[0];				
 							$secondary .= " OR ( survey_group_sec1 = '$group1' AND  survey_group_sec2 = '$group2') ";
 							$secondary .= " OR ( survey_group_sec1 = '$group2' AND survey_group_sec2 = '$group1' ) ";
-							$combi .= $group1 . ' - ' . $group2 . " or " . $group2 . ' - ' . $group1 . "
"; + $combi.= $group1.' - '.$group2." or ".$group2.' - '.$group1."
"; } else { if ($i != 0) { $secondary .= " OR ( survey_group_sec1 = '$group1' AND survey_group_sec2 = '$group2') "; $secondary .= " OR ( survey_group_sec1 = '$group2' AND survey_group_sec2 = '$group1' ) "; - $combi .= $group1 . ' - ' . $group2 . " or " . $group2 . ' - ' . $group1 . "
"; + $combi.= $group1.' - '.$group2." or ".$group2.' - '.$group1."
"; } else { $secondary .= " ( survey_group_sec1 = '$group1' AND survey_group_sec2 = '$group2') "; $secondary .= " OR ( survey_group_sec1 = '$group2' AND survey_group_sec2 = '$group1' ) "; - $combi .= $group1 . ' - ' . $group2 . " or " . $group2 . ' - ' . $group1 . "
"; + $combi.= $group1.' - '.$group2." or ".$group2.' - '.$group1."
"; } - } + } } /* - echo '
';
-					echo "Pair of Groups 

"; + echo '
';
+                    echo "Pair of Groups 

"; echo $combi; echo '
'; */ - // create the new select with the questions from the secondary phase + // create the new select with the questions from the secondary phase if (empty($_SESSION['page_questions_sec']) && !is_array($_SESSION['page_questions_sec']) && count($_SESSION['page_questions_sec']==0)) { - - $sql = "SELECT * FROM $table_survey_question - WHERE survey_id = '" . $my_survey_id . "' - AND ($secondary ) - ORDER BY sort ASC"; - $result = api_sql_query($sql, __FILE__, __LINE__); - $counter = 0; - while ($row = Database :: fetch_array($result, 'ASSOC')) - { - if ($survey_data['one_question_per_page'] == 1) - { - $paged_questions_sec[$counter][] = $row['question_id']; - $counter++; - } - else - if ($row['type'] == 'pagebreak') - { - $counter++; + + $sql = "SELECT * FROM $table_survey_question + WHERE survey_id = '".$my_survey_id."' + AND ($secondary ) + ORDER BY sort ASC"; + $result = api_sql_query($sql, __FILE__, __LINE__); + $counter=0; + while ($row = Database::fetch_array($result,'ASSOC')) + { + if ($survey_data['one_question_per_page']==1) + { + $paged_questions_sec[$counter][] = $row['question_id']; + $counter++; + } + else + if($row['type'] == 'pagebreak') + { + $counter++; } else { - // ids from question of the current survey - $paged_questions_sec[$counter][] = $row['question_id']; - } - } - $_SESSION['paged_questions_sec'] = $paged_questions_sec; - } - else - { - $paged_questions_sec = $_SESSION['paged_questions_sec']; - } + // ids from question of the current survey + $paged_questions_sec[$counter][] = $row['question_id']; + } + } + $_SESSION['paged_questions_sec'] = $paged_questions_sec; + } + else + { + $paged_questions_sec = $_SESSION['paged_questions_sec']; + } //print_r($paged_questions_sec); - - $paged_questions = $_SESSION['paged_questions']; //for the sake of pages counting - //$paged_questions = $paged_questions_sec; //for the sake of pages counting coming up at display time... - - if ($shuffle == '') - $shuffle = ' BY survey_question.sort, survey_question_option.sort ASC '; + $paged_questions = $_SESSION['paged_questions']; //for the sake of pages counting + //$paged_questions = $paged_questions_sec; //for the sake of pages counting coming up at display time... + + if ($shuffle=='') + $shuffle=' BY survey_question.sort, survey_question_option.sort ASC '; + //$val=0; //if ($survey_data['one_question_per_page']==0) //{ - $val = (int) $_POST['personality']; + $val=(int)$_POST['personality']; //} //echo '
';print_r($paged_questions_sec);echo '
'; if (is_array($paged_questions_sec)) { $sql = "SELECT survey_question.survey_group_sec1, survey_question.survey_group_sec2, survey_question.survey_group_pri, - survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value, - survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort - FROM $table_survey_question survey_question - LEFT JOIN $table_survey_question_option survey_question_option - ON survey_question.question_id = survey_question_option.question_id - WHERE survey_question.survey_id = '" . $my_survey_id . "' - AND survey_question.question_id IN (" . implode(',', $paged_questions_sec[$val]) . ") - ORDER $shuffle "; - + survey_question.question_id, survey_question.survey_id, survey_question.survey_question, survey_question.display, survey_question.sort, survey_question.type, survey_question.max_value, + survey_question_option.question_option_id, survey_question_option.option_text, survey_question_option.sort as option_sort + FROM $table_survey_question survey_question + LEFT JOIN $table_survey_question_option survey_question_option + ON survey_question.question_id = survey_question_option.question_id + WHERE survey_question.survey_id = '".$my_survey_id."' + AND survey_question.question_id IN (".implode(',',$paged_questions_sec[$val]).") + ORDER $shuffle "; + $result = api_sql_query($sql, __FILE__, __LINE__); - $question_counter_max = Database :: num_rows($result); + $question_counter_max = Database::num_rows($result); $counter = 0; - $limit = 0; - $questions = array (); - while ($row = Database :: fetch_array($result, 'ASSOC')) + $limit=0; + $questions = array(); + while ($row = Database::fetch_array($result,'ASSOC')) { // if the type is not a pagebreak we store it in the $questions array if ($row['type'] <> 'pagebreak') { @@ -1007,7 +1027,7 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) $questions[$row['sort']]['survey_group_pri'] = $row['survey_group_pri']; } // if the type is a pagebreak we are finished loading the questions for this page - else + else { break; } @@ -1015,12 +1035,12 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) } } else - { + { echo get_lang('SurveyUndetermined'); } - - } - else + + } + else { echo get_lang('SurveyUndetermined'); } @@ -1035,56 +1055,56 @@ if (isset ($_GET['show']) || isset ($_POST['personality'])) //We need this variable only in the 2nd set of questions when personality is set. unset($_SESSION['page_questions_sec']); $paged_questions_sec=array(); - + // Only the questions from the basic group //the 50 questions A B C D E F G - $order_sql = $shuffle; - if ($shuffle == '') - $order_sql = ' BY question_id '; - - if (empty ($_SESSION['paged_questions'])) - { - $sql = "SELECT * FROM $table_survey_question - WHERE survey_id = '" . Database :: escape_string($survey_invitation['survey_id']) . "' - AND survey_group_sec1='0' AND survey_group_sec2='0' - ORDER " . $order_sql . " "; - //echo "
";echo "
"; - $result = api_sql_query($sql, __FILE__, __LINE__); - $counter = 0; - while ($row = Database :: fetch_array($result, 'ASSOC')) - { - if ($survey_data['one_question_per_page'] == 1) - { - $paged_questions[$counter][] = $row['question_id']; - $counter++; + $order_sql= $shuffle; + if ($shuffle=='') + $order_sql=' BY question_id '; + + if(empty($_SESSION['paged_questions'])) + { + $sql = "SELECT * FROM $table_survey_question + WHERE survey_id = '".Database::escape_string($survey_invitation['survey_id'])."' + AND survey_group_sec1='0' AND survey_group_sec2='0' + ORDER ".$order_sql." "; + //echo "
";echo "
"; + $result = api_sql_query($sql, __FILE__, __LINE__); + $counter=0; + while ($row = Database::fetch_array($result,'ASSOC')) + { + if ($survey_data['one_question_per_page']==1) + { + $paged_questions[$counter][] = $row['question_id']; + $counter++; } else { if ($row['type'] == 'pagebreak') { - $counter++; + $counter++; } else { - // ids from question of the current survey - $paged_questions[$counter][] = $row['question_id']; - } - } - } - $_SESSION['paged_questions'] = $paged_questions; - } - else - { - $paged_questions = $_SESSION['paged_questions']; - } + // ids from question of the current survey + $paged_questions[$counter][] = $row['question_id']; + } + } + } + $_SESSION['paged_questions'] = $paged_questions; + } + else + { + $paged_questions = $_SESSION['paged_questions']; + } //print_r($paged_questions); - //print_r($paged_questions); + //print_r($paged_questions); //if (key_exists($_GET['show'],$paged_questions)) //{ - $order_sql = $shuffle; - if ($shuffle == '') - $order_sql = ' BY survey_question.sort, survey_question_option.sort ASC '; - + $order_sql= $shuffle; + if ($shuffle=='') + $order_sql=' BY survey_question.sort, survey_question_option.sort ASC '; + //$val=0; //if ($survey_data['one_question_per_page']==0) //{ - $val = $_GET['show']; + $val=$_GET['show']; //} //echo '
';print_r($paged_questions);echo $val;
 			
@@ -1104,10 +1124,10 @@ if (isset ($_GET['show']) || isset ($_POST['personality']))
 							WHERE survey_question.survey_id = '" . Database :: escape_string($survey_invitation['survey_id']) . "'
 							AND survey_question.question_id IN (" .$imploded. ")  
 							ORDER $order_sql ";	
-					 $result = api_sql_query($sql, __FILE__, __LINE__);
+					$result = api_sql_query($sql, __FILE__, __LINE__);
 					$question_counter_max = Database :: num_rows($result);				
 				}
-			}	
+			}
 			if (!is_null($result))
 			{
 				$counter = 0;
@@ -1138,60 +1158,60 @@ if (isset ($_GET['show']) || isset ($_POST['personality']))
 				}
 			}
 		}
-	} 
-	else //in case it's another type than 0 or 1
-	{
-		echo get_lang('ErrorSurveyTypeUnknown');
 	}
+	else //in case it's another type than 0 or 1
+    {
+        echo get_lang('ErrorSurveyTypeUnknown');
+    }
 }
 
 // selecting the maximum number of pages
-$sql = "SELECT * FROM $table_survey_question WHERE type='" . Database :: escape_string('pagebreak') . "' AND survey_id='" . Database :: escape_string($survey_invitation['survey_id']) . "'";
+$sql = "SELECT * FROM $table_survey_question WHERE type='".Database::escape_string('pagebreak')."' AND survey_id='".Database::escape_string($survey_invitation['survey_id'])."'";
 $result = api_sql_query($sql, __FILE__, __LINE__);
-$numberofpages = Database :: num_rows($result) + 1;
+$numberofpages = Database::num_rows($result) + 1;
 
 // Displaying the form with the questions
-if (isset ($_GET['show'])) 
+if (isset($_GET['show']))
 {
-	$show = (int) $_GET['show'] + 1;
-} 
-else 
+	$show = (int)$_GET['show'] + 1;
+}
+else
 {
 	$show = 0;
 }
 
 // Displaying the form with the questions
-if (isset ($_POST['personality'])) 
+if (isset($_POST['personality']))
 {
-	$personality = (int) $_POST['personality'] + 1;
-} 
-else 
+	$personality = (int)$_POST['personality'] + 1;
+}
+else
 {
-	$personality = 0;
+	$personality= 0;
 }
 
 // Displaying the form with the questions
-$g_c  = (isset ($_GET['course']) ? Security :: remove_XSS($_GET['course']) : '');
-$g_ic = (isset ($_GET['invitationcode']) ? Security :: remove_XSS($_GET['invitationcode']) : '');
-$g_cr = (isset ($_GET['cidReq']) ? Security :: remove_XSS($_GET['cidReq']) : '');
-$p_l  = (isset ($_POST['language']) ? Security :: remove_XSS($_POST['language']) : '');
+$g_c = (isset($_GET['course'])?Security::remove_XSS($_GET['course']):'');
+$g_ic = (isset($_GET['invitationcode'])?Security::remove_XSS($_GET['invitationcode']):'');
+$g_cr = (isset($_GET['cidReq'])?Security::remove_XSS($_GET['cidReq']):'');
+$p_l = (isset($_POST['language'])?Security::remove_XSS($_POST['language']):'');
 
 $add_parameters=isset($_GET['user_id']) ? 'user_id='.$_GET['user_id'].'&': '';
 
 echo '
'; -echo ''; +echo ''; -if (isset ($questions) && is_array($questions)) +if(isset($questions) && is_array($questions)) { - foreach ($questions as $key => $question) + foreach ($questions as $key=>$question) { $display = new $question['type']; $display->render_question($question); } } -if ($survey_data['survey_type'] === '0') -{ +if ($survey_data['survey_type']==='0') +{ if ($survey_data['show_form_profile']==0) { // the normal survey as always @@ -1200,7 +1220,7 @@ if ($survey_data['survey_type'] === '0') //echo ''; echo ''; } - + if ($show >= $numberofpages && $_GET['show']) { //echo ''; echo ''; @@ -1210,22 +1230,22 @@ if ($survey_data['survey_type'] === '0') { // the normal survey as always but with the form profile if (isset ($_GET['show'])) - { - $numberofpages = count($paged_questions); + { + $numberofpages=count($paged_questions); if (($show < $numberofpages) || !$_GET['show']) //$show = $_GET['show']+1 { //echo ''; echo ''; - } - - if ($show >= $numberofpages && $_GET['show']) - { + } + + if ($show >= $numberofpages && $_GET['show'] ) + { //echo ''; echo ''; - } + } } } - + } elseif ($survey_data['survey_type'] === '1') //conditional/personality-test type survey { @@ -1252,7 +1272,7 @@ elseif ($survey_data['survey_type'] === '1') //conditional/personality-test type echo 'num pages:'.$numberofpages;echo "
"; echo 'show :'.$show;echo "
"; echo 'personality :'.$personality; - echo "
"; + echo "
"; */ //echo $show.' / '.$numberofpages."
"; if ($personality ==0) @@ -1262,32 +1282,32 @@ elseif ($survey_data['survey_type'] === '1') //conditional/personality-test type echo ''; if ($survey_data['one_question_per_page']==0) { - if ($personality >= 0 ) + if ($personality >= 0 ) { echo ''; - } + } } else { - if ($personality > 0 ) + if ($personality > 0 ) { echo ''; - } + } } if ($numberofpages == $show) echo ''; } - if ($show > $numberofpages && $_GET['show'] && $personality==0) + if ($show > $numberofpages && $_GET['show'] && $personality==0) { echo ''; //$numberofpages = count($paged_questions); - //echo $numberofpages = count($paged_questions_sec); + //echo $numberofpages = count($paged_questions_sec); //echo $personality.' / '.$numberofpages; - //echo "
"; + //echo "
"; //if ($personality > count($paged_questions_sec) - 1) - //|| $numberofpages == $show +$personality +1 + //|| $numberofpages == $show +$personality +1 //echo $show + $personality; //echo $numberofpages; } @@ -1295,33 +1315,33 @@ elseif ($survey_data['survey_type'] === '1') //conditional/personality-test type { if ($survey_data['one_question_per_page']==1) { - - if ($show >= $numberofpages ) - { + + if ($show >= $numberofpages) + { //echo ''; echo ''; - } - else + } + else { echo ''; //echo ''; echo ''; - } - } + } + } else { // if the personality test hidden input was set. //echo ''; echo ''; - } - } + } + } } // this is the case when the show_profile_form is true but there are not form_fields - elseif ($survey_data['form_fields'] == '') - { + elseif ($survey_data['form_fields'] == '') + { //echo ''; echo ''; - } + } elseif(!is_array($user_data)) { // if the user is not registered in the platform we do not show the form to update his information //echo ''; diff --git a/main/survey/survey.lib.php b/main/survey/survey.lib.php index 7fd1a8d7f7..fa2dfa5f35 100644 --- a/main/survey/survey.lib.php +++ b/main/survey/survey.lib.php @@ -118,11 +118,11 @@ class survey_manager /*if ($values['survey_share']['survey_share'] !== '0') { $shared_survey_id = survey_manager::store_shared_survey($values); - }*/ + }*/ $shared_survey_id=0; - + if (!$values['survey_id'] OR !is_numeric($values['survey_id'])) - { + { // check if the code doesn't soon exists in this language $sql = 'SELECT 1 FROM '.$table_survey.' WHERE code="'.Database::escape_string($values['survey_code']).'" AND lang="'.Database::escape_string($values['survey_language']).'"'; $rs = api_sql_query($sql, __FILE__, __LINE__); @@ -138,21 +138,21 @@ class survey_manager { $values['anonymous']=0; } - + $additional['columns'] = ''; $additional['values'] = ''; - + if ($values['anonymous']==0) { // input_name_list $additional['columns'] .= ', show_form_profile'; $additional['values'] .= ",'".Database::escape_string($values['show_form_profile'])."'"; - + if ($values['show_form_profile']==1) { // input_name_list - $fields=explode(',',$values['input_name_list']); - $field_values=''; + $fields=explode(',',$values['input_name_list']); + $field_values=''; foreach ($fields as $field ) { if ($field!='') @@ -160,15 +160,15 @@ class survey_manager if ($values[$field]=='') $values[$field]=0; $field_values.= $field.':'.$values[$field].'@'; - } - } + } + } $additional['columns'] .= ', form_fields'; $additional['values'] .= ",'".Database::escape_string($field_values)."'"; } else { $additional['columns'] .= ', form_fields'; - $additional['values'] .= ",''"; + $additional['values'] .= ",''"; } } else @@ -176,11 +176,11 @@ class survey_manager // input_name_list $additional['columns'] .= ', show_form_profile'; $additional['values'] .= ",'0'"; - + $additional['columns'] .= ', form_fields'; - $additional['values'] .= ",''"; + $additional['values'] .= ",''"; } - + if($values['survey_type']==1) { $additional['columns'] .= ', survey_type'; @@ -194,7 +194,7 @@ class survey_manager $additional['columns'] .= ', parent_id'; $additional['values'] .= ",'".Database::escape_string($values['parent_id'])."'"; - + // logic for versioning surveys if(!empty($values['parent_id'])) { @@ -208,25 +208,25 @@ class survey_manager if(empty($getversion['survey_version'])) { $additional['values'] .= ",'".++$getversion['survey_version']."'"; - } - else + } + else { - $additional['values'] .= ",'".$getversion['survey_version'].".1'"; + $additional['values'] .= ",'".$getversion['survey_version'].".1'"; } } - else - { - $row = Database::fetch_array($rs,ASSOC); + else + { + $row = Database::fetch_array($rs,ASSOC); $pos = api_strpos($row['survey_version']); if($pos===false) - { + { //$new_version= substr($row['survey_version'],$pos, count()) - $row['survey_version'] = $row['survey_version'] + 1; + $row['survey_version'] = $row['survey_version'] + 1; $additional['values'] .= ",'".$row['survey_version']."'"; - } - else + } + else { - $getlast = api_split('\.',$row['survey_version']); + $getlast = api_split('\.',$row['survey_version']); $lastversion = array_pop($getlast); $lastversion = $lastversion + 1; $add=implode('.',$getlast); @@ -268,8 +268,8 @@ class survey_manager $return['id'] = $survey_id; } else - { - + { + // check if the code doesn't soon exists in this language $sql = 'SELECT 1 FROM '.$table_survey.' WHERE code="'.Database::escape_string($values['survey_code']).'" AND lang="'.Database::escape_string($values['survey_language']).'" AND survey_id!='.intval($values['survey_id']); $rs = api_sql_query($sql, __FILE__, __LINE__); @@ -280,32 +280,32 @@ class survey_manager $return['id'] = isset($values['survey_id']) ? $values['survey_id'] : 0; return $return; } - + if ($values['anonymous']=='') { $values['anonymous']=0; } - + $additionalsets = ", shuffle = '".Database::escape_string($values['shuffle'])."'"; $additionalsets .= ", one_question_per_page = '".Database::escape_string($values['one_question_per_page'])."'"; - + if ($values['anonymous']==0) { - + $additionalsets .= ", show_form_profile = '".Database::escape_string($values['show_form_profile'])."'"; if ($values['show_form_profile']==1) { - $fields=explode(',',$values['input_name_list']); + $fields=explode(',',$values['input_name_list']); $field_values=''; foreach ($fields as $field ) - { + { if ($field!='') { if ($values[$field]=='') $values[$field]=0; $field_values.= $field.':'.$values[$field].'@'; - } - } + } + } $additionalsets .= ", form_fields = '".Database::escape_string($field_values)."'"; } else @@ -318,8 +318,8 @@ class survey_manager $additionalsets .= ", show_form_profile = '0'"; $additionalsets .= ", form_fields = '' "; } - - + + $sql = "UPDATE $table_survey SET title = '".Database::escape_string($values['survey_title'])."', subtitle = '".Database::escape_string($values['survey_subtitle'])."', @@ -419,7 +419,7 @@ class survey_manager // deleting the survey $sql = "DELETE from $table_survey WHERE survey_id='".Database::escape_string($survey_id)."'"; $res = api_sql_query($sql, __FILE__, __LINE__); - + // deleting groups of this survey $sql = "DELETE from $table_survey_question_group WHERE survey_id='".Database::escape_string($survey_id)."'"; $res = api_sql_query($sql, __FILE__, __LINE__); @@ -429,7 +429,7 @@ class survey_manager return true; } - + function copy_survey($parent_survey, $new_survey_id) { // Database table definitions @@ -440,12 +440,12 @@ class survey_manager $parent_survey = Database::escape_string($parent_survey); //get groups $sql = "SELECT * from $table_survey_question_group WHERE survey_id='".$parent_survey."'"; - $res = api_sql_query($sql, __FILE__, __LINE__); + $res = api_sql_query($sql, __FILE__, __LINE__); if(Database::num_rows($res)===0) return true; - + while($row = Database::fetch_array($res,ASSOC)){ $sql1 = 'INSERT INTO '.$table_survey_question_group.' (name,description,survey_id) VALUES (\''.Database::escape_string($row['name']).'\',\''.Database::escape_string($row['description']).'\',\''.$new_survey_id.'\')'; - $res1 = api_sql_query($sql1, __FILE__, __LINE__); + $res1 = api_sql_query($sql1, __FILE__, __LINE__); $group_id[$row['id']] = Database::insert_id(); } @@ -457,20 +457,20 @@ class survey_manager '(\''.$new_survey_id.'\',\''.Database::escape_string($row['survey_question']).'\',\''.Database::escape_string($row['survey_comment']).'\',\''.$row['type'].'\',\''.$row['display'].'\',\''.$row['sort'].'\',\''.$row['shared_question_id'].'\',\''.$row['max_value']. '\',\''.$group_id[$row['survey_group_pri']].'\',\''.$group_id[$row['survey_group_sec1']].'\',\''.$group_id[$row['survey_group_sec2']].'\')'; $res2 = api_sql_query($sql2, __FILE__, __LINE__); - $question_id[$row['question_id']] = Database::insert_id(); + $question_id[$row['question_id']] = Database::insert_id(); } - + //get questions options $sql = "SELECT * FROM $table_survey_options WHERE survey_id='".$parent_survey."'"; $res = api_sql_query($sql, __FILE__, __LINE__); while($row = Database::fetch_array($res,ASSOC)){ $sql3 = 'INSERT INTO '.$table_survey_options.' (question_id,survey_id,option_text,sort,value) VALUES ('. "'".$question_id[$row['question_id']]."','".$new_survey_id."','".Database::escape_string($row['option_text'])."','".$row['sort']."','".$row['value']."')"; - $res3 = api_sql_query($sql3, __FILE__, __LINE__); + $res3 = api_sql_query($sql3, __FILE__, __LINE__); } return true; - } - + } + /** * This function duplicates a survey (and also all the question in that survey * @@ -486,7 +486,7 @@ class survey_manager $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION); $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); $table_survey = Database :: get_course_table(TABLE_SURVEY); - + $datas = survey_manager::get_survey($survey_id); $session_where=''; if (api_get_session_id()!=0) @@ -496,10 +496,10 @@ class survey_manager $sql = 'DELETE FROM '.$table_survey_invitation.' WHERE survey_code = "'.Database::escape_string($datas['code']).'" '.$session_where.' '; api_sql_query($sql, __FILE__, __LINE__); - + $sql = 'DELETE FROM '.$table_survey_answer.' WHERE survey_id='.intval($survey_id); api_sql_query($sql, __FILE__, __LINE__); - + $sql = 'UPDATE '.$table_survey.' SET invited=0, answered=0 WHERE survey_id='.intval($survey_id); api_sql_query($sql, __FILE__, __LINE__); @@ -585,7 +585,7 @@ class survey_manager $icon_question = array ( 'yesno' => 'yesno.gif', - 'personality' => 'yesno.gif', + 'personality' => 'yesno.gif', 'multiplechoice' => 'mcua.gif', 'multipleresponse' => 'mcma.gif', 'open' => 'open_answer.gif', @@ -639,19 +639,19 @@ class survey_manager $return['horizontalvertical'] = $row['display']; $return['shared_question_id'] = $row['shared_question_id']; $return['maximum_score'] = $row['max_value']; - + if($row['survey_group_pri']!=0) { $return['assigned'] = $row['survey_group_pri']; $return['choose'] = 1; - } - else + } + else { $return['assigned1'] = $row['survey_group_sec1']; $return['assigned2'] = $row['survey_group_sec2']; $return['choose'] = 2; } - + // getting the information of the question options $sql = "SELECT * FROM $table_survey_question_option WHERE question_id='".Database::escape_string($question_id)."' ORDER BY `sort` "; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -659,9 +659,9 @@ class survey_manager { /** @todo this should be renamed to options instead of answers */ $return['answers'][] = $row['option_text']; - + $return['values'][] = $row['value']; - + /** @todo this can be done more elegantly (used in reporting) */ $return['answersid'][] = $row['question_option_id']; } @@ -706,7 +706,7 @@ class survey_manager $result = api_sql_query($sql, __FILE__, __LINE__); while ($row = Database::fetch_array($result,'ASSOC')) { - $return[$row['question_id']]['answers'][] = $row['option_text']; + $return[$row['question_id']]['answers'][] = $row['option_text']; } return $return; @@ -721,67 +721,67 @@ class survey_manager * @author Patrick Cool , Ghent University * @version January 2007 */ - + function save_question($form_content) - { + { global $survey_data; - + if (strlen($form_content['question'])>1) - { //checks lenght of the question - $empty_answer=false; - + { //checks lenght of the question + $empty_answer=false; + if ($survey_data['survey_type'] == 1) { if (empty($form_content['choose'])) { - $return_message = 'PleaseChooseACondition'; - return $return_message; + $return_message = 'PleaseChooseACondition'; + return $return_message; } - + if (($form_content['choose']==2)&&($form_content['assigned1']==$form_content['assigned2'])) { - $return_message = 'ChooseDifferentCategories'; - return $return_message; - } + $return_message = 'ChooseDifferentCategories'; + return $return_message; + } } - + if ($form_content['type'] != 'percentage') { for($i=0;$i 0) { $shared_question_id = survey_manager::save_shared_question($form_content, $survey_data); $form_content['shared_question_id'] = $shared_question_id; - } - + } + // storing a new question if ($form_content['question_id'] == '' OR !is_numeric($form_content['question_id'])) { @@ -790,22 +790,22 @@ class survey_manager $result = api_sql_query($sql, __FILE__, __LINE__); $row = Database::fetch_array($result,'ASSOC'); $max_sort = $row['max_sort']; - + //some variables defined for survey-test type $additional['column'] = ''; $additional['value'] = ''; - + if($_POST['choose']==1) { - $additional['column'] = ',survey_group_pri'; - $additional['value'] = ",'".Database::escape_string($_POST['assigned'])."'"; - } - elseif($_POST['choose']==2) + $additional['column'] = ',survey_group_pri'; + $additional['value'] = ",'".Database::escape_string($_POST['assigned'])."'"; + } + elseif($_POST['choose']==2) { - $additional['column'] = ',survey_group_sec1, survey_group_sec2'; - $additional['value'] = ",'".Database::escape_string($_POST['assigned1'])."'".",'".Database::escape_string($_POST['assigned2'])."'"; + $additional['column'] = ',survey_group_sec1, survey_group_sec2'; + $additional['value'] = ",'".Database::escape_string($_POST['assigned1'])."'".",'".Database::escape_string($_POST['assigned2'])."'"; } - + // adding the question to the survey_question table $sql = "INSERT INTO $tbl_survey_question (survey_id,survey_question,survey_question_comment,type,display, sort, shared_question_id, max_value".$additional['column'].") VALUES ( '".Database::escape_string($form_content['survey_id'])."', @@ -827,16 +827,16 @@ class survey_manager else { $additionalsets = ''; - + if($_POST['choose']==1) { - $additionalsets = ',survey_group_pri = \''.Database::escape_string($_POST['assigned']).'\', survey_group_sec1 = \'0\', survey_group_sec2 = \'0\' '; - } - elseif($_POST['choose']==2) + $additionalsets = ',survey_group_pri = \''.Database::escape_string($_POST['assigned']).'\', survey_group_sec1 = \'0\', survey_group_sec2 = \'0\' '; + } + elseif($_POST['choose']==2) { - $additionalsets = ',survey_group_pri = \'0\', survey_group_sec1 = \''.Database::escape_string($_POST['assigned1']).'\', survey_group_sec2 = \''.Database::escape_string($_POST['assigned2']).'\' '; + $additionalsets = ',survey_group_pri = \'0\', survey_group_sec1 = \''.Database::escape_string($_POST['assigned1']).'\', survey_group_sec2 = \''.Database::escape_string($_POST['assigned2']).'\' '; } - + $setadditionals = $additional['set'][1].$additional['set'][2].$additional['set'][3]; // adding the question to the survey_question table @@ -848,21 +848,21 @@ class survey_manager $additionalsets." WHERE question_id = '".Database::escape_string($form_content['question_id'])."'"; $result = api_sql_query($sql, __FILE__, __LINE__); - $return_message = 'QuestionUpdated'; - } + $return_message = 'QuestionUpdated'; + } // storing the options of the question $message_options=survey_manager::save_question_options($form_content, $survey_data); } else - { - $return_message='PleasFillAllAnswer'; - } + { + $return_message='PleasFillAllAnswer'; + } } else { - $return_message='PleaseEnterAQuestion'; + $return_message='PleaseEnterAQuestion'; } - return $return_message; + return $return_message; } /** @@ -879,10 +879,10 @@ class survey_manager function save_shared_question($form_content, $survey_data) { global $_course; - + // table definitions $tbl_survey_question = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY_QUESTION); - + // storing a new question if ($form_content['shared_question_id'] == '' OR !is_numeric($form_content['shared_question_id'])) { @@ -893,7 +893,7 @@ class survey_manager $result = api_sql_query($sql, __FILE__, __LINE__); $row = Database::fetch_array($result,'ASSOC'); $max_sort = $row['max_sort']; - + // adding the question to the survey_question table $sql = "INSERT INTO $tbl_survey_question (survey_id, survey_question, survey_question_comment, type, display, sort, code) VALUES ( '".Database::escape_string($survey_data['survey_share'])."', @@ -919,7 +919,7 @@ class survey_manager $result = api_sql_query($sql, __FILE__, __LINE__); $shared_question_id = $form_content['shared_question_id']; } - + return $shared_question_id; } @@ -972,7 +972,7 @@ class survey_manager $sql2 = "UPDATE $table_survey_question SET sort = '".Database::escape_string($question_sort_one)."' WHERE question_id='".Database::escape_string($question_id_two)."'"; $result = api_sql_query($sql2, __FILE__, __LINE__); } - + /** * This function deletes all the questions of a given survey @@ -996,7 +996,7 @@ class survey_manager // deleting the survey questions $sql = "DELETE from $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."'"; $res = api_sql_query($sql, __FILE__, __LINE__); - + // deleting all the options of the questions of the survey survey_manager::delete_all_survey_questions_options($survey_id, $shared); @@ -1029,7 +1029,7 @@ class survey_manager // deleting the survey questions $sql = "DELETE from $table_survey_question WHERE survey_id='".Database::escape_string($survey_id)."' AND question_id='".Database::escape_string($question_id)."'"; $res = api_sql_query($sql, __FILE__, __LINE__); - + // deleting the options of the question of the survey survey_manager::delete_survey_question_option($survey_id, $question_id, $shared); @@ -1087,8 +1087,8 @@ class survey_manager { $form_content['answers'][] = $i; } - } - + } + if (is_numeric($survey_data['survey_share']) AND $survey_data['survey_share'] <> 0) { survey_manager::save_shared_question_options($form_content, $survey_data); @@ -1106,7 +1106,7 @@ class survey_manager $counter=1; if(is_array($form_content['answers'])) - { + { //foreach ($form_content['answers'] as $key=>$answer) { for ($i=0;$i$answer) { $sql = "INSERT INTO $table_survey_question_option (question_id, survey_id, option_text, sort) VALUES ( @@ -1264,20 +1264,21 @@ class survey_manager // variable initialisation $return = array(); - + // getting the survey information $survey_data = survey_manager::get_survey($survey_id); if ($all_user_info) { - $sql = "SELECT DISTINCT answered_user.user as invited_user, user.firstname, user.lastname, user.user_id + $order_clause = api_sort_by_first_name() ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname'; + $sql = "SELECT DISTINCT answered_user.user as invited_user, user.firstname, user.lastname, user.user_id FROM $table_survey_answer answered_user LEFT JOIN $table_user as user ON answered_user.user = user.user_id - WHERE survey_id= '".Database::escape_string($survey_data['survey_id'])."' - ORDER BY user.lastname, user.firstname"; + WHERE survey_id= '".Database::escape_string($survey_data['survey_id'])."'". + $order_clause; } - else + else { $sql = "SELECT DISTINCT user FROM $table_survey_answer WHERE survey_id= '".Database::escape_string($survey_data['survey_id'])."'"; } @@ -1288,7 +1289,7 @@ class survey_manager { $return[] = $row; } - else + else { $return[] = $row['user']; } @@ -1299,16 +1300,6 @@ class survey_manager } - - - - - - - - - - class question { // the html code of the form @@ -1340,7 +1331,7 @@ class question } if ($_GET['action'] == 'edit') { $tool_name .= get_lang('EditQuestion'); - } + } if ($_GET['type'] == 'yesno') { $tool_name .= ': '.get_lang('YesNo'); @@ -1349,7 +1340,7 @@ class question } else { $tool_name .= ': '.get_lang(api_ucfirst(Security::remove_XSS($_GET['type']))); } - + $this->html .= '
'.$tool_name.'
'; $this->html .= ''; $this->html .= ' '; @@ -1385,30 +1376,30 @@ class question $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); $sql = 'SELECT id,name FROM '.$table_survey_question_group.' WHERE survey_id = '.(int)$_GET['survey_id'].' ORDER BY name'; $rs = api_sql_query($sql,__FILE__,__LINE__); - + while($row = Database::fetch_array($rs,NUM)) { $glist .= ''; } - + $grouplist = $grouplist1 = $grouplist2 = $glist; - + if(!empty($form_content['assigned'])) $grouplist = str_replace('
'; - + // The options $this->html .= '
'; $this->html .= '
'; @@ -1641,7 +1632,7 @@ class yesno extends question $this->html .= ' '; $this->html .= ' '; //$this->html .= ' '; - + $this->html .= ' '.api_return_html_area('answers[0]', stripslashes($form_content['answers'][0]), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).''; $this->html .= ' '; $this->html .= ' '; @@ -1670,7 +1661,7 @@ class yesno extends question { foreach ($form_content['options'] as $key=>$value) { - $this->html .= '
'; - + $this->html .= parent :: add_remove_buttons($form_content); - + } @@ -1802,18 +1793,18 @@ class personality extends question $this->html .= ' '; $this->html .= '  '; $this->html .= ' '; - $this->html .= ' html .= ' html .= 'checked="checked"'; } $this->html .= '/>'.get_lang('Horizontal').'
'; $this->html .= ' html .= 'checked="checked"'; - } - + + if ($form_content['horizontalvertical'] == 'vertical') + { + $this->html .= 'checked="checked"'; + } + $this->html .= ' />'.get_lang('Vertical').''; $this->html .= ' '; $this->html .= '  '; $this->html .= ' '; @@ -1826,18 +1817,18 @@ class personality extends question $this->html .= ' '.get_lang('AnswerOptions').''; $this->html .= ' '; $total_number_of_answers = count($form_content['answers']); - - + + $question_values=array(); - - // values of question options + + // values of question options foreach ($form_content['values'] as $key=>$value) { - $question_values [] = ''; + $question_values [] = ''; } - + $count=0; - + foreach ($form_content['answers'] as $key=>$value) { $this->html .= ' '; @@ -1845,19 +1836,19 @@ class personality extends question //$this->html .= ' '; $this->html .= ' '.api_return_html_area('answers['.$key.']', api_html_entity_decode(stripslashes($form_content['answers'][$key])), '', '', null, array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120')).''; $this->html .= ' '; - + if ($total_number_of_answers> 2) { - $this->html .=$question_values[$count]; + $this->html .=$question_values[$count]; } - + if ($key<$total_number_of_answers-1) { - $this->html .= ' '; + $this->html .= ' '; } if ($key>0) { - $this->html .= ' '; + $this->html .= ' '; } if ($total_number_of_answers> 2) { @@ -1908,7 +1899,7 @@ class multipleresponse extends question $this->html .= get_lang('DisplayAnswersHorVert'); $this->html .= '
'; $this->html .= '
'; - $this->html .= ' html .= ' html .= 'checked="checked"'; } @@ -1951,10 +1942,10 @@ class multipleresponse extends question $this->html .= ' '; $this->html .= ' '; } - // The buttons for adding or removing + // The buttons for adding or removing $this->html .= ' '; $this->html .= '
'; - $this->html .= '
'; + $this->html .= ' '; $this->html .= parent :: add_remove_buttons($form_content); } @@ -2038,7 +2029,7 @@ class dropdown extends question $this->html .= ' '; $this->html .= ' '; } - // The buttons for adding or removing + // The buttons for adding or removing $this->html .= ' '; $this->html .= ' '; $this->html .= ' '; @@ -2058,17 +2049,17 @@ class dropdown extends question foreach ($form_content['options'] as $key=>$value) { - $this->html .= ''; } - + echo '
'; echo '
'.$form_content['survey_question'].'
'; echo '
'; @@ -2117,7 +2108,7 @@ class open extends question { $content = implode('',$answers); } - else + else { $content = $answers; } @@ -2261,7 +2252,7 @@ class score extends question // The buttons for adding or removing $this->html .= ' '; $this->html .= '
'; - $this->html .= '
'; + $this->html .= ' '; $this->html .= parent :: add_remove_buttons($form_content); } @@ -2316,14 +2307,14 @@ class SurveyUtil { * If so, break the current process, displaying an error message * @param integer Survey ID (database ID) * @param boolean Optional. Whether to continue the current process or exit when breaking condition found. Defaults to true (do not break). - * @return void + * @return void */ function check_first_last_question($survey_id, $continue=true) { // table definitions $tbl_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); - + // getting the information of the question $sql = "SELECT * FROM $tbl_survey_question WHERE survey_id='".Database::escape_string($survey_id)."' ORDER BY sort ASC"; $result = api_sql_query($sql, __FILE__, __LINE__); @@ -2341,10 +2332,10 @@ class SurveyUtil { { Display::display_error_message(get_lang('PagebreakNotLast'), false); $error = true; - } + } $counter++; } - + if (!$continue AND $error) { Display::display_footer(); @@ -2392,7 +2383,7 @@ class SurveyUtil { global $types; // table definition $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER, $_course['db_name']); - + // make the survey anonymous if ($survey_data['anonymous'] == 1) { @@ -2425,32 +2416,32 @@ class SurveyUtil { function check_parameters() { $error = false; - + // getting the survey data $survey_data = survey_manager::get_survey($_GET['survey_id']); - + // $_GET['survey_id'] has to be numeric if (!is_numeric($_GET['survey_id'])) { $error = get_lang('IllegalSurveyId'); } - + // $_GET['action'] $allowed_actions = array('overview', 'questionreport', 'userreport', 'comparativereport', 'completereport','deleteuserreport'); if (isset($_GET['action']) AND !in_array($_GET['action'], $allowed_actions)) { $error = get_lang('ActionNotAllowed'); } - + // user report if ($_GET['action'] == 'userreport') - { + { global $people_filled; if ($survey_data['anonymous'] == 0) { $people_filled_full_data = true; } - else + else { $people_filled_full_data = false; } @@ -2462,17 +2453,17 @@ class SurveyUtil { $people_filled_userids[]=$value['invited_user']; } } - else + else { $people_filled_userids = $people_filled; - } - + } + if (isset($_GET['user']) AND !in_array($_GET['user'], $people_filled_userids)) { $error = get_lang('UnknowUser'); } } - + // question report if ($_GET['action'] == 'questionreport') { @@ -2481,7 +2472,7 @@ class SurveyUtil { $error = get_lang('UnknowQuestion'); } } - + if ($error) { $tool_name = get_lang('Reporting'); @@ -2495,7 +2486,7 @@ class SurveyUtil { return true; } } - + /** * This function deals with the action handling * @return void @@ -2516,10 +2507,10 @@ class SurveyUtil { $questions_data[$value['sort']]=$value; } } - + // counting the number of questions that are relevant for the reporting $survey_data['number_of_questions'] = count($questions_data); - + if ($_GET['action'] == 'questionreport') { SurveyUtil::display_question_report($survey_data); @@ -2546,7 +2537,7 @@ class SurveyUtil { /** * This function deletes the report of an user who wants to retake the survey * @param integer survey_id - * @param integer user_id + * @param integer user_id * @return void * @author Christian Fasanando Flores * @version November 2008 @@ -2570,8 +2561,8 @@ class SurveyUtil { Display::display_confirmation_message($message, false); } } - - + + /** * This function displays the user report which is basically nothing more than a one-page display of all the questions * of the survey that is filled with the answers of the person who filled the survey. @@ -2583,23 +2574,23 @@ class SurveyUtil { function display_user_report() { global $people_filled, $survey_data; - + // Database table definitions $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); $table_survey_answer = Database :: get_course_table(TABLE_SURVEY_ANSWER); - + // actions bar echo '
'; echo ''.Display::return_icon('back.png').' '.get_lang('BackTo').' '.get_lang('ReportingOverview').''; - if (isset($_GET['user'])) + if (isset($_GET['user'])) { // the delete link echo ''.Display::return_icon('delete.gif', get_lang('Delete')).' '.get_lang('DeleteSurveyByUser').''; - + // export the user report - echo ''.Display::return_icon('csv.gif', get_lang('ExportAsCSV')).' '.get_lang('ExportAsCSV').' '; - echo ''.Display::return_icon('excel.gif', get_lang('ExportAsXLS')).' '.get_lang('ExportAsXLS').' '; + echo ''.Display::return_icon('csv.gif', get_lang('ExportAsCSV')).' '.get_lang('ExportAsCSV').' '; + echo ''.Display::return_icon('excel.gif', get_lang('ExportAsXLS')).' '.get_lang('ExportAsXLS').' '; echo '
'; echo ''; echo ''; @@ -2608,10 +2599,10 @@ class SurveyUtil { echo ''; echo ''; echo '
'; - echo '
'; + echo ''; } echo '
'; - + // step 1: selection of the user echo "