myspace.lib.php 136 KB

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