myspace.lib.php 137 KB

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