myspace.lib.php 136 KB

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