myspace.lib.php 137 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use CpChart\Classes\pCache as pCache;
  4. use CpChart\Classes\pData as pData;
  5. use CpChart\Classes\pImage as pImage;
  6. /**
  7. * Class MySpace
  8. * @package chamilo.reporting
  9. */
  10. class MySpace
  11. {
  12. /**
  13. * Get admin actions
  14. * @return string
  15. */
  16. public static function getAdminActions()
  17. {
  18. $actions = array(
  19. //array('url' => api_get_path(WEB_CODE_PATH).'mySpace/index.php', 'content' => get_lang('Home')),
  20. array('url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=coaches', 'content' => get_lang('DisplayCoaches')),
  21. array('url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=user', 'content' => get_lang('DisplayUserOverview')),
  22. array('url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=session', 'content' => get_lang('DisplaySessionOverview')),
  23. array('url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=course', 'content' => get_lang('DisplayCourseOverview')),
  24. array('url' => api_get_path(WEB_CODE_PATH).'tracking/question_course_report.php?view=admin', 'content' => get_lang('LPQuestionListResults')),
  25. array('url' => api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin', 'content' => get_lang('LPExerciseResultsBySession')),
  26. );
  27. return Display :: actions($actions, null);
  28. }
  29. public static function getTopMenu()
  30. {
  31. $menu_items = array();
  32. $menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  33. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher');
  34. $menu_items[] = Display::url(Display::return_icon('star_na.png', get_lang('AdminInterface'), array(), 32), '#');
  35. $menu_items[] = Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php');
  36. $menu = null;
  37. foreach ($menu_items as $item) {
  38. $menu .= $item;
  39. }
  40. $menu .= '<br />';
  41. return $menu;
  42. }
  43. /**
  44. * This function serves exporting data in CSV format.
  45. * @param array $header The header labels.
  46. * @param array $data The data array.
  47. * @param string $file_name The name of the file which contains exported data.
  48. * @return string mixed Returns a message (string) if an error occurred.
  49. */
  50. function export_csv($header, $data, $file_name = 'export.csv')
  51. {
  52. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  53. $archive_url = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
  54. if (!$open = fopen($archive_path.$file_name, 'w+')) {
  55. $message = get_lang('noOpen');
  56. } else {
  57. $info = '';
  58. foreach ($header as $value) {
  59. $info .= $value.';';
  60. }
  61. $info .= "\r\n";
  62. foreach ($data as $row) {
  63. foreach ($row as $value) {
  64. $info .= $value.';';
  65. }
  66. $info .= "\r\n";
  67. }
  68. fwrite($open, $info);
  69. fclose($open);
  70. @chmod($file_name, api_get_permissions_for_new_files());
  71. header("Location:".$archive_url.$file_name);
  72. }
  73. return $message;
  74. }
  75. /**
  76. * Gets the connections to a course as an array of login and logout time
  77. *
  78. * @param int User ud
  79. * @param int $courseId
  80. * @param int Session id (optional, default = 0)
  81. * @return array Conections
  82. */
  83. static function get_connections_to_course($user_id, $courseId, $session_id = 0)
  84. {
  85. // Database table definitions
  86. $tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  87. // protect data
  88. $user_id = intval($user_id);
  89. $courseId = intval($courseId);
  90. $session_id = intval($session_id);
  91. $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . '
  92. WHERE user_id = '.$user_id.' AND
  93. c_id = '.$courseId.' AND
  94. session_id = '.$session_id.'
  95. ORDER BY login_course_date ASC';
  96. $rs = Database::query($sql);
  97. $connections = array();
  98. while ($row = Database::fetch_array($rs)) {
  99. $timestamp_login_date = api_strtotime($row['login_course_date'], 'UTC');
  100. $timestamp_logout_date = api_strtotime($row['logout_course_date'], 'UTC');
  101. $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date);
  102. }
  103. return $connections;
  104. }
  105. /**
  106. * @param $user_id
  107. * @param $course_list
  108. * @param int $session_id
  109. * @return array|bool
  110. */
  111. static function get_connections_from_course_list($user_id, $course_list, $session_id = 0)
  112. {
  113. // Database table definitions
  114. $tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  115. if (empty($course_list)) {
  116. return false;
  117. }
  118. // protect data
  119. $user_id = intval($user_id);
  120. $session_id = intval($session_id);
  121. $new_course_list = array();
  122. foreach ($course_list as $course_item) {
  123. $courseInfo = api_get_course_info($course_item['code']);
  124. $courseId = $courseInfo['real_id'];
  125. $new_course_list[] = '"'.$courseId.'"';
  126. }
  127. $course_list = implode(', ', $new_course_list);
  128. if (empty($course_list)) {
  129. return false;
  130. }
  131. $sql = 'SELECT login_course_date, logout_course_date, c_id
  132. FROM ' . $tbl_track_course . '
  133. WHERE
  134. user_id = '.$user_id.' AND
  135. c_id IN ('.$course_list.') AND
  136. session_id = '.$session_id.'
  137. ORDER BY login_course_date ASC';
  138. $rs = Database::query($sql);
  139. $connections = array();
  140. while ($row = Database::fetch_array($rs)) {
  141. $timestamp_login_date = api_strtotime($row['login_course_date'], 'UTC');
  142. $timestamp_logout_date = api_strtotime($row['logout_course_date'], 'UTC');
  143. $connections[] = array(
  144. 'login' => $timestamp_login_date,
  145. 'logout' => $timestamp_logout_date,
  146. 'c_id' => $row['c_id']
  147. );
  148. }
  149. return $connections;
  150. }
  151. /**
  152. * Creates a small table in the last column of the table with the user overview
  153. *
  154. * @param integer $user_id the id of the user
  155. * @param array $url_params additonal url parameters
  156. * @param array $row the row information (the other columns)
  157. * @return string html code
  158. */
  159. public static function course_info_tracking_filter($user_id, $url_params, $row)
  160. {
  161. // the table header
  162. $return = '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  163. /*$return .= ' <tr>';
  164. $return .= ' <th>'.get_lang('Course').'</th>';
  165. $return .= ' <th>'.get_lang('AvgTimeSpentInTheCourse').'</th>';
  166. $return .= ' <th>'.get_lang('AvgStudentsProgress').'</th>';
  167. $return .= ' <th>'.get_lang('AvgCourseScore').'</th>';
  168. $return .= ' <th>'.get_lang('AvgExercisesScore').'</th>';
  169. $return .= ' <th>'.get_lang('AvgMessages').'</th>';
  170. $return .= ' <th>'.get_lang('AvgAssignments').'</th>';
  171. $return .= ' <th>'.get_lang('TotalExercisesScoreObtained').'</th>';
  172. $return .= ' <th>'.get_lang('TotalExercisesScorePossible').'</th>';
  173. $return .= ' <th>'.get_lang('TotalExercisesAnswered').'</th>';
  174. $return .= ' <th>'.get_lang('TotalExercisesScorePercentage').'</th>';
  175. $return .= ' <th>'.get_lang('FirstLogin').'</th>';
  176. $return .= ' <th>'.get_lang('LatestLogin').'</th>';
  177. $return .= ' </tr>';*/
  178. // database table definition
  179. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  180. // getting all the courses of the user
  181. $sql = "SELECT * FROM $tbl_course_user
  182. WHERE
  183. user_id = '".intval($user_id)."' AND
  184. relation_type<>".COURSE_RELATION_TYPE_RRHH." ";
  185. $result = Database::query($sql);
  186. while ($row = Database::fetch_array($result)) {
  187. $courseInfo = api_get_course_info_by_id($row['c_id']);
  188. if (empty($courseInfo)) {
  189. continue;
  190. }
  191. $courseCode = $courseInfo['code'];
  192. $courseId = $courseInfo['real_id'];
  193. $return .= '<tr>';
  194. // course code
  195. $return .= ' <td width="157px" >'.cut($courseCode, 20, true).'</td>';
  196. // time spent in the course
  197. $return .= ' <td><div>'.api_time_to_hms(Tracking :: get_time_spent_on_the_course($user_id, $courseId)).'</div></td>';
  198. // student progress in course
  199. $return .= ' <td><div>'.round(Tracking :: get_avg_student_progress($user_id, $courseCode), 2).'</div></td>';
  200. // student score
  201. $avg_score = Tracking :: get_avg_student_score($user_id, $courseCode);
  202. if (is_numeric($avg_score)) {
  203. $avg_score = round($avg_score,2);
  204. } else {
  205. $$avg_score = '-';
  206. }
  207. $return .= ' <td><div>'.$avg_score.'</div></td>';
  208. // student tes score
  209. //$return .= ' <td><div style="width:40px">'.round(Tracking :: get_avg_student_exercise_score ($user_id, $courseCode),2).'%</div></td>';
  210. // student messages
  211. $return .= ' <td><div>'.Tracking :: count_student_messages($user_id, $courseCode).'</div></td>';
  212. // student assignments
  213. $return .= ' <td><div>'.Tracking :: count_student_assignments($user_id, $courseCode).'</div></td>';
  214. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  215. $exercises_results = MySpace::exercises_results($user_id, $courseCode);
  216. $return .= ' <td width="105px"><div>'.(is_null($exercises_results['percentage']) ? '' : $exercises_results['score_obtained'].'/'.$exercises_results['score_possible'].' ( '.$exercises_results['percentage'].'% )').'</div></td>';
  217. //$return .= ' <td><div>'.$exercises_results['score_possible'].'</div></td>';
  218. $return .= ' <td><div>'.$exercises_results['questions_answered'].'</div></td>';
  219. $return .= ' <td><div>'.Tracking :: get_last_connection_date_on_the_course($user_id, $courseInfo).'</div></td>';
  220. $return .= '<tr>';
  221. }
  222. $return .= '</table>';
  223. return $return;
  224. }
  225. /**
  226. * Display a sortable table that contains an overview off all the reporting progress of all users and all courses the user is subscribed to
  227. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  228. * @version Dokeos 1.8.6
  229. * @since October 2008
  230. */
  231. public static function display_tracking_user_overview()
  232. {
  233. MySpace::display_user_overview_export_options();
  234. $t_head = ' <table style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  235. //$t_head .= ' <caption>'.get_lang('CourseInformation').'</caption>';
  236. $t_head .= '<tr>';
  237. $t_head .= ' <th width="155px" style="border-left:0;border-bottom:0"><span>'.get_lang('Course').'</span></th>';
  238. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).'</span></th>';
  239. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgStudentsProgress'), 6, true).'</span></th>';
  240. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgCourseScore'), 6, true).'</span></th>';
  241. //$t_head .= ' <th><div style="width:40px">'.get_lang('AvgExercisesScore').'</div></th>';
  242. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfMessages'), 6, true).'</span></th>';
  243. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfAssignments'), 6, true).'</span></th>';
  244. $t_head .= ' <th width="105px" style="border-bottom:0"><span>'.get_lang('TotalExercisesScoreObtained').'</span></th>';
  245. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePossible').'</div></th>';
  246. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalExercisesAnswered'), 6, true).'</span></th>';
  247. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePercentage').'</div></th>';
  248. //$t_head .= ' <th><div style="width:60px">'.get_lang('FirstLogin').'</div></th>';
  249. $t_head .= ' <th style="padding:0;border-bottom:0;border-right:0;"><span>'.get_lang('LatestLogin').'</span></th>';
  250. $t_head .= ' </tr></table>';
  251. $addparams = array('view' => 'admin', 'display' => 'useroverview');
  252. $table = new SortableTable('tracking_user_overview', array('MySpace','get_number_of_users_tracking_overview'), array('MySpace','get_user_data_tracking_overview'), 0);
  253. $table->additional_parameters = $addparams;
  254. $table->set_header(0, get_lang('OfficialCode'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  255. if (api_is_western_name_order()) {
  256. $table->set_header(1, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  257. $table->set_header(2, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  258. } else {
  259. $table->set_header(1, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  260. $table->set_header(2, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  261. }
  262. $table->set_header(3, get_lang('LoginName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  263. $table->set_header(4, $t_head, false, array('style' => 'width:90%;border:0;padding:0;font-size:7.5pt;'), array('style' => 'width:90%;padding:0;font-size:7.5pt;'));
  264. $table->set_column_filter(4, array('MySpace','course_info_tracking_filter'));
  265. $table->display();
  266. }
  267. public static function display_tracking_coach_overview($export_csv)
  268. {
  269. if ($export_csv) {
  270. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  271. } else {
  272. $is_western_name_order = api_is_western_name_order();
  273. }
  274. $sort_by_first_name = api_sort_by_first_name();
  275. $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : ($is_western_name_order xor $sort_by_first_name) ? 1 : 0;
  276. $tracking_direction = (isset($_GET['tracking_list_coaches_direction']) && in_array(strtoupper($_GET['tracking_list_coaches_direction']), array('ASC', 'DESC', 'ASCENDING', 'DESCENDING', '0', '1'))) ? $_GET['tracking_list_coaches_direction'] : 'DESC';
  277. // Prepare array for column order - when impossible, use some of user names.
  278. if ($is_western_name_order) {
  279. $order = array(0 => 'firstname', 1 => 'lastname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname'));
  280. } else {
  281. $order = array(0 => 'lastname', 1 => 'firstname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname'));
  282. }
  283. $table = new SortableTable('tracking_list_coaches_myspace', array('MySpace', 'count_coaches'), null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0);
  284. $parameters['view'] = 'admin';
  285. $table->set_additional_parameters($parameters);
  286. if ($is_western_name_order) {
  287. $table -> set_header(0, get_lang('FirstName'), true);
  288. $table -> set_header(1, get_lang('LastName'), true);
  289. } else {
  290. $table -> set_header(0, get_lang('LastName'), true);
  291. $table -> set_header(1, get_lang('FirstName'), true);
  292. }
  293. $table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false);
  294. $table -> set_header(3, get_lang('LastConnexion'), false);
  295. $table -> set_header(4, get_lang('NbStudents'), false);
  296. $table -> set_header(5, get_lang('CountCours'), false);
  297. $table -> set_header(6, get_lang('NumberOfSessions'), false);
  298. $table -> set_header(7, get_lang('Sessions'), false);
  299. if ($is_western_name_order) {
  300. $csv_header[] = array (
  301. get_lang('FirstName', ''),
  302. get_lang('LastName', ''),
  303. get_lang('TimeSpentOnThePlatform', ''),
  304. get_lang('LastConnexion', ''),
  305. get_lang('NbStudents', ''),
  306. get_lang('CountCours', ''),
  307. get_lang('NumberOfSessions', '')
  308. );
  309. } else {
  310. $csv_header[] = array (
  311. get_lang('LastName', ''),
  312. get_lang('FirstName', ''),
  313. get_lang('TimeSpentOnThePlatform', ''),
  314. get_lang('LastConnexion', ''),
  315. get_lang('NbStudents', ''),
  316. get_lang('CountCours', ''),
  317. get_lang('NumberOfSessions', '')
  318. );
  319. }
  320. $tbl_track_login = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  321. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  322. $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  323. $tbl_sessions = Database::get_main_table(TABLE_MAIN_SESSION);
  324. $sqlCoachs = "SELECT DISTINCT
  325. scu.user_id as id_coach,
  326. u.id as user_id,
  327. lastname,
  328. firstname,
  329. MAX(login_date) as login_date
  330. FROM $tbl_user u, $tbl_session_course_user scu, $tbl_track_login
  331. WHERE
  332. scu.user_id = u.id AND scu.status=2 AND login_user_id=u.id
  333. GROUP BY user_id ";
  334. if (api_is_multiple_url_enabled()) {
  335. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  336. $access_url_id = api_get_current_access_url_id();
  337. if ($access_url_id != -1) {
  338. $sqlCoachs = "SELECT DISTINCT
  339. scu.user_id as id_coach,
  340. u.id as user_id,
  341. lastname,
  342. firstname,
  343. MAX(login_date) as login_date
  344. FROM $tbl_user u,
  345. $tbl_session_course_user scu,
  346. $tbl_track_login ,
  347. $tbl_session_rel_access_url session_rel_url
  348. WHERE
  349. scu.user_id = u.id AND
  350. scu.status = 2 AND
  351. login_user_id = u.id AND
  352. access_url_id = $access_url_id AND
  353. session_rel_url.session_id = scu.session_id
  354. GROUP BY u.id";
  355. }
  356. }
  357. if (!empty($order[$tracking_column])) {
  358. $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction;
  359. }
  360. $result_coaches = Database::query($sqlCoachs);
  361. $total_no_coaches = Database::num_rows($result_coaches);
  362. $global_coaches = array();
  363. while ($coach = Database::fetch_array($result_coaches)) {
  364. $global_coaches[$coach['user_id']] = $coach;
  365. }
  366. $sql_session_coach = 'SELECT session.id_coach, u.id as user_id, lastname, firstname, MAX(login_date) as login_date
  367. FROM '.$tbl_user.' u ,'.$tbl_sessions.' as session,'.$tbl_track_login.'
  368. WHERE id_coach = u.id AND login_user_id = u.id
  369. GROUP BY u.id
  370. ORDER BY login_date '.$tracking_direction;
  371. if (api_is_multiple_url_enabled()) {
  372. $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  373. $access_url_id = api_get_current_access_url_id();
  374. if ($access_url_id != -1) {
  375. $sql_session_coach = 'SELECT session.id_coach, u.id as user_id, lastname, firstname, MAX(login_date) as login_date
  376. FROM '.$tbl_user.' u ,'.$tbl_sessions.' as session, '.$tbl_track_login.' , '.$tbl_session_rel_access_url.' as session_rel_url
  377. WHERE
  378. id_coach = u.id AND
  379. login_user_id = u.id AND
  380. access_url_id = '.$access_url_id.' AND
  381. session_rel_url.session_id = session.id
  382. GROUP BY u.id
  383. ORDER BY login_date '.$tracking_direction;
  384. }
  385. }
  386. $result_sessions_coach = Database::query($sql_session_coach);
  387. $total_no_coaches += Database::num_rows($result_sessions_coach);
  388. while ($coach = Database::fetch_array($result_sessions_coach)) {
  389. $global_coaches[$coach['user_id']] = $coach;
  390. }
  391. $all_datas = array();
  392. foreach ($global_coaches as $id_coach => $coaches) {
  393. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($coaches['user_id']));
  394. $last_connection = Tracking :: get_last_connection_date($coaches['user_id']);
  395. $nb_students = count(Tracking :: get_student_followed_by_coach($coaches['user_id']));
  396. $nb_courses = count(Tracking :: get_courses_followed_by_coach($coaches['user_id']));
  397. $nb_sessions = count(Tracking :: get_sessions_coached_by_user($coaches['user_id']));
  398. $table_row = array();
  399. if ($is_western_name_order) {
  400. $table_row[] = $coaches['firstname'];
  401. $table_row[] = $coaches['lastname'];
  402. } else {
  403. $table_row[] = $coaches['lastname'];
  404. $table_row[] = $coaches['firstname'];
  405. }
  406. $table_row[] = $time_on_platform;
  407. $table_row[] = $last_connection;
  408. $table_row[] = $nb_students;
  409. $table_row[] = $nb_courses;
  410. $table_row[] = $nb_sessions;
  411. $table_row[] = '<a href="session.php?id_coach='.$coaches['user_id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  412. $all_datas[] = $table_row;
  413. if ($is_western_name_order) {
  414. $csv_content[] = array(
  415. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  416. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  417. $time_on_platform,
  418. $last_connection,
  419. $nb_students,
  420. $nb_courses,
  421. $nb_sessions
  422. );
  423. } else {
  424. $csv_content[] = array(
  425. api_html_entity_decode($coaches['lastname'], ENT_QUOTES, $charset),
  426. api_html_entity_decode($coaches['firstname'], ENT_QUOTES, $charset),
  427. $time_on_platform,
  428. $last_connection,
  429. $nb_students,
  430. $nb_courses,
  431. $nb_sessions
  432. );
  433. }
  434. }
  435. if ($tracking_column != 3) {
  436. if ($tracking_direction == 'DESC') {
  437. usort($all_datas, array('MySpace','rsort_users'));
  438. } else {
  439. usort($all_datas, array('MySpace','sort_users'));
  440. }
  441. }
  442. if ($export_csv && $tracking_column != 3) {
  443. usort($csv_content, 'sort_users');
  444. }
  445. if ($export_csv) {
  446. $csv_content = array_merge($csv_header, $csv_content);
  447. }
  448. foreach ($all_datas as $row) {
  449. $table -> addRow($row, 'align="right"');
  450. }
  451. $table -> display();
  452. }
  453. public static function count_coaches() {
  454. global $total_no_coaches;
  455. return $total_no_coaches;
  456. }
  457. public static function sort_users($a, $b) {
  458. return api_strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  459. }
  460. public static function rsort_users($a, $b) {
  461. return api_strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
  462. }
  463. /**
  464. * Display a sortable table that contains an overview off all the progress of the user in a session
  465. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  466. */
  467. public static function display_tracking_lp_progress_overview($sessionId = '', $courseId = '', $date_from, $date_to)
  468. {
  469. $course = api_get_course_info_by_id($courseId);
  470. /**
  471. * Column name
  472. * The order is important you need to check the $column variable in the model.ajax.php file
  473. */
  474. $columns = array(
  475. get_lang('Username'),
  476. get_lang('FirstName'),
  477. get_lang('LastName'),
  478. );
  479. //add lessons of course
  480. $lessons = LearnpathList::get_course_lessons($course['code'], $sessionId);
  481. //create columns array
  482. foreach ($lessons as $lesson_id => $lesson)
  483. {
  484. $columns[] = $lesson['name'];
  485. }
  486. $columns[] = get_lang('Total');
  487. /**
  488. * Column config
  489. */
  490. $column_model = array(
  491. array('name'=>'username', 'index'=>'username', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  492. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left', 'search' => 'true'),
  493. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left', 'search' => 'true'),
  494. );
  495. //get dinamic column names
  496. foreach ($lessons as $lesson_id => $lesson)
  497. {
  498. $column_model[] = array('name'=> $lesson['id'], 'index'=>$lesson['id'], 'align'=>'left', 'search' => 'true');
  499. }
  500. $column_model[] = array('name'=>'total', 'index'=>'total', 'align'=>'left', 'search' => 'true');
  501. $action_links = '';
  502. // jqgrid will use this URL to do the selects
  503. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_session_lp_progress&session_id=' . $sessionId . '&course_id=' . $courseId . '&date_to=' . $date_to . '&date_from=' . $date_from;
  504. //Table Id
  505. $tableId = 'lpProgress';
  506. //Autowidth
  507. $extra_params['autowidth'] = 'true';
  508. //height auto
  509. $extra_params['height'] = 'auto';
  510. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  511. $return = '<script>$(function() {'. $table .
  512. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  513. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  514. caption:"",
  515. title:"' . get_lang('ExportExcel') . '",
  516. onClickButton : function () {
  517. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  518. }
  519. });
  520. });</script>';
  521. $return .= Display::grid_html($tableId);
  522. return $return;
  523. }
  524. /**
  525. * Display a sortable table that contains an overview off all the progress of the user in a session
  526. * @param int $sessionId The session ID
  527. * @param int $courseId The course ID
  528. * @param int $exerciseId The quiz ID
  529. * @param int $answer Answer status (0 = incorrect, 1 = correct, 2 = both)
  530. * @return string HTML array of results formatted for gridJS
  531. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  532. */
  533. static function display_tracking_exercise_progress_overview(
  534. $sessionId = 0,
  535. $courseId = 0,
  536. $exerciseId = 0,
  537. $date_from = null,
  538. $date_to = null
  539. ) {
  540. $date_from = Security::remove_XSS($date_from);
  541. $date_to = Security::remove_XSS($date_to);
  542. /**
  543. * Column names
  544. * The column order is important. Check $column variable in the main/inc/ajax/model.ajax.php file
  545. */
  546. $columns = array(
  547. get_lang('Session'),
  548. get_lang('ExerciseId'),
  549. get_lang('ExerciseName'),
  550. get_lang('Username'),
  551. get_lang('LastName'),
  552. get_lang('FirstName'),
  553. get_lang('Time'),
  554. get_lang('QuestionId'),
  555. get_lang('QuestionTitle'),
  556. get_lang('WorkDescription'),
  557. get_lang('Answer'),
  558. get_lang('Correct'),
  559. );
  560. /**
  561. * Column config
  562. */
  563. $column_model = array(
  564. array('name'=>'session', 'index'=>'session', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  565. array('name'=>'exercise_id', 'index'=>'exercise_id', 'align'=>'left', 'search' => 'true'),
  566. array('name'=>'quiz_title', 'index'=>'quiz_title', 'align'=>'left', 'search' => 'true'),
  567. array('name'=>'username', 'index'=>'username', 'align'=>'left', 'search' => 'true'),
  568. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left', 'search' => 'true'),
  569. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left', 'search' => 'true'),
  570. array('name'=>'time', 'index'=>'time', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  571. array('name'=>'question_id', 'index'=>'question_id', 'align'=>'left', 'search' => 'true'),
  572. array('name'=>'question', 'index'=>'question', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  573. array('name'=>'description', 'index'=>'description', 'align'=>'left', 'width' => '550', 'search' => 'true', 'wrap_cell' => "true"),
  574. array('name'=>'answer', 'index'=>'answer', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  575. array('name'=>'correct', 'index'=>'correct', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  576. );
  577. //get dynamic column names
  578. // jqgrid will use this URL to do the selects
  579. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_exercise_progress&session_id=' . $sessionId . '&course_id=' . $courseId . '&exercise_id=' . $exerciseId . '&date_to=' . $date_to . '&date_from=' . $date_from;
  580. // Autowidth
  581. $extra_params['autowidth'] = 'true';
  582. // height auto
  583. $extra_params['height'] = 'auto';
  584. $tableId = 'exerciseProgressOverview';
  585. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), '', true);
  586. $return = '<script>$(function() {'. $table .
  587. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  588. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  589. caption:"",
  590. title:"' . get_lang('ExportExcel') . '",
  591. onClickButton : function () {
  592. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  593. }
  594. });
  595. });</script>';
  596. $return .= Display::grid_html($tableId);
  597. return $return;
  598. }
  599. /**
  600. * Display a sortable table that contains an overview off all the progress of the user in a session
  601. * @param int $sessionId The session ID
  602. * @param int $courseId The course ID
  603. * @param null $date_from
  604. * @param null $date_to
  605. * @internal param int $exerciseId The quiz ID
  606. * @internal param int $answer Answer status (0 = incorrect, 1 = correct, 2 = both)
  607. * @return string HTML array of results formatted for gridJS
  608. * @author Francis Gonzales <francis.gonzales@beeznest.com>, Beeznest Team
  609. */
  610. static function display_tracking_grade_overview($sessionId = 0, $courseId = 0, $date_from = null, $date_to = null)
  611. {
  612. /**
  613. * Column names
  614. * The column order is important. Check $column variable in the main/inc/ajax/model.ajax.php file
  615. */
  616. $objExercise = new Exercise();
  617. $exercises = $objExercise->getExercisesByCouseSession($courseId, $sessionId);
  618. $cntExer = 4;
  619. if (!empty($exercises)) {
  620. $cntExer += count($exercises);
  621. }
  622. $column = array();
  623. $column_model = array();
  624. $i = 1;
  625. //Get dynamic column names
  626. foreach (range(1, $cntExer) as $cnt) {
  627. switch ($cnt) {
  628. case 1:
  629. $column[] = get_lang('Section');
  630. $column_model[] = array(
  631. 'name' => 'session',
  632. 'index' => 'session',
  633. 'align' => 'center',
  634. 'search' => 'true',
  635. );
  636. break;
  637. case 2:
  638. $column[] = get_lang('Username');
  639. $column_model[] = array(
  640. 'name' => 'username',
  641. 'index' => 'username',
  642. 'align' => 'center',
  643. 'search' => 'true',
  644. );
  645. break;
  646. case 3:
  647. $column[] = get_lang('FirstName');
  648. $column_model[] = array(
  649. 'name' => 'name',
  650. 'index' => 'name',
  651. 'align' => 'left',
  652. 'search' => 'true',
  653. );
  654. break;
  655. case $cntExer:
  656. $column[] = get_lang('FinalScore');
  657. $column_model[] = array(
  658. 'name' => 'finalscore',
  659. 'index' => 'finalscore',
  660. 'align' => 'center',
  661. 'search' => 'true',
  662. 'wrap_cell' => "true"
  663. );
  664. break;
  665. default:
  666. $title = "";
  667. if (!empty($exercises[$cnt - 4]['title'])) {
  668. $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title'])));
  669. }
  670. $column[] = $title;
  671. $column_model[] = array(
  672. 'name' => 'exer' . $i,
  673. 'index' => 'exer' . $i,
  674. 'align' => 'center',
  675. 'search' => 'true',
  676. 'wrap_cell' => "true"
  677. );
  678. $i++;
  679. break;
  680. }
  681. }
  682. //end get dynamic column names
  683. // jqgrid will use this URL to do the selects
  684. $url = api_get_path(WEB_AJAX_PATH) . 'model.ajax.php?a=get_exercise_grade&session_id=' . $sessionId . '&course_id=' . $courseId;
  685. //Autowidth
  686. $extra_params['autowidth'] = 'true';
  687. //height auto
  688. $extra_params['height'] = 'auto';
  689. $tableId = 'exerciseGradeOverview';
  690. $table = Display::grid_js($tableId, $url, $column, $column_model, $extra_params, array(), '', true);
  691. $return = '<script>$(function() {' . $table .
  692. 'jQuery("#' . $tableId . '").jqGrid("navGrid","#' . $tableId . '_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  693. jQuery("#' . $tableId . '").jqGrid("navButtonAdd","#' . $tableId . '_pager",{
  694. caption:"",
  695. title:"' . get_lang('ExportExcel') . '",
  696. onClickButton : function () {
  697. jQuery("#' . $tableId . '").jqGrid("excelExport",{"url":"' . $url . '&export_format=xls"});
  698. }
  699. });
  700. });</script>';
  701. $return .= Display::grid_html($tableId);
  702. return $return;
  703. }
  704. /**
  705. * Display a sortable table that contains an overview off all the progress of the user in a session
  706. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  707. */
  708. function display_survey_overview($sessionId = 0, $courseId = 0, $surveyId = 0, $date_from, $date_to)
  709. {
  710. /**
  711. * Column name
  712. * The order is important you need to check the $column variable in the model.ajax.php file
  713. */
  714. $columns = array(
  715. get_lang('Username'),
  716. get_lang('FirstName'),
  717. get_lang('LastName'),
  718. );
  719. //add lessons of course
  720. $questions = SurveyManager::get_questions($surveyId, $courseId);
  721. foreach ($questions as $question) {
  722. $columns[] = $question['question'];
  723. }
  724. /**
  725. * Column config
  726. */
  727. $column_model = array(
  728. array('name'=>'username', 'index'=>'username', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  729. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left', 'search' => 'true'),
  730. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left', 'search' => 'true'),
  731. );
  732. //get dinamic column names
  733. foreach ($questions as $question_id => $question) {
  734. $column_model[] = array(
  735. 'name'=> $question_id,
  736. 'index'=>$question_id,
  737. 'width'=>'70',
  738. 'align'=>'left',
  739. 'search' => 'true'
  740. );
  741. }
  742. $action_links = '';
  743. // jqgrid will use this URL to do the selects
  744. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_survey_overview&session_id=' . $sessionId . '&course_id=' . $courseId . '&survey_id=' . $surveyId . '&date_to=' . $date_to . '&date_from=' . $date_from;
  745. //Table Id
  746. $tableId = 'lpProgress';
  747. //Autowidth
  748. $extra_params['autowidth'] = 'true';
  749. //height auto
  750. $extra_params['height'] = 'auto';
  751. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  752. $return = '<script>$(function() {'. $table .
  753. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  754. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  755. caption:"",
  756. title:"' . get_lang('ExportExcel') . '",
  757. onClickButton : function () {
  758. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  759. }
  760. });
  761. });</script>';
  762. $return .= Display::grid_html($tableId);
  763. return $return;
  764. }
  765. /**
  766. * Display a sortable table that contains an overview off all the progress of the user in a session
  767. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  768. */
  769. static function display_tracking_progress_overview($sessionId = 0, $courseId = 0, $date_from, $date_to)
  770. {
  771. //The order is important you need to check the the $column variable in the model.ajax.php file
  772. $columns = array(
  773. get_lang('LastName'),
  774. get_lang('FirstName'),
  775. get_lang('Username'),
  776. #get_lang('Profile'),
  777. get_lang('Total'),
  778. get_lang('Courses'),
  779. get_lang('LearningPaths'),
  780. get_lang('Exercises'),
  781. get_lang('Forums'),
  782. get_lang('Assignments'),
  783. get_lang('ToolWiki'),
  784. get_lang('ToolSurvey'),
  785. //Learning paths
  786. get_lang('LearnpathsTotal'),
  787. get_lang('LearnpathsDone'),
  788. get_lang('LearnpathsLeft'),
  789. get_lang('LearnpathsProgress'),
  790. //Exercises
  791. get_lang('ExercisesTotal'),
  792. get_lang('ExercisesDone'),
  793. get_lang('ExercisesLeft'),
  794. get_lang('ExercisesProgress'),
  795. //Forums
  796. get_lang('ForumsTotal'),
  797. get_lang('ForumsDone'),
  798. get_lang('ForumsLeft'),
  799. get_lang('ForumsProgress'),
  800. //Assignments
  801. get_lang('AssignmentsTotal'),
  802. get_lang('AssignmentsDone'),
  803. get_lang('AssignmentsLeft'),
  804. get_lang('AssignmentsProgress'),
  805. //Wiki
  806. get_lang('WikiTotal'),
  807. get_lang('WikiRevisions'),
  808. get_lang('WikiRead'),
  809. get_lang('WikiUnread'),
  810. get_lang('WikiProgress'),
  811. //Surveys
  812. get_lang('SurveysTotal'),
  813. get_lang('SurveysDone'),
  814. get_lang('SurveysLeft'),
  815. get_lang('SurveysProgress'),
  816. );
  817. //Column config
  818. $column_model = array(
  819. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left'),
  820. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left'),
  821. array('name'=>'username', 'index'=>'username', 'align'=>'left'),
  822. #array('name'=>'profile', 'index'=>'username', 'align'=>'left'),
  823. array('name'=>'total', 'index'=>'total', 'align'=>'left'),
  824. array('name'=>'courses', 'index'=>'courses', 'align'=>'left', 'sortable' => 'false'),
  825. array('name'=>'lessons', 'index'=>'lessons', 'align'=>'left', 'sortable' => 'false'),
  826. array('name'=>'exercises', 'index'=>'exercises', 'align'=>'left', 'sortable' => 'false'),
  827. array('name'=>'forums', 'index'=>'forums', 'align'=>'left', 'sortable' => 'false'),
  828. array('name'=>'homeworks', 'index'=>'homeworks', 'align'=>'left', 'sortable' => 'false'),
  829. array('name'=>'wikis', 'index'=>'wikis', 'align'=>'left', 'sortable' => 'false'),
  830. array('name'=>'surveys', 'index'=>'surveys', 'align'=>'left', 'sortable' => 'false'),
  831. //Lessons
  832. array('name'=>'lessons_total', 'index'=>'lessons_total', 'align'=>'center', 'sortable' => 'false'),
  833. array('name'=>'lessons_done', 'index'=>'lessons_done', 'align'=>'center', 'sortable' => 'false'),
  834. array('name'=>'lessons_left', 'index'=>'lessons_left', 'align'=>'center', 'sortable' => 'false'),
  835. array('name'=>'lessons_progress', 'index'=>'lessons_progress', 'align'=>'center', 'sortable' => 'false'),
  836. //Exercises
  837. array('name'=>'exercises_total', 'index'=>'exercises_total', 'align'=>'center', 'sortable' => 'false'),
  838. array('name'=>'exercises_done', 'index'=>'exercises_done', 'align'=>'center', 'sortable' => 'false'),
  839. array('name'=>'exercises_left', 'index'=>'exercises_left', 'align'=>'center', 'sortable' => 'false'),
  840. array('name'=>'exercises_progress', 'index'=>'exercises_progress', 'align'=>'center', 'sortable' => 'false'),
  841. //Assignments
  842. array('name'=>'forums_total', 'index'=>'forums_total', 'align'=>'center', 'sortable' => 'false'),
  843. array('name'=>'forums_done', 'index'=>'forums_done', 'align'=>'center', 'sortable' => 'false'),
  844. array('name'=>'forums_left', 'index'=>'forums_left', 'align'=>'center', 'sortable' => 'false'),
  845. array('name'=>'forums_progress', 'index'=>'forums_progress', 'align'=>'center', 'sortable' => 'false'),
  846. //Assignments
  847. array('name'=>'assigments_total', 'index'=>'assigments_total', 'align'=>'center', 'sortable' => 'false'),
  848. array('name'=>'assigments_done', 'index'=>'assigments_done', 'align'=>'center', 'sortable' => 'false'),
  849. array('name'=>'assigments_left', 'index'=>'assigments_left', 'align'=>'center', 'sortable' => 'false'),
  850. array('name'=>'assigments_progress', 'index'=>'assigments_progress', 'align'=>'center', 'sortable' => 'false'),
  851. //Assignments
  852. array('name'=>'wiki_total', 'index'=>'wiki_total', 'align'=>'center', 'sortable' => 'false'),
  853. array('name'=>'wiki_revisions', 'index'=>'wiki_revisions', 'align'=>'center', 'sortable' => 'false'),
  854. array('name'=>'wiki_read', 'index'=>'wiki_read', 'align'=>'center', 'sortable' => 'false'),
  855. array('name'=>'wiki_unread', 'index'=>'wiki_unread', 'align'=>'center', 'sortable' => 'false'),
  856. array('name'=>'wiki_progress', 'index'=>'wiki_progress', 'align'=>'center', 'sortable' => 'false'),
  857. //Surveys
  858. array('name'=>'surveys_total', 'index'=>'surveys_total', 'align'=>'center', 'sortable' => 'false'),
  859. array('name'=>'surveys_done', 'index'=>'surveys_done', 'align'=>'center', 'sortable' => 'false'),
  860. array('name'=>'surveys_left', 'index'=>'surveys_left', 'align'=>'center', 'sortable' => 'false'),
  861. array('name'=>'surveys_progress', 'index'=>'surveys_progress', 'align'=>'center', 'sortable' => 'false'),
  862. );
  863. $action_links = '';
  864. // jqgrid will use this URL to do the selects
  865. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_session_progress&session_id=' . $sessionId . '&course_id=' . $courseId . '&date_to=' . $date_to . '&date_from=' . $date_from;
  866. //Table Id
  867. $tableId = 'progressOverview';
  868. //Autowidth
  869. $extra_params['autowidth'] = 'true';
  870. $extra_params['shrinkToFit'] = 'true';
  871. $extra_params['headertitles'] = 'true';
  872. $extra_params['groupHeaders'] = array(
  873. 'courses_detail' => array(
  874. "startColumnName" => 'courses',
  875. "numberOfColumns" => 7,
  876. "titleText" => get_lang('Global'),
  877. ),
  878. 'lessons' => array(
  879. "startColumnName" => 'lessons_total',
  880. "numberOfColumns" => 4,
  881. "titleText" => get_lang('LearningPaths'),
  882. ),
  883. 'exercises' => array(
  884. "startColumnName" => 'exercises_total',
  885. "numberOfColumns" => 4,
  886. "titleText" => get_lang('Exercises'),
  887. ),
  888. 'forums' => array(
  889. "startColumnName" => 'forums_total',
  890. "numberOfColumns" => 4,
  891. "titleText" => get_lang('Forums'),
  892. ),
  893. 'assignments' => array(
  894. "startColumnName" => 'assigments_total',
  895. "numberOfColumns" => 4,
  896. "titleText" => get_lang('Assignments'),
  897. ),
  898. 'wikis' => array(
  899. "startColumnName" => 'wiki_total',
  900. "numberOfColumns" => 5,
  901. "titleText" => get_lang('Wiki'),
  902. ),
  903. 'surveys' => array(
  904. "startColumnName" => 'surveys_total',
  905. "numberOfColumns" => 4,
  906. "titleText" => get_lang('Survey'),
  907. ),
  908. );
  909. //height auto
  910. $extra_params['height'] = 'auto';
  911. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  912. $return = '<script>$(function() {'. $table .
  913. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  914. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  915. caption:"",
  916. title:"' . get_lang('ExportExcel') . '",
  917. onClickButton : function () {
  918. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  919. }
  920. });
  921. });</script>';
  922. $return .= Display::grid_html($tableId);
  923. return $return;
  924. }
  925. /**
  926. * Display a sortable table that contains an overview off all the access to a session
  927. * @deprecated seem not to be used
  928. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  929. * @version Chamilo 1.9.6
  930. */
  931. static function display_tracking_access_overview($sessionId = 0, $courseId = 0, $studentId = '', $profile = '', $date_from, $date_to)
  932. {
  933. //The order is important you need to check the the $column variable in the model.ajax.php file
  934. $columns = array(
  935. get_lang('LoginDate'),
  936. get_lang('UserName'),
  937. get_lang('LastName'),
  938. get_lang('FirstName'),
  939. get_lang('Clicks'),
  940. get_lang('IP'),
  941. get_lang('TimeLoggedIn'),
  942. get_lang('Section'),
  943. );
  944. $column_model = array(
  945. array('name'=>'logindate', 'index'=>'loginDate', 'align'=>'left', 'search' => 'true'),
  946. array('name'=>'username', 'index'=>'username', 'align'=>'left', 'search' => 'true'),
  947. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left', 'search' => 'true'),
  948. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left', 'search' => 'true'),
  949. array('name'=>'clicks', 'index'=>'clicks', 'align'=>'left', 'search' => 'true'),
  950. array('name'=>'ip', 'index'=>'ip', 'align'=>'left', 'search' => 'true'),
  951. array('name'=>'timeloggedin', 'index'=>'timeLoggedIn', 'align'=>'left', 'search' => 'true'),
  952. array('name'=>'session', 'index'=>'session', 'align'=>'left')
  953. );
  954. $action_links = '';
  955. // jqgrid will use this URL to do the selects
  956. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_session_access_overview&session_id=' . $sessionId . '&course_id=' . $courseId . '&student_id=' . $studentId . '&profile=' . $profile . '&date_to=' . $date_to . '&date_from=' . $date_from;
  957. //Table Id
  958. $tableId = 'accessOverview';
  959. //Autowidth
  960. $extra_params['autowidth'] = 'true';
  961. //height auto
  962. $extra_params['height'] = 'auto';
  963. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  964. $return = '<script>$(function() {'. $table .
  965. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  966. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  967. caption:"",
  968. title:"' . get_lang('ExportExcel') . '",
  969. onClickButton : function () {
  970. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  971. }
  972. });
  973. });</script>';
  974. $return .= Display::grid_html($tableId);
  975. return $return;
  976. }
  977. /**
  978. * Displays a form with all the additionally defined user fields of the profile
  979. * and give you the opportunity to include these in the CSV export
  980. *
  981. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  982. * @version 1.8.6
  983. * @since November 2008
  984. */
  985. public static function display_user_overview_export_options()
  986. {
  987. // include the user manager and formvalidator library
  988. if (isset($_GET['export']) && $_GET['export'] == 'options') {
  989. // get all the defined extra fields
  990. $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC', false, 1);
  991. // creating the form with all the defined extra fields
  992. $form = new FormValidator('exportextrafields', 'post', api_get_self()."?view=".Security::remove_XSS($_GET['view']).'&display='.Security::remove_XSS($_GET['display']).'&export='.Security::remove_XSS($_GET['export']));
  993. if (is_array($extrafields) && count($extrafields) > 0) {
  994. foreach ($extrafields as $key => $extra) {
  995. $form->addElement('checkbox', 'extra_export_field'.$extra[0], '', $extra[3]);
  996. }
  997. $form->addButtonSave(get_lang('Ok'), 'submit');
  998. // setting the default values for the form that contains all the extra fields
  999. if (is_array($_SESSION['additional_export_fields'])) {
  1000. foreach ($_SESSION['additional_export_fields'] as $key => $value) {
  1001. $defaults['extra_export_field'.$value] = 1;
  1002. }
  1003. }
  1004. $form->setDefaults($defaults);
  1005. } else {
  1006. $form->addElement('html', Display::display_warning_message(get_lang('ThereAreNotExtrafieldsAvailable')));
  1007. }
  1008. if ($form->validate()) {
  1009. // exporting the form values
  1010. $values = $form->exportValues();
  1011. // re-initialising the session that contains the additional fields that need to be exported
  1012. $_SESSION['additional_export_fields'] = array();
  1013. // adding the fields that are checked to the session
  1014. $message = '';
  1015. foreach ($values as $field_ids => $value) {
  1016. if ($value == 1 && strstr($field_ids,'extra_export_field')) {
  1017. $_SESSION['additional_export_fields'][] = str_replace('extra_export_field', '', $field_ids);
  1018. }
  1019. }
  1020. // adding the fields that will be also exported to a message string
  1021. if (is_array($_SESSION['additional_export_fields'])) {
  1022. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  1023. $message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
  1024. }
  1025. }
  1026. // Displaying a feedback message
  1027. if (!empty($_SESSION['additional_export_fields'])) {
  1028. Display::display_confirmation_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>', false);
  1029. } else {
  1030. Display::display_confirmation_message(get_lang('NoAdditionalFieldsWillBeExported'), false);
  1031. }
  1032. $message = '';
  1033. } else {
  1034. $form->display();
  1035. }
  1036. } else {
  1037. if (!empty($_SESSION['additional_export_fields'])) {
  1038. // get all the defined extra fields
  1039. $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC');
  1040. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  1041. $message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
  1042. }
  1043. Display::display_normal_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>', false);
  1044. $message = '';
  1045. }
  1046. }
  1047. }
  1048. /**
  1049. * Display a sortable table that contains an overview of all the reporting progress of all courses
  1050. */
  1051. public static function display_tracking_course_overview() {
  1052. //MySpace::display_user_overview_export_options();
  1053. $t_head = ' <table style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  1054. //$t_head .= ' <caption>'.get_lang('CourseInformation').'</caption>';
  1055. $t_head .= '<tr>';
  1056. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).'</span></th>';
  1057. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgStudentsProgress'), 6, true).'</span></th>';
  1058. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgCourseScore'), 6, true).'</span></th>';
  1059. //$t_head .= ' <th><div style="width:40px">'.get_lang('AvgExercisesScore').'</div></th>';
  1060. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfMessages'), 6, true).'</span></th>';
  1061. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfAssignments'), 6, true).'</span></th>';
  1062. $t_head .= ' <th width="105px" style="border-bottom:0"><span>'.get_lang('TotalExercisesScoreObtained').'</span></th>';
  1063. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePossible').'</div></th>';
  1064. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalExercisesAnswered'), 6, true).'</span></th>';
  1065. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePercentage').'</div></th>';
  1066. //$t_head .= ' <th><div style="width:60px">'.get_lang('FirstLogin').'</div></th>';
  1067. $t_head .= ' <th style="padding:0;border-bottom:0;border-right:0;"><span>'.get_lang('LatestLogin').'</span></th>';
  1068. $t_head .= ' </tr></table>';
  1069. $addparams = array('view' => 'admin', 'display' => 'courseoverview');
  1070. $table = new SortableTable('tracking_session_overview', array('MySpace', 'get_total_number_courses'), array('MySpace','get_course_data_tracking_overview'), 1);
  1071. $table->additional_parameters = $addparams;
  1072. $table->set_header(0, '', false, null, array('style' => 'display: none'));
  1073. $table->set_header(1, get_lang('Course'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  1074. $table->set_header(2, $t_head, false, array('style' => 'width:90%;border:0;padding:0;font-size:7.5pt;'), array('style' => 'width:90%;padding:0;font-size:7.5pt;'));
  1075. $table->set_column_filter(2, array('MySpace','course_tracking_filter'));
  1076. $table->display();
  1077. }
  1078. /**
  1079. * Get the total number of courses
  1080. *
  1081. * @return integer Total number of courses
  1082. */
  1083. public static function get_total_number_courses()
  1084. {
  1085. // database table definition
  1086. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  1087. return Database::count_rows($main_course_table);
  1088. }
  1089. /**
  1090. * Get data for the courses
  1091. *
  1092. * @param int Inferior limit
  1093. * @param int Number of items to select
  1094. * @param string Column to order on
  1095. * @param string Order direction
  1096. * @return array Results
  1097. */
  1098. public static function get_course_data_tracking_overview($from, $number_of_items, $column, $direction)
  1099. {
  1100. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  1101. $from = intval($from);
  1102. $number_of_items = intval($number_of_items);
  1103. $sql = "SELECT code AS col0, title AS col1 FROM $main_course_table";
  1104. $sql .= " ORDER BY col$column $direction ";
  1105. $sql .= " LIMIT $from,$number_of_items";
  1106. $result = Database::query($sql);
  1107. $return = array ();
  1108. while ($course = Database::fetch_row($result)) {
  1109. $return[] = $course;
  1110. }
  1111. return $return;
  1112. }
  1113. /**
  1114. * Fills in course reporting data
  1115. *
  1116. * @param integer course code
  1117. * @param array $url_params additional url parameters
  1118. * @param array $row the row information (the other columns)
  1119. * @return string html code
  1120. */
  1121. public static function course_tracking_filter($course_code, $url_params, $row)
  1122. {
  1123. $course_code = $row[0];
  1124. $courseInfo = api_get_course_info($course_code);
  1125. $courseId = $courseInfo['real_id'];
  1126. // the table header
  1127. $return = '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  1128. // database table definition
  1129. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1130. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1131. // getting all the courses of the user
  1132. $sql = "SELECT *
  1133. FROM $tbl_user AS u
  1134. INNER JOIN $tbl_course_rel_user AS cu
  1135. ON cu.user_id = u.user_id
  1136. WHERE cu.c_id = '".$courseId."'";
  1137. $result = Database::query($sql);
  1138. $time_spent = 0;
  1139. $progress = 0;
  1140. $nb_progress_lp = 0;
  1141. $score = 0;
  1142. $nb_score_lp = 0;
  1143. $nb_messages = 0;
  1144. $nb_assignments = 0;
  1145. $last_login_date = false;
  1146. $total_score_obtained = 0;
  1147. $total_score_possible = 0;
  1148. $total_questions_answered = 0;
  1149. while ($row = Database::fetch_object($result)) {
  1150. // get time spent in the course and session
  1151. $time_spent += Tracking::get_time_spent_on_the_course($row->user_id, $courseInfo['real_id']);
  1152. $progress_tmp = Tracking::get_avg_student_progress($row->user_id, $course_code, array(), null, true);
  1153. $progress += $progress_tmp[0];
  1154. $nb_progress_lp += $progress_tmp[1];
  1155. $score_tmp = Tracking :: get_avg_student_score($row->user_id, $course_code, array(), null, true);
  1156. if(is_array($score_tmp)) {
  1157. $score += $score_tmp[0];
  1158. $nb_score_lp += $score_tmp[1];
  1159. }
  1160. $nb_messages += Tracking::count_student_messages($row->user_id, $course_code);
  1161. $nb_assignments += Tracking::count_student_assignments($row->user_id, $course_code);
  1162. $last_login_date_tmp = Tracking :: get_last_connection_date_on_the_course($row->user_id, $courseInfo, null, false);
  1163. if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned
  1164. $last_login_date = $last_login_date_tmp;
  1165. } else if($last_login_date_tmp != false && $last_login_date != false) { // TODO: Repeated previous condition. To be cleaned.
  1166. // Find the max and assign it to first_login_date
  1167. if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) {
  1168. $last_login_date = $last_login_date_tmp;
  1169. }
  1170. }
  1171. $exercise_results_tmp = MySpace::exercises_results($row->user_id, $course_code);
  1172. $total_score_obtained += $exercise_results_tmp['score_obtained'];
  1173. $total_score_possible += $exercise_results_tmp['score_possible'];
  1174. $total_questions_answered += $exercise_results_tmp['questions_answered'];
  1175. }
  1176. if($nb_progress_lp > 0) {
  1177. $avg_progress = round($progress / $nb_progress_lp, 2);
  1178. } else {
  1179. $avg_progress = 0;
  1180. }
  1181. if($nb_score_lp > 0) {
  1182. $avg_score = round($score / $nb_score_lp, 2);
  1183. } else {
  1184. $avg_score = '-';
  1185. }
  1186. if($last_login_date) {
  1187. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1188. } else {
  1189. $last_login_date = '-';
  1190. }
  1191. if($total_score_possible > 0) {
  1192. $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2);
  1193. } else {
  1194. $total_score_percentage = 0;
  1195. }
  1196. if($total_score_percentage > 0) {
  1197. $total_score = $total_score_obtained.'/'.$total_score_possible.' ('.$total_score_percentage.' %)';
  1198. } else {
  1199. $total_score = '-';
  1200. }
  1201. $return .= '<tr>';
  1202. // time spent in the course
  1203. $return .= ' <td style="width:164px;">'.api_time_to_hms($time_spent).'</td>';
  1204. // student progress in course
  1205. $return .= ' <td>'.$avg_progress.'</td>';
  1206. // student score
  1207. $return .= ' <td>'.$avg_score.'</td>';
  1208. // student messages
  1209. $return .= ' <td>'.$nb_messages.'</td>';
  1210. // student assignments
  1211. $return .= ' <td>'.$nb_assignments.'</td>';
  1212. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  1213. $return .= '<td width="105px;">'.$total_score.'</td>';
  1214. $return .= '<td>'.$total_questions_answered.'</td>';
  1215. // last connection
  1216. $return .= ' <td>'.$last_login_date.'</td>';
  1217. $return .= '</tr>';
  1218. $return .= '</table>';
  1219. return $return;
  1220. }
  1221. /**
  1222. * This function exports the table that we see in display_tracking_course_overview()
  1223. *
  1224. */
  1225. public static function export_tracking_course_overview()
  1226. {
  1227. // database table definition
  1228. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1229. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1230. // the values of the sortable table
  1231. if ($_GET['tracking_course_overview_page_nr']) {
  1232. $from = $_GET['tracking_course_overview_page_nr'];
  1233. } else {
  1234. $from = 0;
  1235. }
  1236. if ($_GET['tracking_course_overview_column']) {
  1237. $orderby = $_GET['tracking_course_overview_column'];
  1238. } else {
  1239. $orderby = 0;
  1240. }
  1241. if ($_GET['tracking_course_overview_direction']) {
  1242. $direction = $_GET['tracking_course_overview_direction'];
  1243. } else {
  1244. $direction = 'ASC';
  1245. }
  1246. $course_data = MySpace::get_course_data_tracking_overview($from, 1000, $orderby, $direction);
  1247. $csv_content = array();
  1248. // the first line of the csv file with the column headers
  1249. $csv_row = array();
  1250. $csv_row[] = get_lang('Course', '');
  1251. $csv_row[] = get_lang('AvgTimeSpentInTheCourse', '');
  1252. $csv_row[] = get_lang('AvgStudentsProgress', '');
  1253. $csv_row[] = get_lang('AvgCourseScore', '');
  1254. $csv_row[] = get_lang('TotalNumberOfMessages', '');
  1255. $csv_row[] = get_lang('TotalNumberOfAssignments', '');
  1256. $csv_row[] = get_lang('TotalExercisesScoreObtained', '');
  1257. $csv_row[] = get_lang('TotalExercisesScorePossible', '');
  1258. $csv_row[] = get_lang('TotalExercisesAnswered', '');
  1259. $csv_row[] = get_lang('TotalExercisesScorePercentage', '');
  1260. $csv_row[] = get_lang('LatestLogin', '');
  1261. $csv_content[] = $csv_row;
  1262. // the other lines (the data)
  1263. foreach ($course_data as $key => $course) {
  1264. $course_code = $course[0];
  1265. $courseInfo = api_get_course_info($course_code);
  1266. $course_title = $courseInfo['title'];
  1267. $courseId = $courseInfo['real_id'];
  1268. $csv_row = array();
  1269. $csv_row[] = $course_title;
  1270. // getting all the courses of the session
  1271. $sql = "SELECT *
  1272. FROM $tbl_user AS u
  1273. INNER JOIN $tbl_course_rel_user AS cu
  1274. ON cu.user_id = u.user_id
  1275. WHERE cu.c_id = '".$courseId."'";
  1276. $result = Database::query($sql);
  1277. $time_spent = 0;
  1278. $progress = 0;
  1279. $nb_progress_lp = 0;
  1280. $score = 0;
  1281. $nb_score_lp = 0;
  1282. $nb_messages = 0;
  1283. $nb_assignments = 0;
  1284. $last_login_date = false;
  1285. $total_score_obtained = 0;
  1286. $total_score_possible = 0;
  1287. $total_questions_answered = 0;
  1288. while ($row = Database::fetch_object($result)) {
  1289. // get time spent in the course and session
  1290. $time_spent += Tracking::get_time_spent_on_the_course($row->user_id, $courseId);
  1291. $progress_tmp = Tracking::get_avg_student_progress($row->user_id, $course_code, array(), null, true);
  1292. $progress += $progress_tmp[0];
  1293. $nb_progress_lp += $progress_tmp[1];
  1294. $score_tmp = Tracking :: get_avg_student_score($row->user_id, $course_code, array(), null, true);
  1295. if(is_array($score_tmp)) {
  1296. $score += $score_tmp[0];
  1297. $nb_score_lp += $score_tmp[1];
  1298. }
  1299. $nb_messages += Tracking::count_student_messages($row->user_id, $course_code);
  1300. $nb_assignments += Tracking::count_student_assignments($row->user_id, $course_code);
  1301. $last_login_date_tmp = Tracking::get_last_connection_date_on_the_course($row->user_id, $courseInfo, null, false);
  1302. if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned.
  1303. $last_login_date = $last_login_date_tmp;
  1304. } else if($last_login_date_tmp != false && $last_login_date == false) { // TODO: Repeated previous condition. To be cleaned.
  1305. // Find the max and assign it to first_login_date
  1306. if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) {
  1307. $last_login_date = $last_login_date_tmp;
  1308. }
  1309. }
  1310. $exercise_results_tmp = MySpace::exercises_results($row->user_id, $course_code);
  1311. $total_score_obtained += $exercise_results_tmp['score_obtained'];
  1312. $total_score_possible += $exercise_results_tmp['score_possible'];
  1313. $total_questions_answered += $exercise_results_tmp['questions_answered'];
  1314. }
  1315. if($nb_progress_lp > 0) {
  1316. $avg_progress = round($progress / $nb_progress_lp, 2);
  1317. } else {
  1318. $avg_progress = 0;
  1319. }
  1320. if($nb_score_lp > 0) {
  1321. $avg_score = round($score / $nb_score_lp, 2);
  1322. } else {
  1323. $avg_score = '-';
  1324. }
  1325. if($last_login_date) {
  1326. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1327. } else {
  1328. $last_login_date = '-';
  1329. }
  1330. if($total_score_possible > 0) {
  1331. $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2);
  1332. } else {
  1333. $total_score_percentage = 0;
  1334. }
  1335. // time spent in the course
  1336. $csv_row[] = api_time_to_hms($time_spent);
  1337. // student progress in course
  1338. $csv_row[] = $avg_progress;
  1339. // student score
  1340. $csv_row[] = $avg_score;
  1341. // student messages
  1342. $csv_row[] = $nb_messages;
  1343. // student assignments
  1344. $csv_row[] = $nb_assignments;
  1345. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  1346. $csv_row[] = $total_score_obtained;
  1347. $csv_row[] = $total_score_possible;
  1348. $csv_row[] = $total_questions_answered;
  1349. $csv_row[] = $total_score_percentage;
  1350. // last connection
  1351. $csv_row[] = $last_login_date;
  1352. $csv_content[] = $csv_row;
  1353. }
  1354. Export :: arrayToCsv($csv_content, 'reporting_course_overview');
  1355. exit;
  1356. }
  1357. /**
  1358. * Display a sortable table that contains an overview of all the reporting progress of all sessions and all courses the user is subscribed to
  1359. * @author Guillaume Viguier <guillaume@viguierjust.com>
  1360. */
  1361. public static function display_tracking_session_overview()
  1362. {
  1363. //MySpace::display_user_overview_export_options();
  1364. $t_head = ' <table style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  1365. //$t_head .= ' <caption>'.get_lang('CourseInformation').'</caption>';
  1366. $t_head .= '<tr>';
  1367. $t_head .= ' <th width="155px" style="border-left:0;border-bottom:0"><span>'.get_lang('Course').'</span></th>';
  1368. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).'</span></th>';
  1369. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgStudentsProgress'), 6, true).'</span></th>';
  1370. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgCourseScore'), 6, true).'</span></th>';
  1371. //$t_head .= ' <th><div style="width:40px">'.get_lang('AvgExercisesScore').'</div></th>';
  1372. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfMessages'), 6, true).'</span></th>';
  1373. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfAssignments'), 6, true).'</span></th>';
  1374. $t_head .= ' <th width="105px" style="border-bottom:0"><span>'.get_lang('TotalExercisesScoreObtained').'</span></th>';
  1375. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePossible').'</div></th>';
  1376. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalExercisesAnswered'), 6, true).'</span></th>';
  1377. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePercentage').'</div></th>';
  1378. //$t_head .= ' <th><div style="width:60px">'.get_lang('FirstLogin').'</div></th>';
  1379. $t_head .= ' <th style="padding:0;border-bottom:0;border-right:0;"><span>'.get_lang('LatestLogin').'</span></th>';
  1380. $t_head .= ' </tr></table>';
  1381. $addparams = array('view' => 'admin', 'display' => 'sessionoverview');
  1382. $table = new SortableTable('tracking_session_overview', array('MySpace','get_total_number_sessions'), array('MySpace','get_session_data_tracking_overview'), 1);
  1383. $table->additional_parameters = $addparams;
  1384. $table->set_header(0, '', false, null, array('style' => 'display: none'));
  1385. $table->set_header(1, get_lang('Session'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  1386. $table->set_header(2, $t_head, false, array('style' => 'width:90%;border:0;padding:0;font-size:7.5pt;'), array('style' => 'width:90%;padding:0;font-size:7.5pt;'));
  1387. $table->set_column_filter(2, array('MySpace', 'session_tracking_filter'));
  1388. $table->display();
  1389. }
  1390. /**
  1391. * Get the total number of sessions
  1392. *
  1393. * @return integer Total number of sessions
  1394. */
  1395. public static function get_total_number_sessions()
  1396. {
  1397. // database table definition
  1398. $main_session_table = Database :: get_main_table(TABLE_MAIN_SESSION);
  1399. return Database::count_rows($main_session_table);
  1400. }
  1401. /**
  1402. * Get data for the sessions
  1403. *
  1404. * @param int Inferior limit
  1405. * @param int Number of items to select
  1406. * @param string Column to order on
  1407. * @param string Order direction
  1408. * @return array Results
  1409. */
  1410. public static function get_session_data_tracking_overview($from, $number_of_items, $column, $direction)
  1411. {
  1412. //global $_configuration;
  1413. // database table definition
  1414. //$access_url_id = api_get_current_access_url_id();
  1415. //$tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  1416. $main_session_table = Database :: get_main_table(TABLE_MAIN_SESSION);
  1417. /*if ($_configuration['multiple_access_urls']) {
  1418. $condition_multi_url = ", $tbl_url_rel_user as url_user WHERE user.user_id=url_user.user_id AND access_url_id='$access_url_id'";
  1419. }
  1420. global $export_csv;
  1421. if ($export_csv) {
  1422. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  1423. } else {
  1424. $is_western_name_order = api_is_western_name_order();
  1425. }*/
  1426. $sql = "SELECT id AS col0, name AS col1 FROM $main_session_table";
  1427. $sql .= " ORDER BY col$column $direction ";
  1428. $sql .= " LIMIT $from,$number_of_items";
  1429. $result = Database::query($sql);
  1430. $return = array ();
  1431. while ($session = Database::fetch_row($result)) {
  1432. $return[] = $session;
  1433. }
  1434. return $return;
  1435. }
  1436. /**
  1437. * Fills in session reporting data
  1438. *
  1439. * @param integer $user_id the id of the user
  1440. * @param array $url_params additonal url parameters
  1441. * @param array $row the row information (the other columns)
  1442. * @return string html code
  1443. */
  1444. public static function session_tracking_filter($session_id, $url_params, $row)
  1445. {
  1446. $session_id = $row[0];
  1447. // the table header
  1448. $return = '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  1449. /*$return .= ' <tr>';
  1450. $return .= ' <th>'.get_lang('Course').'</th>';
  1451. $return .= ' <th>'.get_lang('AvgTimeSpentInTheCourse').'</th>';
  1452. $return .= ' <th>'.get_lang('AvgStudentsProgress').'</th>';
  1453. $return .= ' <th>'.get_lang('AvgCourseScore').'</th>';
  1454. $return .= ' <th>'.get_lang('AvgExercisesScore').'</th>';
  1455. $return .= ' <th>'.get_lang('AvgMessages').'</th>';
  1456. $return .= ' <th>'.get_lang('AvgAssignments').'</th>';
  1457. $return .= ' <th>'.get_lang('TotalExercisesScoreObtained').'</th>';
  1458. $return .= ' <th>'.get_lang('TotalExercisesScorePossible').'</th>';
  1459. $return .= ' <th>'.get_lang('TotalExercisesAnswered').'</th>';
  1460. $return .= ' <th>'.get_lang('TotalExercisesScorePercentage').'</th>';
  1461. $return .= ' <th>'.get_lang('FirstLogin').'</th>';
  1462. $return .= ' <th>'.get_lang('LatestLogin').'</th>';
  1463. $return .= ' </tr>';*/
  1464. // database table definition
  1465. $tbl_session_rel_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  1466. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  1467. $tbl_session_rel_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1468. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1469. // getting all the courses of the user
  1470. $sql = "SELECT * FROM $tbl_course AS c
  1471. INNER JOIN $tbl_session_rel_course AS sc
  1472. ON sc.c_id = c.id
  1473. WHERE sc.session_id = '".$session_id."';";
  1474. $result = Database::query($sql);
  1475. while ($row = Database::fetch_object($result)) {
  1476. $courseId = $row->c_id;
  1477. $courseInfo = api_get_course_info_by_id($courseId);
  1478. $return .= '<tr>';
  1479. // course code
  1480. $return .= ' <td width="157px" >'.$row->title.'</td>';
  1481. // get the users in the course
  1482. $sql = "SELECT u.user_id
  1483. FROM $tbl_user AS u
  1484. INNER JOIN $tbl_session_rel_course_rel_user AS scu
  1485. ON u.user_id = scu.user_id
  1486. WHERE scu.session_id = '".$session_id."' AND scu.c_id = '".$courseId."'";
  1487. $result_users = Database::query($sql);
  1488. $time_spent = 0;
  1489. $progress = 0;
  1490. $nb_progress_lp = 0;
  1491. $score = 0;
  1492. $nb_score_lp = 0;
  1493. $nb_messages = 0;
  1494. $nb_assignments = 0;
  1495. $last_login_date = false;
  1496. $total_score_obtained = 0;
  1497. $total_score_possible = 0;
  1498. $total_questions_answered = 0;
  1499. while ($row_user = Database::fetch_object($result_users)) {
  1500. // get time spent in the course and session
  1501. $time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $courseId, $session_id);
  1502. $progress_tmp = Tracking::get_avg_student_progress($row_user->user_id, $row->code, array(), $session_id, true);
  1503. $progress += $progress_tmp[0];
  1504. $nb_progress_lp += $progress_tmp[1];
  1505. $score_tmp = Tracking :: get_avg_student_score($row_user->user_id, $row->code, array(), $session_id, true);
  1506. if (is_array($score_tmp)) {
  1507. $score += $score_tmp[0];
  1508. $nb_score_lp += $score_tmp[1];
  1509. }
  1510. $nb_messages += Tracking::count_student_messages($row_user->user_id, $row->code, $session_id);
  1511. $nb_assignments += Tracking::count_student_assignments($row_user->user_id, $row->code, $session_id);
  1512. $last_login_date_tmp = Tracking::get_last_connection_date_on_the_course($row_user->user_id, $courseInfo, $session_id, false);
  1513. if ($last_login_date_tmp != false && $last_login_date == false) {
  1514. // TODO: To be cleaned.
  1515. $last_login_date = $last_login_date_tmp;
  1516. } else if($last_login_date_tmp != false && $last_login_date != false) {
  1517. // TODO: Repeated previous condition! To be cleaned.
  1518. // Find the max and assign it to first_login_date
  1519. if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) {
  1520. $last_login_date = $last_login_date_tmp;
  1521. }
  1522. }
  1523. $exercise_results_tmp = MySpace::exercises_results($row_user->user_id, $row->code, $session_id);
  1524. $total_score_obtained += $exercise_results_tmp['score_obtained'];
  1525. $total_score_possible += $exercise_results_tmp['score_possible'];
  1526. $total_questions_answered += $exercise_results_tmp['questions_answered'];
  1527. }
  1528. if($nb_progress_lp > 0) {
  1529. $avg_progress = round($progress / $nb_progress_lp, 2);
  1530. } else {
  1531. $avg_progress = 0;
  1532. }
  1533. if($nb_score_lp > 0) {
  1534. $avg_score = round($score / $nb_score_lp, 2);
  1535. } else {
  1536. $avg_score = '-';
  1537. }
  1538. if($last_login_date) {
  1539. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1540. } else {
  1541. $last_login_date = '-';
  1542. }
  1543. if($total_score_possible > 0) {
  1544. $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2);
  1545. } else {
  1546. $total_score_percentage = 0;
  1547. }
  1548. if($total_score_percentage > 0) {
  1549. $total_score = $total_score_obtained.'/'.$total_score_possible.' ('.$total_score_percentage.' %)';
  1550. } else {
  1551. $total_score = '-';
  1552. }
  1553. // time spent in the course
  1554. $return .= ' <td><div>'.api_time_to_hms($time_spent).'</div></td>';
  1555. // student progress in course
  1556. $return .= ' <td><div>'.$avg_progress.'</div></td>';
  1557. // student score
  1558. $return .= ' <td><div>'.$avg_score.'</div></td>';
  1559. // student messages
  1560. $return .= ' <td><div>'.$nb_messages.'</div></td>';
  1561. // student assignments
  1562. $return .= ' <td><div>'.$nb_assignments.'</div></td>';
  1563. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  1564. $return .= '<td width="105px;">'.$total_score.'</td>';
  1565. $return .= '<td>'.$total_questions_answered.'</td>';
  1566. // last connection
  1567. $return .= ' <td><div>'.$last_login_date.'</div></td>';
  1568. $return .= '<tr>';
  1569. }
  1570. $return .= '</table>';
  1571. return $return;
  1572. }
  1573. /**
  1574. * This function exports the table that we see in display_tracking_session_overview()
  1575. *
  1576. */
  1577. public static function export_tracking_session_overview()
  1578. {
  1579. // database table definition
  1580. $tbl_session_rel_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  1581. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  1582. $tbl_session_rel_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1583. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1584. // the values of the sortable table
  1585. if ($_GET['tracking_session_overview_page_nr']) {
  1586. $from = $_GET['tracking_session_overview_page_nr'];
  1587. } else {
  1588. $from = 0;
  1589. }
  1590. if ($_GET['tracking_session_overview_column']) {
  1591. $orderby = $_GET['tracking_session_overview_column'];
  1592. } else {
  1593. $orderby = 0;
  1594. }
  1595. if ($_GET['tracking_session_overview_direction']) {
  1596. $direction = $_GET['tracking_session_overview_direction'];
  1597. } else {
  1598. $direction = 'ASC';
  1599. }
  1600. $session_data = MySpace::get_session_data_tracking_overview($from, 1000, $orderby, $direction);
  1601. $csv_content = array();
  1602. // the first line of the csv file with the column headers
  1603. $csv_row = array();
  1604. $csv_row[] = get_lang('Session');
  1605. $csv_row[] = get_lang('Course', '');
  1606. $csv_row[] = get_lang('AvgTimeSpentInTheCourse', '');
  1607. $csv_row[] = get_lang('AvgStudentsProgress', '');
  1608. $csv_row[] = get_lang('AvgCourseScore', '');
  1609. $csv_row[] = get_lang('TotalNumberOfMessages', '');
  1610. $csv_row[] = get_lang('TotalNumberOfAssignments', '');
  1611. $csv_row[] = get_lang('TotalExercisesScoreObtained', '');
  1612. $csv_row[] = get_lang('TotalExercisesScorePossible', '');
  1613. $csv_row[] = get_lang('TotalExercisesAnswered', '');
  1614. $csv_row[] = get_lang('TotalExercisesScorePercentage', '');
  1615. $csv_row[] = get_lang('LatestLogin', '');
  1616. $csv_content[] = $csv_row;
  1617. // the other lines (the data)
  1618. foreach ($session_data as $key => $session) {
  1619. $session_id = $session[0];
  1620. $session_title = $session[1];
  1621. // getting all the courses of the session
  1622. $sql = "SELECT * FROM $tbl_course AS c
  1623. INNER JOIN $tbl_session_rel_course AS sc
  1624. ON sc.c_id = c.id
  1625. WHERE sc.session_id = '".$session_id."';";
  1626. $result = Database::query($sql);
  1627. while ($row = Database::fetch_object($result)) {
  1628. $courseId = $row->c_id;
  1629. $courseInfo = api_get_course_info_by_id($courseId);
  1630. $csv_row = array();
  1631. $csv_row[] = $session_title;
  1632. $csv_row[] = $row->title;
  1633. // get the users in the course
  1634. $sql = "SELECT scu.user_id
  1635. FROM $tbl_user AS u
  1636. INNER JOIN $tbl_session_rel_course_rel_user AS scu
  1637. ON u.user_id = scu.user_id
  1638. WHERE scu.session_id = '".$session_id."' AND scu.c_id = '".$courseId."'";
  1639. $result_users = Database::query($sql);
  1640. $time_spent = 0;
  1641. $progress = 0;
  1642. $nb_progress_lp = 0;
  1643. $score = 0;
  1644. $nb_score_lp = 0;
  1645. $nb_messages = 0;
  1646. $nb_assignments = 0;
  1647. $last_login_date = false;
  1648. $total_score_obtained = 0;
  1649. $total_score_possible = 0;
  1650. $total_questions_answered = 0;
  1651. while($row_user = Database::fetch_object($result_users)) {
  1652. // get time spent in the course and session
  1653. $time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $courseId, $session_id);
  1654. $progress_tmp = Tracking::get_avg_student_progress($row_user->user_id, $row->code, array(), $session_id, true);
  1655. $progress += $progress_tmp[0];
  1656. $nb_progress_lp += $progress_tmp[1];
  1657. $score_tmp = Tracking :: get_avg_student_score($row_user->user_id, $row->code, array(), $session_id, true);
  1658. if (is_array($score_tmp)) {
  1659. $score += $score_tmp[0];
  1660. $nb_score_lp += $score_tmp[1];
  1661. }
  1662. $nb_messages += Tracking::count_student_messages(
  1663. $row_user->user_id,
  1664. $row->code,
  1665. $session_id
  1666. );
  1667. $nb_assignments += Tracking::count_student_assignments(
  1668. $row_user->user_id,
  1669. $row->code,
  1670. $session_id
  1671. );
  1672. $last_login_date_tmp = Tracking:: get_last_connection_date_on_the_course(
  1673. $row_user->user_id,
  1674. $courseInfo,
  1675. $session_id,
  1676. false
  1677. );
  1678. if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned.
  1679. $last_login_date = $last_login_date_tmp;
  1680. } else if($last_login_date_tmp != false && $last_login_date == false) { // TODO: Repeated previous condition. To be cleaned.
  1681. // Find the max and assign it to first_login_date
  1682. if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) {
  1683. $last_login_date = $last_login_date_tmp;
  1684. }
  1685. }
  1686. $exercise_results_tmp = MySpace::exercises_results($row_user->user_id, $row->code, $session_id);
  1687. $total_score_obtained += $exercise_results_tmp['score_obtained'];
  1688. $total_score_possible += $exercise_results_tmp['score_possible'];
  1689. $total_questions_answered += $exercise_results_tmp['questions_answered'];
  1690. }
  1691. if($nb_progress_lp > 0) {
  1692. $avg_progress = round($progress / $nb_progress_lp, 2);
  1693. } else {
  1694. $avg_progress = 0;
  1695. }
  1696. if($nb_score_lp > 0) {
  1697. $avg_score = round($score / $nb_score_lp, 2);
  1698. } else {
  1699. $avg_score = '-';
  1700. }
  1701. if($last_login_date) {
  1702. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1703. } else {
  1704. $last_login_date = '-';
  1705. }
  1706. if($total_score_possible > 0) {
  1707. $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2);
  1708. } else {
  1709. $total_score_percentage = 0;
  1710. }
  1711. if($total_score_percentage > 0) {
  1712. $total_score = $total_score_obtained.'/'.$total_score_possible.' ('.$total_score_percentage.' %)';
  1713. } else {
  1714. $total_score = '-';
  1715. }
  1716. // time spent in the course
  1717. $csv_row[] = api_time_to_hms($time_spent);
  1718. // student progress in course
  1719. $csv_row[] = $avg_progress;
  1720. // student score
  1721. $csv_row[] = $avg_score;
  1722. // student messages
  1723. $csv_row[] = $nb_messages;
  1724. // student assignments
  1725. $csv_row[] = $nb_assignments;
  1726. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  1727. $csv_row[] = $total_score_obtained;
  1728. $csv_row[] = $total_score_possible;
  1729. $csv_row[] = $total_questions_answered;
  1730. $csv_row[] = $total_score_percentage;
  1731. // last connection
  1732. $csv_row[] = $last_login_date;
  1733. $csv_content[] = $csv_row;
  1734. }
  1735. }
  1736. Export :: arrayToCsv($csv_content, 'reporting_session_overview');
  1737. exit;
  1738. }
  1739. /**
  1740. * Get general information about the exercise performance of the user
  1741. * the total obtained score (all the score on all the questions)
  1742. * the maximum score that could be obtained
  1743. * the number of questions answered
  1744. * the success percentage
  1745. * @param integer $user_id the id of the user
  1746. * @param string $course_code the course code
  1747. * @return array
  1748. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1749. * @version Dokeos 1.8.6
  1750. * @since November 2008
  1751. */
  1752. public static function exercises_results($user_id, $course_code, $session_id = false)
  1753. {
  1754. $questions_answered = 0;
  1755. $courseId = api_get_course_int_id($course_code);
  1756. $sql = 'SELECT exe_result , exe_weighting
  1757. FROM '.Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES)."
  1758. WHERE c_id = ' . $courseId . '
  1759. AND exe_user_id = '".intval($user_id)."'";
  1760. if($session_id !== false) {
  1761. $sql .= " AND session_id = '".$session_id."' ";
  1762. }
  1763. $result = Database::query($sql);
  1764. $score_obtained = 0;
  1765. $score_possible = 0;
  1766. $questions_answered = 0;
  1767. while ($row = Database::fetch_array($result)) {
  1768. $score_obtained += $row['exe_result'];
  1769. $score_possible += $row['exe_weighting'];
  1770. $questions_answered ++;
  1771. }
  1772. if ($score_possible != 0) {
  1773. $percentage = round(($score_obtained / $score_possible * 100), 2);
  1774. } else {
  1775. $percentage = null;
  1776. }
  1777. return array(
  1778. 'score_obtained' => $score_obtained,
  1779. 'score_possible' => $score_possible,
  1780. 'questions_answered' => $questions_answered,
  1781. 'percentage' => $percentage
  1782. );
  1783. }
  1784. /**
  1785. * This function exports the table that we see in display_tracking_user_overview()
  1786. *
  1787. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1788. * @version Dokeos 1.8.6
  1789. * @since October 2008
  1790. */
  1791. public static function export_tracking_user_overview()
  1792. {
  1793. // database table definitions
  1794. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1795. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  1796. $sort_by_first_name = api_sort_by_first_name();
  1797. // the values of the sortable table
  1798. if ($_GET['tracking_user_overview_page_nr']) {
  1799. $from = $_GET['tracking_user_overview_page_nr'];
  1800. } else {
  1801. $from = 0;
  1802. }
  1803. if ($_GET['tracking_user_overview_column']) {
  1804. $orderby = $_GET['tracking_user_overview_column'];
  1805. } else {
  1806. $orderby = 0;
  1807. }
  1808. if ($is_western_name_order != api_is_western_name_order() && ($orderby == 1 || $orderby == 2)) {
  1809. // Swapping the sorting column if name order for export is different than the common name order.
  1810. $orderby = 3 - $orderby;
  1811. }
  1812. if ($_GET['tracking_user_overview_direction']) {
  1813. $direction = $_GET['tracking_user_overview_direction'];
  1814. } else {
  1815. $direction = 'ASC';
  1816. }
  1817. $user_data = MySpace::get_user_data_tracking_overview($from, 1000, $orderby, $direction);
  1818. // the first line of the csv file with the column headers
  1819. $csv_row = array();
  1820. $csv_row[] = get_lang('OfficialCode');
  1821. if ($is_western_name_order) {
  1822. $csv_row[] = get_lang('FirstName', '');
  1823. $csv_row[] = get_lang('LastName', '');
  1824. } else {
  1825. $csv_row[] = get_lang('LastName', '');
  1826. $csv_row[] = get_lang('FirstName', '');
  1827. }
  1828. $csv_row[] = get_lang('LoginName');
  1829. $csv_row[] = get_lang('CourseCode');
  1830. // the additional user defined fields (only those that were selected to be exported)
  1831. $fields = UserManager::get_extra_fields(0, 50, 5, 'ASC');
  1832. if (is_array($_SESSION['additional_export_fields'])) {
  1833. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  1834. $csv_row[] = $fields[$extra_field_export][3];
  1835. $field_names_to_be_exported[] = 'extra_'.$fields[$extra_field_export][1];
  1836. }
  1837. }
  1838. $csv_row[] = get_lang('AvgTimeSpentInTheCourse', '');
  1839. $csv_row[] = get_lang('AvgStudentsProgress', '');
  1840. $csv_row[] = get_lang('AvgCourseScore', '');
  1841. $csv_row[] = get_lang('AvgExercisesScore', '');
  1842. $csv_row[] = get_lang('AvgMessages', '');
  1843. $csv_row[] = get_lang('AvgAssignments', '');
  1844. $csv_row[] = get_lang('TotalExercisesScoreObtained', '');
  1845. $csv_row[] = get_lang('TotalExercisesScorePossible', '');
  1846. $csv_row[] = get_lang('TotalExercisesAnswered', '');
  1847. $csv_row[] = get_lang('TotalExercisesScorePercentage', '');
  1848. $csv_row[] = get_lang('FirstLogin', '');
  1849. $csv_row[] = get_lang('LatestLogin', '');
  1850. $csv_content[] = $csv_row;
  1851. // the other lines (the data)
  1852. foreach ($user_data as $key => $user) {
  1853. // getting all the courses of the user
  1854. $sql = "SELECT * FROM $tbl_course_user
  1855. WHERE user_id = '".intval($user[4])."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." ";
  1856. $result = Database::query($sql);
  1857. while ($row = Database::fetch_row($result)) {
  1858. $courseInfo = api_get_course_info($row['course_code']);
  1859. $courseId = $courseInfo['real_id'];
  1860. $csv_row = array();
  1861. // user official code
  1862. $csv_row[] = $user[0];
  1863. // user first|last name
  1864. $csv_row[] = $user[1];
  1865. // user last|first name
  1866. $csv_row[] = $user[2];
  1867. // user login name
  1868. $csv_row[] = $user[3];
  1869. // course code
  1870. $csv_row[] = $row[0];
  1871. // the additional defined user fields
  1872. $extra_fields = MySpace::get_user_overview_export_extra_fields($user[4]);
  1873. if (is_array($field_names_to_be_exported)) {
  1874. foreach ($field_names_to_be_exported as $key => $extra_field_export) {
  1875. $csv_row[] = $extra_fields[$extra_field_export];
  1876. }
  1877. }
  1878. // time spent in the course
  1879. $csv_row[] = api_time_to_hms(Tracking::get_time_spent_on_the_course ($user[4], $courseId));
  1880. // student progress in course
  1881. $csv_row[] = round(Tracking::get_avg_student_progress ($user[4], $row[0]), 2);
  1882. // student score
  1883. $csv_row[] = round(Tracking::get_avg_student_score($user[4], $row[0]), 2);
  1884. // student tes score
  1885. $csv_row[] = round(Tracking::get_avg_student_exercise_score($user[4], $row[0]), 2);
  1886. // student messages
  1887. $csv_row[] = Tracking::count_student_messages($user[4], $row[0]);
  1888. // student assignments
  1889. $csv_row[] = Tracking::count_student_assignments ($user[4], $row[0]);
  1890. // student exercises results
  1891. $exercises_results = MySpace::exercises_results($user[4], $row[0]);
  1892. $csv_row[] = $exercises_results['score_obtained'];
  1893. $csv_row[] = $exercises_results['score_possible'];
  1894. $csv_row[] = $exercises_results['questions_answered'];
  1895. $csv_row[] = $exercises_results['percentage'];
  1896. // first connection
  1897. $csv_row[] = Tracking::get_first_connection_date_on_the_course ($user[4], $courseId);
  1898. // last connection
  1899. $csv_row[] = strip_tags(Tracking::get_last_connection_date_on_the_course($user[4], $courseInfo));
  1900. $csv_content[] = $csv_row;
  1901. }
  1902. }
  1903. Export :: arrayToCsv($csv_content, 'reporting_user_overview');
  1904. exit;
  1905. }
  1906. /**
  1907. * Get data for courses list in sortable with pagination
  1908. * @return array
  1909. */
  1910. public static function get_course_data($from, $number_of_items, $column, $direction)
  1911. {
  1912. global $courses, $csv_content, $charset, $session_id;
  1913. // definition database tables
  1914. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  1915. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1916. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1917. $course_data = array();
  1918. $courses_code = array_keys($courses);
  1919. foreach ($courses_code as &$code) {
  1920. $code = "'$code'";
  1921. }
  1922. // get all courses with limit
  1923. $sql = "SELECT course.code as col1, course.title as col2
  1924. FROM $tbl_course course
  1925. WHERE course.code IN (".implode(',',$courses_code).")";
  1926. if (!in_array($direction, array('ASC','DESC'))) $direction = 'ASC';
  1927. $column = intval($column);
  1928. $from = intval($from);
  1929. $number_of_items = intval($number_of_items);
  1930. $sql .= " ORDER BY col$column $direction ";
  1931. $sql .= " LIMIT $from,$number_of_items";
  1932. $res = Database::query($sql);
  1933. while ($row_course = Database::fetch_row($res)) {
  1934. $course_code = $row_course[0];
  1935. $courseInfo = api_get_course_info($course_code);
  1936. $courseId = $courseInfo['real_id'];
  1937. $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0;
  1938. // students directly subscribed to the course
  1939. if (empty($session_id)) {
  1940. $sql = "SELECT user_id
  1941. FROM $tbl_course_user as course_rel_user
  1942. WHERE
  1943. course_rel_user.status='5' AND
  1944. course_rel_user.c_id = '$courseId'";
  1945. } else {
  1946. $sql = "SELECT user_id FROM $tbl_session_course_user srcu
  1947. WHERE
  1948. c_id = '$courseId' AND
  1949. session_id = '$session_id' AND
  1950. status<>2";
  1951. }
  1952. $rs = Database::query($sql);
  1953. $users = array();
  1954. while ($row = Database::fetch_array($rs)) {
  1955. $users[] = $row['user_id'];
  1956. }
  1957. if (count($users) > 0) {
  1958. $nb_students_in_course = count($users);
  1959. $avg_assignments_in_course = Tracking::count_student_assignments($users, $course_code, $session_id);
  1960. $avg_messages_in_course = Tracking::count_student_messages($users, $course_code, $session_id);
  1961. $avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code, array(), $session_id);
  1962. $avg_score_in_course = Tracking::get_avg_student_score($users, $course_code, array(), $session_id);
  1963. $avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code, 0, $session_id);
  1964. $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $courseInfo['real_id'], $session_id);
  1965. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
  1966. if (is_numeric($avg_score_in_course)) {
  1967. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2);
  1968. }
  1969. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  1970. } else {
  1971. $avg_time_spent_in_course = null;
  1972. $avg_progress_in_course = null;
  1973. $avg_score_in_course = null;
  1974. $avg_score_in_exercise = null;
  1975. $avg_messages_in_course = null;
  1976. $avg_assignments_in_course = null;
  1977. }
  1978. $table_row = array();
  1979. $table_row[] = $row_course[1];
  1980. $table_row[] = $nb_students_in_course;
  1981. $table_row[] = $avg_time_spent_in_course;
  1982. $table_row[] = is_null($avg_progress_in_course) ? '' : $avg_progress_in_course.'%';
  1983. $table_row[] = is_null($avg_score_in_course) ? '' : $avg_score_in_course.'%';
  1984. $table_row[] = is_null($avg_score_in_exercise) ? '' : $avg_score_in_exercise.'%';
  1985. $table_row[] = $avg_messages_in_course;
  1986. $table_row[] = $avg_assignments_in_course;
  1987. //set the "from" value to know if I access the Reporting by the chamilo tab or the course link
  1988. $table_row[] = '<center><a href="../../tracking/courseLog.php?cidReq=' .$course_code.'&from=myspace&id_session='.$session_id.'">
  1989. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
  1990. </center>';
  1991. $csv_content[] = array(
  1992. api_html_entity_decode($row_course[1], ENT_QUOTES, $charset),
  1993. $nb_students_in_course,
  1994. $avg_time_spent_in_course,
  1995. is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%',
  1996. is_null($avg_score_in_course) ? null : is_numeric($avg_score_in_course) ? $avg_score_in_course.'%' : $avg_score_in_course ,
  1997. is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%',
  1998. $avg_messages_in_course,
  1999. $avg_assignments_in_course,
  2000. );
  2001. $course_data[] = $table_row;
  2002. }
  2003. return $course_data;
  2004. }
  2005. /**
  2006. * get the numer of users of the platform
  2007. *
  2008. * @return integer
  2009. *
  2010. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  2011. * @version Dokeos 1.8.6
  2012. * @since October 2008
  2013. */
  2014. public static function get_number_of_users_tracking_overview()
  2015. {
  2016. // database table definition
  2017. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  2018. return Database::count_rows($main_user_table);
  2019. }
  2020. /**
  2021. * get all the data for the sortable table of the reporting progress of all users and all the courses the user is subscribed to.
  2022. *
  2023. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  2024. * @version Dokeos 1.8.6
  2025. * @since October 2008
  2026. */
  2027. public static function get_user_data_tracking_overview($from, $number_of_items, $column, $direction)
  2028. {
  2029. // database table definition
  2030. $access_url_id = api_get_current_access_url_id();
  2031. $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  2032. $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
  2033. $condition_multi_url = null;
  2034. if (api_is_multiple_url_enabled()) {
  2035. $condition_multi_url = ", $tbl_url_rel_user as url_user
  2036. WHERE user.user_id=url_user.user_id AND access_url_id='$access_url_id'";
  2037. }
  2038. global $export_csv;
  2039. if ($export_csv) {
  2040. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  2041. } else {
  2042. $is_western_name_order = api_is_western_name_order();
  2043. }
  2044. $sql = "SELECT
  2045. official_code AS col0,
  2046. ".($is_western_name_order ? "
  2047. firstname AS col1,
  2048. lastname AS col2,
  2049. " : "
  2050. lastname AS col1,
  2051. firstname AS col2,
  2052. ").
  2053. "username AS col3,
  2054. user.user_id AS col4
  2055. FROM
  2056. $main_user_table as user $condition_multi_url
  2057. ";
  2058. $sql .= " ORDER BY col$column $direction ";
  2059. $sql .= " LIMIT $from,$number_of_items";
  2060. $result = Database::query($sql);
  2061. $return = array ();
  2062. while ($user = Database::fetch_row($result)) {
  2063. $return[] = $user;
  2064. }
  2065. return $return;
  2066. }
  2067. /**
  2068. * Get all information that the user with user_id = $user_data has
  2069. * entered in the additionally defined profile fields
  2070. * @param integer $user_id the id of the user
  2071. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  2072. * @version Dokeos 1.8.6
  2073. * @since November 2008
  2074. */
  2075. public static function get_user_overview_export_extra_fields($user_id)
  2076. {
  2077. // include the user manager
  2078. $extra_data = UserManager::get_extra_user_data($user_id, true);
  2079. return $extra_data;
  2080. }
  2081. /**
  2082. * Checks if a username exist in the DB otherwise it create a "double"
  2083. * i.e. if we look into for jmontoya but the user's name already exist we create the user jmontoya2
  2084. * the return array will be array(username=>'jmontoya', sufix='2')
  2085. * @param string firstname
  2086. * @param string lastname
  2087. * @param string username
  2088. * @return array with the username, the sufix
  2089. * @author Julio Montoya Armas
  2090. */
  2091. public static function make_username($firstname, $lastname, $username, $language = null, $encoding = null)
  2092. {
  2093. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  2094. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2095. // if username exist
  2096. if (!UserManager::is_username_available($username) || empty($username)) {
  2097. $i = 0;
  2098. while (1) {
  2099. if ($i == 0) {
  2100. $sufix = '';
  2101. } else {
  2102. $sufix = $i;
  2103. }
  2104. $desired_username = UserManager::create_username($firstname, $lastname, $language, $encoding);
  2105. if (UserManager::is_username_available($desired_username.$sufix)) {
  2106. break;
  2107. } else {
  2108. $i++;
  2109. }
  2110. }
  2111. $username_array = array('username' => $desired_username , 'sufix' => $sufix);
  2112. return $username_array;
  2113. } else {
  2114. $username_array = array('username' => $username, 'sufix' => '');
  2115. return $username_array;
  2116. }
  2117. }
  2118. /**
  2119. * Checks if there are repeted users in a given array
  2120. * @param array $usernames list of the usernames in the uploaded file
  2121. * @param array $user_array['username'] and $user_array['sufix'] where sufix is the number part in a login i.e -> jmontoya2
  2122. * @return array with the $usernames array and the $user_array array
  2123. * @author Julio Montoya Armas
  2124. */
  2125. public static function check_user_in_array($usernames, $user_array)
  2126. {
  2127. $user_list = array_keys($usernames);
  2128. $username = $user_array['username'].$user_array['sufix'];
  2129. if (in_array($username, $user_list)) {
  2130. $user_array['sufix'] += $usernames[$username];
  2131. $usernames[$username]++;
  2132. } else {
  2133. $usernames[$username] = 1;
  2134. }
  2135. $result_array = array($usernames, $user_array);
  2136. return $result_array;
  2137. }
  2138. /**
  2139. * Checks whether a username has been already subscribed in a session.
  2140. * @param string a given username
  2141. * @param array the array with the course list id
  2142. * @param the session id
  2143. * @return 0 if the user is not subscribed otherwise it returns the user_id of the given username
  2144. * @author Julio Montoya
  2145. */
  2146. public static function user_available_in_session($username, $course_list, $id_session)
  2147. {
  2148. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  2149. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2150. $id_session = intval($id_session);
  2151. $username = Database::escape_string($username);
  2152. foreach ($course_list as $courseId) {
  2153. $courseId = intval($courseId);
  2154. $sql = " SELECT u.user_id FROM $tbl_session_rel_course_rel_user rel
  2155. INNER JOIN $table_user u
  2156. ON (rel.user_id = u.user_id)
  2157. WHERE
  2158. rel.session_id='$id_session' AND
  2159. u.status='5' AND
  2160. u.username ='$username' AND
  2161. rel.c_id='$courseId'";
  2162. $rs = Database::query($sql);
  2163. if (Database::num_rows($rs) > 0) {
  2164. return Database::result($rs, 0, 0);
  2165. } else {
  2166. return 0;
  2167. }
  2168. }
  2169. }
  2170. /**
  2171. * This function checks whether some users in the uploaded file
  2172. * repeated and creates unique usernames if necesary.
  2173. * A case: Within the file there is an user repeted twice (Julio Montoya / Julio Montoya)
  2174. * and the username fields are empty.
  2175. * Then, this function would create unique usernames based on the first and the last name.
  2176. * Two users wiould be created - jmontoya and jmontoya2.
  2177. * Of course, if in the database there is a user with the name jmontoya,
  2178. * the newly created two users registered would be jmontoya2 and jmontoya3.
  2179. * @param $users list of users
  2180. * @author Julio Montoya Armas
  2181. */
  2182. function check_all_usernames($users, $course_list, $id_session)
  2183. {
  2184. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  2185. $usernames = array();
  2186. $new_users = array();
  2187. foreach ($users as $index => $user) {
  2188. $desired_username = array();
  2189. if (empty($user['UserName'])) {
  2190. $desired_username = MySpace::make_username($user['FirstName'], $user['LastName'], '');
  2191. $pre_username = $desired_username['username'].$desired_username['sufix'];
  2192. $user['UserName'] = $pre_username;
  2193. $user['create'] = '1';
  2194. } else {
  2195. if (UserManager::is_username_available($user['UserName'])) {
  2196. $desired_username = MySpace::make_username($user['FirstName'], $user['LastName'], $user['UserName']);
  2197. $user['UserName'] = $desired_username['username'].$desired_username['sufix'];
  2198. $user['create'] = '1';
  2199. } else {
  2200. $is_session_avail = MySpace::user_available_in_session($user['UserName'], $course_list, $id_session);
  2201. if ($is_session_avail == 0) {
  2202. $user_name = $user['UserName'];
  2203. $sql_select = "SELECT user_id FROM $table_user WHERE username ='$user_name' ";
  2204. $rs = Database::query($sql_select);
  2205. $user['create'] = Database::result($rs, 0, 0); // This should be the ID because the user exists.
  2206. } else {
  2207. $user['create'] = $is_session_avail;
  2208. }
  2209. }
  2210. }
  2211. // Usernames is the current list of users in the file.
  2212. $result_array = MySpace::check_user_in_array($usernames, $desired_username);
  2213. $usernames = $result_array[0];
  2214. $desired_username = $result_array[1];
  2215. $user['UserName'] = $desired_username['username'].$desired_username['sufix'];
  2216. $new_users[] = $user;
  2217. }
  2218. return $new_users;
  2219. }
  2220. /**
  2221. * This functions checks whether there are users that are already
  2222. * registered in the DB by different creator than the current coach.
  2223. * @param string a given username
  2224. * @param array the array with the course list ids
  2225. * @param the session id
  2226. * @author Julio Montoya Armas
  2227. */
  2228. public function get_user_creator($users)
  2229. {
  2230. $errors = array();
  2231. foreach ($users as $index => $user) {
  2232. // database table definition
  2233. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  2234. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2235. $username = Database::escape_string($user['UserName']);
  2236. $sql = "SELECT creator_id FROM $table_user WHERE username='$username' ";
  2237. $rs = Database::query($sql);
  2238. $creator_id = Database::result($rs, 0, 0);
  2239. // check if we are the creators or not
  2240. if ($creator_id != '') {
  2241. if ($creator_id != api_get_user_id()) {
  2242. $user['error'] = get_lang('UserAlreadyRegisteredByOtherCreator');
  2243. $errors[] = $user;
  2244. }
  2245. }
  2246. }
  2247. return $errors;
  2248. }
  2249. /**
  2250. * Validates imported data.
  2251. * @param list of users
  2252. */
  2253. function validate_data($users, $id_session = null) {
  2254. $errors = array();
  2255. $usernames = array();
  2256. $new_users = array();
  2257. foreach ($users as $index => $user) {
  2258. // 1. Check whether mandatory fields are set.
  2259. $mandatory_fields = array('LastName', 'FirstName');
  2260. if (api_get_setting('registration', 'email') == 'true') {
  2261. $mandatory_fields[] = 'Email';
  2262. }
  2263. foreach ($mandatory_fields as $key => $field) {
  2264. if (!isset ($user[$field]) || strlen($user[$field]) == 0) {
  2265. $user['error'] = get_lang($field.'Mandatory');
  2266. $errors[] = $user;
  2267. }
  2268. }
  2269. // 2. Check whether the username is too long.
  2270. if (UserManager::is_username_too_long($user['UserName'])) {
  2271. $user['error'] = get_lang('UserNameTooLong');
  2272. $errors[] = $user;
  2273. }
  2274. $user['UserName'] = trim($user['UserName']);
  2275. if (empty($user['UserName'])) {
  2276. $user['UserName'] = UserManager::create_username($user['FirstName'], $user['LastName']);
  2277. }
  2278. $new_users[] = $user;
  2279. }
  2280. $results = array('errors' => $errors, 'users' => $new_users);
  2281. return $results;
  2282. }
  2283. /**
  2284. * Adds missing user-information (which isn't required, like password, etc).
  2285. */
  2286. function complete_missing_data($user) {
  2287. // 1. Generate a password if it is necessary.
  2288. if (!isset ($user['Password']) || strlen($user['Password']) == 0) {
  2289. $user['Password'] = api_generate_password();
  2290. }
  2291. return $user;
  2292. }
  2293. /**
  2294. * Saves imported data.
  2295. */
  2296. public function save_data($users, $course_list, $id_session)
  2297. {
  2298. $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
  2299. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  2300. $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  2301. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  2302. $id_session = intval($id_session);
  2303. $sendMail = $_POST['sendMail'] ? 1 : 0;
  2304. // Adding users to the platform.
  2305. $new_users = array();
  2306. foreach ($users as $index => $user) {
  2307. $user = MySpace::complete_missing_data($user);
  2308. // coach only will registered users
  2309. $default_status = STUDENT;
  2310. if ($user['create'] == COURSEMANAGER) {
  2311. $user['id'] = UserManager:: create_user(
  2312. $user['FirstName'],
  2313. $user['LastName'],
  2314. $default_status,
  2315. $user['Email'],
  2316. $user['UserName'],
  2317. $user['Password'],
  2318. $user['OfficialCode'],
  2319. api_get_setting('PlatformLanguage'),
  2320. $user['PhoneNumber'],
  2321. ''
  2322. );
  2323. $user['added_at_platform'] = 1;
  2324. } else {
  2325. $user['id'] = $user['create'];
  2326. $user['added_at_platform'] = 0;
  2327. }
  2328. $new_users[] = $user;
  2329. }
  2330. // Update user list.
  2331. $users = $new_users;
  2332. // Inserting users.
  2333. $super_list = array();
  2334. foreach ($course_list as $enreg_course) {
  2335. $nbr_users = 0;
  2336. $new_users = array();
  2337. $enreg_course = Database::escape_string($enreg_course);
  2338. foreach ($users as $index => $user) {
  2339. $userid = intval($user['id']);
  2340. $sql = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(session_id, c_id, user_id)
  2341. VALUES('$id_session','$enreg_course','$userid')";
  2342. $course_session = array('course' => $enreg_course, 'added' => 1);
  2343. $result = Database::query($sql);
  2344. if (Database::affected_rows($result)) {
  2345. $nbr_users++;
  2346. }
  2347. $new_users[] = $user;
  2348. }
  2349. $super_list[] = $new_users;
  2350. //update the nbr_users field
  2351. $sql_select = "SELECT COUNT(user_id) as nbUsers FROM $tbl_session_rel_course_rel_user
  2352. WHERE session_id='$id_session' AND c_id='$enreg_course'";
  2353. $rs = Database::query($sql_select);
  2354. list($nbr_users) = Database::fetch_array($rs);
  2355. $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users=$nbr_users
  2356. WHERE session_id='$id_session' AND c_id='$enreg_course'";
  2357. Database::query($sql_update);
  2358. $sql_update = "UPDATE $tbl_session SET nbr_users= '$nbr_users' WHERE id='$id_session'";
  2359. Database::query($sql_update);
  2360. }
  2361. $new_users = array();
  2362. foreach ($users as $index => $user) {
  2363. $userid = $user['id'];
  2364. $sql_insert = "INSERT IGNORE INTO $tbl_session_rel_user(session_id, user_id, registered_at)
  2365. VALUES ('$id_session','$userid', '" . api_get_utc_datetime() . "')";
  2366. Database::query($sql_insert);
  2367. $user['added_at_session'] = 1;
  2368. $new_users[] = $user;
  2369. }
  2370. $users = $new_users;
  2371. $registered_users = get_lang('FileImported').'<br /> Import file results : <br />';
  2372. // Sending emails.
  2373. $addedto = '';
  2374. if ($sendMail) {
  2375. $i = 0;
  2376. foreach ($users as $index => $user) {
  2377. $emailsubject = '['.api_get_setting('siteName').'] '.get_lang('YourReg').' '.api_get_setting('siteName');
  2378. $emailbody = get_lang('Dear').' '.
  2379. api_get_person_name($user['FirstName'], $user['LastName']).",\n\n".
  2380. get_lang('YouAreReg')." ".api_get_setting('siteName')." ".get_lang('WithTheFollowingSettings')."\n\n".
  2381. get_lang('Username')." : $user[UserName]\n".
  2382. get_lang('Pass')." : $user[Password]\n\n".
  2383. get_lang('Address')." ".api_get_setting('siteName')." ".get_lang('Is')." : ".api_get_path(WEB_PATH)." \n\n".
  2384. get_lang('Problem')."\n\n".
  2385. get_lang('SignatureFormula').",\n\n".
  2386. api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname'))."\n".
  2387. get_lang('Manager')." ".api_get_setting('siteName')."\nT. ".
  2388. api_get_setting('administratorTelephone')."\n".get_lang('Email')." : ".api_get_setting('emailAdministrator');
  2389. api_mail_html(
  2390. api_get_person_name($user['FirstName'], $user['LastName'], null, PERSON_NAME_EMAIL_ADDRESS),
  2391. $user['Email'],
  2392. $emailsubject,
  2393. $emailbody
  2394. );
  2395. $userInfo = api_get_user_info($user['id']);
  2396. if (($user['added_at_platform'] == 1 && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) {
  2397. if ($user['added_at_platform'] == 1) {
  2398. $addedto = get_lang('UserCreatedPlatform');
  2399. } else {
  2400. $addedto = ' ';
  2401. }
  2402. if ($user['added_at_session'] == 1) {
  2403. $addedto .= get_lang('UserInSession');
  2404. }
  2405. } else {
  2406. $addedto = get_lang('UserNotAdded');
  2407. }
  2408. $registered_users .= UserManager::getUserProfileLink($userInfo)." - ".$addedto.'<br />';
  2409. }
  2410. } else {
  2411. $i = 0;
  2412. foreach ($users as $index => $user) {
  2413. $userInfo = api_get_user_info($user['id']);
  2414. if (($user['added_at_platform'] == 1 && $user['added_at_session'] == 1) || $user['added_at_session'] == 1) {
  2415. if ($user['added_at_platform'] == 1) {
  2416. $addedto = get_lang('UserCreatedPlatform');
  2417. } else {
  2418. $addedto = ' ';
  2419. }
  2420. if ($user['added_at_session'] == 1) {
  2421. $addedto .= ' '.get_lang('UserInSession');
  2422. }
  2423. } else {
  2424. $addedto = get_lang('UserNotAdded');
  2425. }
  2426. $registered_users .= "<a href=\"../user/userInfo.php?uInfo=".$user['id']."\">".api_get_person_name($user['FirstName'], $user['LastName'])."</a> - ".$addedto.'<br />';
  2427. }
  2428. }
  2429. header('Location: course.php?id_session='.$id_session.'&action=show_message&message='.urlencode($registered_users));
  2430. exit;
  2431. }
  2432. /**
  2433. * Reads CSV-file.
  2434. * @param string $file Path to the CSV-file
  2435. * @return array All userinformation read from the file
  2436. */
  2437. function parse_csv_data($file) {
  2438. $users = Import :: csvToArray($file);
  2439. foreach ($users as $index => $user) {
  2440. if (isset ($user['Courses'])) {
  2441. $user['Courses'] = explode('|', trim($user['Courses']));
  2442. }
  2443. $users[$index] = $user;
  2444. }
  2445. return $users;
  2446. }
  2447. /**
  2448. * XML-parser: the handler at the beginning of element.
  2449. */
  2450. function element_start($parser, $data) {
  2451. $data = api_utf8_decode($data);
  2452. global $user;
  2453. global $current_tag;
  2454. switch ($data) {
  2455. case 'Contact' :
  2456. $user = array ();
  2457. break;
  2458. default :
  2459. $current_tag = $data;
  2460. }
  2461. }
  2462. /**
  2463. * XML-parser: the handler at the end of element.
  2464. */
  2465. function element_end($parser, $data) {
  2466. $data = api_utf8_decode($data);
  2467. global $user;
  2468. global $users;
  2469. global $current_value;
  2470. global $purification_option_for_usernames;
  2471. $user[$data] = $current_value;
  2472. switch ($data) {
  2473. case 'Contact' :
  2474. $user['UserName'] = UserManager::purify_username($user['UserName'], $purification_option_for_usernames);
  2475. $users[] = $user;
  2476. break;
  2477. default :
  2478. $user[$data] = $current_value;
  2479. break;
  2480. }
  2481. }
  2482. /**
  2483. * XML-parser: the handler for character data.
  2484. */
  2485. function character_data($parser, $data) {
  2486. $data = trim(api_utf8_decode($data));
  2487. global $current_value;
  2488. $current_value = $data;
  2489. }
  2490. /**
  2491. * Reads XML-file.
  2492. * @param string $file Path to the XML-file
  2493. * @return array All userinformation read from the file
  2494. */
  2495. function parse_xml_data($file) {
  2496. global $current_tag;
  2497. global $current_value;
  2498. global $user;
  2499. global $users;
  2500. $users = array ();
  2501. $parser = xml_parser_create('UTF-8');
  2502. xml_set_element_handler($parser, array('MySpace','element_start'), array('MySpace','element_end'));
  2503. xml_set_character_data_handler($parser, "character_data");
  2504. xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
  2505. xml_parse($parser, api_utf8_encode_xml(file_get_contents($file)));
  2506. xml_parser_free($parser);
  2507. return $users;
  2508. }
  2509. }
  2510. /**
  2511. * @param $user_id
  2512. * @param int $courseId
  2513. * @param null $start_date
  2514. * @param null $end_date
  2515. * @return array
  2516. */
  2517. function get_stats($user_id, $courseId, $start_date = null, $end_date = null)
  2518. {
  2519. // Database table definitions
  2520. $tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  2521. $course_info = api_get_course_info_by_id($courseId);
  2522. if (!empty($course_info)) {
  2523. $strg_sd = "";
  2524. $strg_ed = "";
  2525. if ($start_date != null && $end_date != null){
  2526. $end_date = add_day_to( $end_date );
  2527. $strg_sd = "AND login_course_date BETWEEN '$start_date' AND '$end_date'";
  2528. $strg_ed = "AND logout_course_date BETWEEN '$start_date' AND '$end_date'";
  2529. }
  2530. $sql = 'SELECT
  2531. SEC_TO_TIME(avg(time_to_sec(timediff(logout_course_date,login_course_date)))) as avrg,
  2532. SEC_TO_TIME(sum(time_to_sec(timediff(logout_course_date,login_course_date)))) as total,
  2533. count(user_id) as times
  2534. FROM ' . $tbl_track_course . '
  2535. WHERE
  2536. user_id = ' . intval($user_id) . ' AND
  2537. c_id = ' . intval($courseId) . ' '.$strg_sd.' '.$strg_ed.' '.'
  2538. ORDER BY login_course_date ASC';
  2539. $rs = Database::query($sql);
  2540. $result = array();
  2541. if ($row = Database::fetch_array($rs)) {
  2542. $foo_avg = $row['avrg'];
  2543. $foo_total = $row['total'];
  2544. $foo_times = $row['times'];
  2545. $result = array('avg' => $foo_avg, 'total' => $foo_total, 'times' => $foo_times);
  2546. }
  2547. }
  2548. return $result;
  2549. }
  2550. function add_day_to($end_date) {
  2551. $foo_date = strtotime( $end_date );
  2552. $foo_date = strtotime(" +1 day", $foo_date);
  2553. $foo_date = date("Y-m-d", $foo_date);
  2554. return $foo_date;
  2555. }
  2556. /**
  2557. * Gets the connections to a course as an array of login and logout time
  2558. *
  2559. * @param int $user_id
  2560. * @param int $courseId
  2561. * @author Jorge Frisancho Jibaja
  2562. * @author Julio Montoya <gugli100@gmail.com> fixing the function
  2563. * @version OCT-22- 2010
  2564. * @return array
  2565. */
  2566. function get_connections_to_course_by_date($user_id, $courseId, $start_date, $end_date)
  2567. {
  2568. // Database table definitions
  2569. $tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  2570. $course_info = api_get_course_info_by_id($courseId);
  2571. $user_id = intval($user_id);
  2572. $courseId = intval($courseId);
  2573. $connections = array();
  2574. if (!empty($course_info)) {
  2575. $end_date = add_day_to($end_date);
  2576. $sql = "SELECT login_course_date, logout_course_date
  2577. FROM $tbl_track_course
  2578. WHERE
  2579. user_id = $user_id AND
  2580. c_id = $courseId AND
  2581. login_course_date BETWEEN '$start_date' AND '$end_date' AND
  2582. logout_course_date BETWEEN '$start_date' AND '$end_date'
  2583. ORDER BY login_course_date ASC";
  2584. $rs = Database::query($sql);
  2585. while ($row = Database::fetch_array($rs)) {
  2586. $login_date = $row['login_course_date'];
  2587. $logout_date = $row['logout_course_date'];
  2588. $timestamp_login_date = strtotime($login_date);
  2589. $timestamp_logout_date = strtotime($logout_date);
  2590. $connections[] = array(
  2591. 'login' => $timestamp_login_date,
  2592. 'logout' => $timestamp_logout_date
  2593. );
  2594. }
  2595. }
  2596. return $connections;
  2597. }
  2598. /**
  2599. *
  2600. *
  2601. * @param array
  2602. * @author Jorge Frisancho Jibaja
  2603. * @version OCT-22- 2010
  2604. * @return array
  2605. */
  2606. function convert_to_array($sql_result){
  2607. $result_to_print = '<table>';
  2608. foreach ($sql_result as $key => $data) {
  2609. $result_to_print .= '<tr><td>'.date('d-m-Y (H:i:s)', $data['login']).'</td><td>'.api_time_to_hms($data['logout'] - $data['login']).'</tr></td>'."\n";
  2610. }
  2611. $result_to_print .= '</table>';
  2612. $result_to_print = array("result"=>$result_to_print);
  2613. return $result_to_print;
  2614. }
  2615. /**
  2616. * Converte an array to a table in html
  2617. *
  2618. * @param array $sql_result
  2619. * @author Jorge Frisancho Jibaja
  2620. * @version OCT-22- 2010
  2621. * @return string
  2622. */
  2623. function convert_to_string($sql_result){
  2624. $result_to_print = '<table>';
  2625. if (!empty($sql_result)) {
  2626. foreach ($sql_result as $key => $data) {
  2627. $result_to_print .= '<tr><td>'.date('d-m-Y (H:i:s)', $data['login']).'</td><td>'.api_time_to_hms($data['logout'] - $data['login']).'</tr></td>'."\n";
  2628. }
  2629. }
  2630. $result_to_print .= '</table>';
  2631. return $result_to_print;
  2632. }
  2633. /**
  2634. * This function draw the graphic to be displayed on the user view as an image
  2635. *
  2636. * @param array $sql_result
  2637. * @param string $start_date
  2638. * @param string $end_date
  2639. * @param string $type
  2640. * @author Jorge Frisancho Jibaja
  2641. * @version OCT-22- 2010
  2642. * @return string
  2643. */
  2644. function grapher($sql_result, $start_date, $end_date, $type = "")
  2645. {
  2646. if (empty($start_date)) { $start_date =""; }
  2647. if (empty($end_date)) { $end_date =""; }
  2648. if ($type == ""){ $type = 'day'; }
  2649. $main_year = $main_month_year = $main_day = array();
  2650. // get last 8 days/months
  2651. $last_days = 5;
  2652. $last_months = 3;
  2653. for ($i = $last_days; $i >= 0; $i--) {
  2654. $main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0;
  2655. }
  2656. for ($i = $last_months; $i >= 0; $i--) {
  2657. $main_month_year[date ('m-Y', mktime () - $i * 30 * 3600 * 24)] = 0;
  2658. }
  2659. $i = 0;
  2660. if (is_array($sql_result) && count($sql_result) > 0) {
  2661. foreach ($sql_result as $key => $data) {
  2662. //creating the main array
  2663. $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
  2664. $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
  2665. if ($i > 500) {
  2666. break;
  2667. }
  2668. $i++;
  2669. }
  2670. switch ($type) {
  2671. case 'day':
  2672. $main_date = $main_day;
  2673. break;
  2674. case 'month':
  2675. $main_date = $main_month_year;
  2676. break;
  2677. case 'year':
  2678. $main_date = $main_year;
  2679. break;
  2680. }
  2681. // the nice graphics :D
  2682. $labels = array_keys($main_date);
  2683. if (count($main_date) == 1) {
  2684. $labels = $labels[0];
  2685. $main_date = $main_date[$labels];
  2686. }
  2687. /* Create and populate the pData object */
  2688. $myData = new pData();
  2689. $myData->addPoints($main_date, 'Serie1');
  2690. if (count($main_date)!= 1) {
  2691. $myData->addPoints($labels, 'Labels');
  2692. $myData->setSerieDescription('Labels', 'Months');
  2693. $myData->setAbscissa('Labels');
  2694. }
  2695. $myData->setSerieWeight('Serie1', 1);
  2696. $myData->setSerieDescription('Serie1', get_lang('MyResults'));
  2697. $myData->setAxisName(0, get_lang('Minutes'));
  2698. $myData->loadPalette(api_get_path(SYS_CODE_PATH) . 'palettes/pchart/default.color', true);
  2699. // Cache definition
  2700. $cachePath = api_get_path(SYS_ARCHIVE_PATH);
  2701. $myCache = new pCache(array('CacheFolder' => substr($cachePath, 0, strlen($cachePath) - 1)));
  2702. $chartHash = $myCache->getHash($myData);
  2703. if ($myCache->isInCache($chartHash)) {
  2704. //if we already created the img
  2705. $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
  2706. $myCache->saveFromCache($chartHash, $imgPath);
  2707. $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
  2708. } else {
  2709. /* Define width, height and angle */
  2710. $mainWidth = 760;
  2711. $mainHeight = 230;
  2712. $angle = 50;
  2713. /* Create the pChart object */
  2714. $myPicture = new pImage($mainWidth, $mainHeight, $myData);
  2715. /* Turn of Antialiasing */
  2716. $myPicture->Antialias = false;
  2717. /* Draw the background */
  2718. $settings = array("R" => 255, "G" => 255, "B" => 255);
  2719. $myPicture->drawFilledRectangle(0, 0, $mainWidth, $mainHeight, $settings);
  2720. /* Add a border to the picture */
  2721. $myPicture->drawRectangle(
  2722. 0,
  2723. 0,
  2724. $mainWidth - 1,
  2725. $mainHeight - 1,
  2726. array("R" => 0, "G" => 0, "B" => 0)
  2727. );
  2728. /* Set the default font */
  2729. $myPicture->setFontProperties(
  2730. array(
  2731. "FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf',
  2732. "FontSize" => 10)
  2733. );
  2734. /* Write the chart title */
  2735. $myPicture->drawText(
  2736. $mainWidth / 2,
  2737. 30,
  2738. get_lang('ExercisesInTimeProgressChart'),
  2739. array(
  2740. "FontSize" => 12,
  2741. "Align" => TEXT_ALIGN_BOTTOMMIDDLE
  2742. )
  2743. );
  2744. /* Set the default font */
  2745. $myPicture->setFontProperties(
  2746. array(
  2747. "FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf',
  2748. "FontSize" => 8
  2749. )
  2750. );
  2751. /* Define the chart area */
  2752. $myPicture->setGraphArea(50, 40, $mainWidth - 40, $mainHeight - 80);
  2753. /* Draw the scale */
  2754. $scaleSettings = array(
  2755. 'XMargin' => 10,
  2756. 'YMargin' => 10,
  2757. 'Floating' => true,
  2758. 'GridR' => 200,
  2759. 'GridG' => 200,
  2760. 'GridB' => 200,
  2761. 'DrawSubTicks' => true,
  2762. 'CycleBackground' => true,
  2763. 'LabelRotation' => $angle,
  2764. 'Mode' => SCALE_MODE_ADDALL_START0,
  2765. );
  2766. $myPicture->drawScale($scaleSettings);
  2767. /* Turn on Antialiasing */
  2768. $myPicture->Antialias = true;
  2769. /* Enable shadow computing */
  2770. $myPicture->setShadow(
  2771. true,
  2772. array(
  2773. "X" => 1,
  2774. "Y" => 1,
  2775. "R" => 0,
  2776. "G" => 0,
  2777. "B" => 0,
  2778. "Alpha" => 10
  2779. )
  2780. );
  2781. /* Draw the line chart */
  2782. $myPicture->setFontProperties(
  2783. array(
  2784. "FontName" => api_get_path(SYS_FONTS_PATH) . 'opensans/OpenSans-Regular.ttf',
  2785. "FontSize" => 10
  2786. )
  2787. );
  2788. $myPicture->drawSplineChart();
  2789. $myPicture->drawPlotChart(
  2790. array(
  2791. "DisplayValues" => true,
  2792. "PlotBorder" => true,
  2793. "BorderSize" => 1,
  2794. "Surrounding" => -60,
  2795. "BorderAlpha" => 80
  2796. )
  2797. );
  2798. /* Do NOT Write the chart legend */
  2799. /* Write and save into cache */
  2800. $myCache->writeToCache($chartHash, $myPicture);
  2801. $imgPath = api_get_path(SYS_ARCHIVE_PATH) . $chartHash;
  2802. $myCache->saveFromCache($chartHash, $imgPath);
  2803. $imgPath = api_get_path(WEB_ARCHIVE_PATH) . $chartHash;
  2804. }
  2805. $html = '<img src="' . $imgPath . '">';
  2806. return $html;
  2807. } else {
  2808. $foo_img = api_convert_encoding('<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>','UTF-8');
  2809. return $foo_img;
  2810. }
  2811. }