myspace.lib.php 136 KB

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