myspace.lib.php 135 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  4. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  5. /**
  6. * Class MySpace
  7. * @package chamilo.reporting
  8. */
  9. class MySpace
  10. {
  11. /**
  12. * Get admin actions
  13. * @return string
  14. */
  15. public static function getAdminActions()
  16. {
  17. $actions = array(
  18. //array('url' => api_get_path(WEB_CODE_PATH).'mySpace/index.php', 'content' => get_lang('Home')),
  19. array('url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=coaches', 'content' => get_lang('DisplayCoaches')),
  20. array('url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=user', 'content' => get_lang('DisplayUserOverview')),
  21. array('url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=session', 'content' => get_lang('DisplaySessionOverview')),
  22. array('url' => api_get_path(WEB_CODE_PATH).'mySpace/admin_view.php?display=course', 'content' => get_lang('DisplayCourseOverview')),
  23. array('url' => api_get_path(WEB_CODE_PATH).'tracking/question_course_report.php?view=admin', 'content' => get_lang('LPQuestionListResults')),
  24. array('url' => api_get_path(WEB_CODE_PATH).'tracking/course_session_report.php?view=admin', 'content' => get_lang('LPExerciseResultsBySession')),
  25. );
  26. return Display :: actions($actions, null);
  27. }
  28. public static function getTopMenu()
  29. {
  30. $menu_items = array();
  31. $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" );
  32. $menu_items[] = Display::url(Display::return_icon('teacher.png', get_lang('TeacherInterface'), array(), 32), api_get_path(WEB_CODE_PATH).'mySpace/?view=teacher');
  33. $menu_items[] = Display::url(Display::return_icon('star_na.png', get_lang('AdminInterface'), array(), 32), '#');
  34. $menu_items[] = Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php');
  35. $menu = null;
  36. foreach ($menu_items as $item) {
  37. $menu .= $item;
  38. }
  39. $menu .= '<br />';
  40. return $menu;
  41. }
  42. /**
  43. * This function serves exporting data in CSV format.
  44. * @param array $header The header labels.
  45. * @param array $data The data array.
  46. * @param string $file_name The name of the file which contains exported data.
  47. * @return string mixed Returns a message (string) if an error occurred.
  48. */
  49. function export_csv($header, $data, $file_name = 'export.csv') {
  50. $archive_path = api_get_path(SYS_ARCHIVE_PATH);
  51. $archive_url = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
  52. if (!$open = fopen($archive_path.$file_name, 'w+')) {
  53. $message = get_lang('noOpen');
  54. } else {
  55. $info = '';
  56. foreach ($header as $value) {
  57. $info .= $value.';';
  58. }
  59. $info .= "\r\n";
  60. foreach ($data as $row) {
  61. foreach ($row as $value) {
  62. $info .= $value.';';
  63. }
  64. $info .= "\r\n";
  65. }
  66. fwrite($open, $info);
  67. fclose($open);
  68. @chmod($file_name, api_get_permissions_for_new_files());
  69. header("Location:".$archive_url.$file_name);
  70. }
  71. return $message;
  72. }
  73. /**
  74. * Gets the connections to a course as an array of login and logout time
  75. *
  76. * @param int User ud
  77. * @param string Course code
  78. * @param int Session id (optional, default = 0)
  79. * @return array Conections
  80. */
  81. static function get_connections_to_course($user_id, $course_code, $session_id = 0)
  82. {
  83. // Database table definitions
  84. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  85. // protect data
  86. $user_id = intval($user_id);
  87. $course_code = Database::escape_string($course_code);
  88. $session_id = intval($session_id);
  89. $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . '
  90. WHERE user_id = '.$user_id.' AND
  91. course_code="'.$course_code.'" AND
  92. session_id = '.$session_id.'
  93. ORDER BY login_course_date ASC';
  94. $rs = Database::query($sql);
  95. $connections = array();
  96. while ($row = Database::fetch_array($rs)) {
  97. $timestamp_login_date = api_strtotime($row['login_course_date'], 'UTC');
  98. $timestamp_logout_date = api_strtotime($row['logout_course_date'], 'UTC');
  99. $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date);
  100. }
  101. return $connections;
  102. }
  103. static function get_connections_from_course_list($user_id, $course_list, $session_id = 0) {
  104. // Database table definitions
  105. $tbl_track_course = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  106. if (empty($course_list)) {
  107. return false;
  108. }
  109. // protect data
  110. $user_id = intval($user_id);
  111. $session_id = intval($session_id);
  112. $new_course_list = array();
  113. foreach ($course_list as $course_item) {
  114. $new_course_list[] = '"'.Database::escape_string($course_item['code']).'"';
  115. }
  116. $course_list = implode(', ', $new_course_list);
  117. if (empty($course_list)) {
  118. return false;
  119. }
  120. $sql = 'SELECT login_course_date, logout_course_date, course_code FROM ' . $tbl_track_course . '
  121. WHERE user_id = '.$user_id.' AND
  122. course_code IN ('.$course_list.') AND
  123. session_id = '.$session_id.'
  124. ORDER BY login_course_date ASC';
  125. $rs = Database::query($sql);
  126. $connections = array();
  127. while ($row = Database::fetch_array($rs)) {
  128. $timestamp_login_date = api_strtotime($row['login_course_date'], 'UTC');
  129. $timestamp_logout_date = api_strtotime($row['logout_course_date'], 'UTC');
  130. $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date,'course_code' => $row['course_code']);
  131. }
  132. return $connections;
  133. }
  134. /**
  135. * TODO: Not used, to b deleted?
  136. * Enter description here...
  137. * @param int $user_id
  138. * @param string $course_code
  139. * @param date $year
  140. * @param date $month
  141. * @param date $day
  142. * @return unknown
  143. */
  144. static function get_connections_to_course_by_time($user_id, $course_code, $year = '', $month = '', $day = '') {
  145. // Database table definitions
  146. $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
  147. $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . '
  148. WHERE user_id = ' . intval($user_id) . '
  149. AND course_code="' . Database::escape_string($course_code) . '"
  150. ORDER BY login_course_date DESC';
  151. $rs = Database::query($sql);
  152. $connections = array();
  153. while ($row = Database::fetch_array($rs)) {
  154. $login_date = $row['login_course_date'];
  155. $logout_date = $row['logout_course_date'];
  156. $timestamp_login_date = strtotime($login_date);
  157. $timestamp_logout_date = strtotime($logout_date);
  158. $connections[] = array('login' => $timestamp_login_date, 'logout' => $timestamp_logout_date);
  159. }
  160. return $connections;
  161. }
  162. /**
  163. * Creates a small table in the last column of the table with the user overview
  164. *
  165. * @param integer $user_id the id of the user
  166. * @param array $url_params additonal url parameters
  167. * @param array $row the row information (the other columns)
  168. * @return string html code
  169. */
  170. public static function course_info_tracking_filter($user_id, $url_params, $row)
  171. {
  172. // the table header
  173. $return = '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  174. /*$return .= ' <tr>';
  175. $return .= ' <th>'.get_lang('Course').'</th>';
  176. $return .= ' <th>'.get_lang('AvgTimeSpentInTheCourse').'</th>';
  177. $return .= ' <th>'.get_lang('AvgStudentsProgress').'</th>';
  178. $return .= ' <th>'.get_lang('AvgCourseScore').'</th>';
  179. $return .= ' <th>'.get_lang('AvgExercisesScore').'</th>';
  180. $return .= ' <th>'.get_lang('AvgMessages').'</th>';
  181. $return .= ' <th>'.get_lang('AvgAssignments').'</th>';
  182. $return .= ' <th>'.get_lang('TotalExercisesScoreObtained').'</th>';
  183. $return .= ' <th>'.get_lang('TotalExercisesScorePossible').'</th>';
  184. $return .= ' <th>'.get_lang('TotalExercisesAnswered').'</th>';
  185. $return .= ' <th>'.get_lang('TotalExercisesScorePercentage').'</th>';
  186. $return .= ' <th>'.get_lang('FirstLogin').'</th>';
  187. $return .= ' <th>'.get_lang('LatestLogin').'</th>';
  188. $return .= ' </tr>';*/
  189. // database table definition
  190. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  191. // getting all the courses of the user
  192. $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".intval($user_id)."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." ";
  193. $result = Database::query($sql);
  194. while ($row = Database::fetch_row($result)) {
  195. $return .= '<tr>';
  196. // course code
  197. $return .= ' <td width="157px" >'.cut($row[0], 20, true).'</td>';
  198. // time spent in the course
  199. $return .= ' <td><div>'.api_time_to_hms(Tracking :: get_time_spent_on_the_course($user_id, $row[0])).'</div></td>';
  200. // student progress in course
  201. $return .= ' <td><div>'.round(Tracking :: get_avg_student_progress($user_id, $row[0]), 2).'</div></td>';
  202. // student score
  203. $avg_score = Tracking :: get_avg_student_score($user_id, $row[0]);
  204. if (is_numeric($avg_score)) {
  205. $avg_score = round($avg_score,2);
  206. } else {
  207. $$avg_score = '-';
  208. }
  209. $return .= ' <td><div>'.$avg_score.'</div></td>';
  210. // student tes score
  211. //$return .= ' <td><div style="width:40px">'.round(Tracking :: get_avg_student_exercise_score ($user_id, $row[0]),2).'%</div></td>';
  212. // student messages
  213. $return .= ' <td><div>'.Tracking :: count_student_messages($user_id, $row[0]).'</div></td>';
  214. // student assignments
  215. $return .= ' <td><div>'.Tracking :: count_student_assignments($user_id, $row[0]).'</div></td>';
  216. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  217. $exercises_results = MySpace::exercises_results($user_id, $row[0]);
  218. $return .= ' <td width="105px"><div>'.(is_null($exercises_results['percentage']) ? '' : $exercises_results['score_obtained'].'/'.$exercises_results['score_possible'].' ( '.$exercises_results['percentage'].'% )').'</div></td>';
  219. //$return .= ' <td><div>'.$exercises_results['score_possible'].'</div></td>';
  220. $return .= ' <td><div>'.$exercises_results['questions_answered'].'</div></td>';
  221. //$return .= ' <td><div>'.$exercises_results['percentage'].'% </div></td>';
  222. // first connection
  223. //$return .= ' <td width="60px">'.Tracking :: get_first_connection_date_on_the_course ($user_id, $row[0]).'</td>';
  224. // last connection
  225. $return .= ' <td><div>'.Tracking :: get_last_connection_date_on_the_course ($user_id, $row[0]).'</div></td>';
  226. $return .= '<tr>';
  227. }
  228. $return .= '</table>';
  229. return $return;
  230. }
  231. /**
  232. * Display a sortable table that contains an overview off all the reporting progress of all users and all courses the user is subscribed to
  233. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  234. * @version Dokeos 1.8.6
  235. * @since October 2008
  236. */
  237. public static function display_tracking_user_overview()
  238. {
  239. MySpace::display_user_overview_export_options();
  240. $t_head = ' <table style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  241. //$t_head .= ' <caption>'.get_lang('CourseInformation').'</caption>';
  242. $t_head .= '<tr>';
  243. $t_head .= ' <th width="155px" style="border-left:0;border-bottom:0"><span>'.get_lang('Course').'</span></th>';
  244. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).'</span></th>';
  245. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgStudentsProgress'), 6, true).'</span></th>';
  246. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgCourseScore'), 6, true).'</span></th>';
  247. //$t_head .= ' <th><div style="width:40px">'.get_lang('AvgExercisesScore').'</div></th>';
  248. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfMessages'), 6, true).'</span></th>';
  249. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfAssignments'), 6, true).'</span></th>';
  250. $t_head .= ' <th width="105px" style="border-bottom:0"><span>'.get_lang('TotalExercisesScoreObtained').'</span></th>';
  251. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePossible').'</div></th>';
  252. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalExercisesAnswered'), 6, true).'</span></th>';
  253. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePercentage').'</div></th>';
  254. //$t_head .= ' <th><div style="width:60px">'.get_lang('FirstLogin').'</div></th>';
  255. $t_head .= ' <th style="padding:0;border-bottom:0;border-right:0;"><span>'.get_lang('LatestLogin').'</span></th>';
  256. $t_head .= ' </tr></table>';
  257. $addparams = array('view' => 'admin', 'display' => 'useroverview');
  258. $table = new SortableTable('tracking_user_overview', array('MySpace','get_number_of_users_tracking_overview'), array('MySpace','get_user_data_tracking_overview'), 0);
  259. $table->additional_parameters = $addparams;
  260. $table->set_header(0, get_lang('OfficialCode'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  261. if (api_is_western_name_order()) {
  262. $table->set_header(1, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  263. $table->set_header(2, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  264. } else {
  265. $table->set_header(1, get_lang('LastName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  266. $table->set_header(2, get_lang('FirstName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  267. }
  268. $table->set_header(3, get_lang('LoginName'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  269. $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;'));
  270. $table->set_column_filter(4, array('MySpace','course_info_tracking_filter'));
  271. $table->display();
  272. }
  273. public static function display_tracking_coach_overview($export_csv)
  274. {
  275. global $_configuration;
  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 ($_configuration['multiple_access_urls']) {
  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 ($_configuration['multiple_access_urls']) {
  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. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  464. $lessons = LearnpathList::get_course_lessons($course['code'], $sessionId);
  465. //create columns array
  466. foreach ($lessons as $lesson_id => $lesson)
  467. {
  468. $columns[] = $lesson['name'];
  469. }
  470. $columns[] = get_lang('Total');
  471. /**
  472. * Column config
  473. */
  474. $column_model = array(
  475. array('name'=>'username', 'index'=>'username', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  476. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left', 'search' => 'true'),
  477. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left', 'search' => 'true'),
  478. );
  479. //get dinamic column names
  480. foreach ($lessons as $lesson_id => $lesson)
  481. {
  482. $column_model[] = array('name'=> $lesson['id'], 'index'=>$lesson['id'], 'align'=>'left', 'search' => 'true');
  483. }
  484. $column_model[] = array('name'=>'total', 'index'=>'total', 'align'=>'left', 'search' => 'true');
  485. $action_links = '';
  486. // jqgrid will use this URL to do the selects
  487. $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;
  488. //Table Id
  489. $tableId = 'lpProgress';
  490. //Autowidth
  491. $extra_params['autowidth'] = 'true';
  492. //height auto
  493. $extra_params['height'] = 'auto';
  494. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  495. $return = '<script>$(function() {'. $table .
  496. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  497. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  498. caption:"",
  499. title:"' . get_lang('ExportExcel') . '",
  500. onClickButton : function () {
  501. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  502. }
  503. });
  504. });</script>';
  505. $return .= Display::grid_html($tableId);
  506. return $return;
  507. }
  508. /**
  509. * Display a sortable table that contains an overview off all the progress of the user in a session
  510. * @param int $sessionId The session ID
  511. * @param int $courseId The course ID
  512. * @param int $exerciseId The quiz ID
  513. * @param int $answer Answer status (0 = incorrect, 1 = correct, 2 = both)
  514. * @return string HTML array of results formatted for gridJS
  515. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  516. */
  517. static function display_tracking_exercise_progress_overview(
  518. $sessionId = 0,
  519. $courseId = 0,
  520. $exerciseId = 0,
  521. $date_from = null,
  522. $date_to = null
  523. ) {
  524. $date_from = Security::remove_XSS($date_from);
  525. $date_to = Security::remove_XSS($date_to);
  526. /**
  527. * Column names
  528. * The column order is important. Check $column variable in the main/inc/ajax/model.ajax.php file
  529. */
  530. $columns = array(
  531. get_lang('Session'),
  532. get_lang('ExerciseId'),
  533. get_lang('ExerciseName'),
  534. get_lang('Username'),
  535. get_lang('LastName'),
  536. get_lang('FirstName'),
  537. get_lang('Time'),
  538. get_lang('QuestionId'),
  539. get_lang('QuestionTitle'),
  540. get_lang('WorkDescription'),
  541. get_lang('Answer'),
  542. get_lang('Correct'),
  543. );
  544. /**
  545. * Column config
  546. */
  547. $column_model = array(
  548. array('name'=>'session', 'index'=>'session', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  549. array('name'=>'exercise_id', 'index'=>'exercise_id', 'align'=>'left', 'search' => 'true'),
  550. array('name'=>'quiz_title', 'index'=>'quiz_title', 'align'=>'left', 'search' => 'true'),
  551. array('name'=>'username', 'index'=>'username', 'align'=>'left', 'search' => 'true'),
  552. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left', 'search' => 'true'),
  553. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left', 'search' => 'true'),
  554. array('name'=>'time', 'index'=>'time', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  555. array('name'=>'question_id', 'index'=>'question_id', 'align'=>'left', 'search' => 'true'),
  556. array('name'=>'question', 'index'=>'question', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  557. array('name'=>'description', 'index'=>'description', 'align'=>'left', 'width' => '550', 'search' => 'true', 'wrap_cell' => "true"),
  558. array('name'=>'answer', 'index'=>'answer', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  559. array('name'=>'correct', 'index'=>'correct', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  560. );
  561. //get dynamic column names
  562. // jqgrid will use this URL to do the selects
  563. $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;
  564. // Autowidth
  565. $extra_params['autowidth'] = 'true';
  566. // height auto
  567. $extra_params['height'] = 'auto';
  568. $tableId = 'exerciseProgressOverview';
  569. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), '', true);
  570. $return = '<script>$(function() {'. $table .
  571. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  572. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  573. caption:"",
  574. title:"' . get_lang('ExportExcel') . '",
  575. onClickButton : function () {
  576. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  577. }
  578. });
  579. });</script>';
  580. $return .= Display::grid_html($tableId);
  581. return $return;
  582. }
  583. /**
  584. * Display a sortable table that contains an overview off all the progress of the user in a session
  585. * @param int $sessionId The session ID
  586. * @param int $courseId The course ID
  587. * @param null $date_from
  588. * @param null $date_to
  589. * @internal param int $exerciseId The quiz ID
  590. * @internal param int $answer Answer status (0 = incorrect, 1 = correct, 2 = both)
  591. * @return string HTML array of results formatted for gridJS
  592. * @author Francis Gonzales <francis.gonzales@beeznest.com>, Beeznest Team
  593. */
  594. static function display_tracking_grade_overview($sessionId = 0, $courseId = 0, $date_from = null, $date_to = null)
  595. {
  596. /**
  597. * Column names
  598. * The column order is important. Check $column variable in the main/inc/ajax/model.ajax.php file
  599. */
  600. $objExercise = new Exercise();
  601. $exercises = $objExercise->getExercisesByCouseSession($courseId, $sessionId);
  602. $cntExer = 4;
  603. if (!empty($exercises)) {
  604. $cntExer += count($exercises);
  605. }
  606. $column = array();
  607. $column_model = array();
  608. $i = 1;
  609. //Get dynamic column names
  610. foreach (range(1, $cntExer) as $cnt) {
  611. switch ($cnt) {
  612. case 1:
  613. $column[] = get_lang('Section');
  614. $column_model[] = array(
  615. 'name' => 'session',
  616. 'index' => 'session',
  617. 'align' => 'center',
  618. 'search' => 'true',
  619. );
  620. break;
  621. case 2:
  622. $column[] = get_lang('Username');
  623. $column_model[] = array(
  624. 'name' => 'username',
  625. 'index' => 'username',
  626. 'align' => 'center',
  627. 'search' => 'true',
  628. );
  629. break;
  630. case 3:
  631. $column[] = get_lang('FirstName');
  632. $column_model[] = array(
  633. 'name' => 'name',
  634. 'index' => 'name',
  635. 'align' => 'left',
  636. 'search' => 'true',
  637. );
  638. break;
  639. case $cntExer:
  640. $column[] = get_lang('FinalScore');
  641. $column_model[] = array(
  642. 'name' => 'finalscore',
  643. 'index' => 'finalscore',
  644. 'align' => 'center',
  645. 'search' => 'true',
  646. 'wrap_cell' => "true"
  647. );
  648. break;
  649. default:
  650. $title = "";
  651. if (!empty($exercises[$cnt - 4]['title'])) {
  652. $title = ucwords(strtolower(trim($exercises[$cnt - 4]['title'])));
  653. }
  654. $column[] = $title;
  655. $column_model[] = array(
  656. 'name' => 'exer' . $i,
  657. 'index' => 'exer' . $i,
  658. 'align' => 'center',
  659. 'search' => 'true',
  660. 'wrap_cell' => "true"
  661. );
  662. $i++;
  663. break;
  664. }
  665. }
  666. //end get dynamic column names
  667. // jqgrid will use this URL to do the selects
  668. $url = api_get_path(WEB_AJAX_PATH) . 'model.ajax.php?a=get_exercise_grade&session_id=' . $sessionId . '&course_id=' . $courseId;
  669. //Autowidth
  670. $extra_params['autowidth'] = 'true';
  671. //height auto
  672. $extra_params['height'] = 'auto';
  673. $tableId = 'exerciseGradeOverview';
  674. $table = Display::grid_js($tableId, $url, $column, $column_model, $extra_params, array(), '', true);
  675. $return = '<script>$(function() {' . $table .
  676. 'jQuery("#' . $tableId . '").jqGrid("navGrid","#' . $tableId . '_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  677. jQuery("#' . $tableId . '").jqGrid("navButtonAdd","#' . $tableId . '_pager",{
  678. caption:"",
  679. title:"' . get_lang('ExportExcel') . '",
  680. onClickButton : function () {
  681. jQuery("#' . $tableId . '").jqGrid("excelExport",{"url":"' . $url . '&export_format=xls"});
  682. }
  683. });
  684. });</script>';
  685. $return .= Display::grid_html($tableId);
  686. return $return;
  687. }
  688. /**
  689. * Display a sortable table that contains an overview off all the progress of the user in a session
  690. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  691. */
  692. function display_survey_overview($sessionId = 0, $courseId = 0, $surveyId = 0, $date_from, $date_to)
  693. {
  694. /**
  695. * Column name
  696. * The order is important you need to check the $column variable in the model.ajax.php file
  697. */
  698. $columns = array(
  699. get_lang('Username'),
  700. get_lang('FirstName'),
  701. get_lang('LastName'),
  702. );
  703. //add lessons of course
  704. $questions = survey_manager::get_questions($surveyId, $courseId);
  705. foreach ($questions as $question) {
  706. $columns[] = $question['question'];
  707. }
  708. /**
  709. * Column config
  710. */
  711. $column_model = array(
  712. array('name'=>'username', 'index'=>'username', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"),
  713. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left', 'search' => 'true'),
  714. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left', 'search' => 'true'),
  715. );
  716. //get dinamic column names
  717. foreach ($questions as $question_id => $question) {
  718. $column_model[] = array(
  719. 'name'=> $question_id,
  720. 'index'=>$question_id,
  721. 'width'=>'70',
  722. 'align'=>'left',
  723. 'search' => 'true'
  724. );
  725. }
  726. $action_links = '';
  727. // jqgrid will use this URL to do the selects
  728. $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;
  729. //Table Id
  730. $tableId = 'lpProgress';
  731. //Autowidth
  732. $extra_params['autowidth'] = 'true';
  733. //height auto
  734. $extra_params['height'] = 'auto';
  735. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  736. $return = '<script>$(function() {'. $table .
  737. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  738. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  739. caption:"",
  740. title:"' . get_lang('ExportExcel') . '",
  741. onClickButton : function () {
  742. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  743. }
  744. });
  745. });</script>';
  746. $return .= Display::grid_html($tableId);
  747. return $return;
  748. }
  749. /**
  750. * Display a sortable table that contains an overview off all the progress of the user in a session
  751. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  752. */
  753. static function display_tracking_progress_overview($sessionId = 0, $courseId = 0, $date_from, $date_to)
  754. {
  755. //The order is important you need to check the the $column variable in the model.ajax.php file
  756. $columns = array(
  757. get_lang('LastName'),
  758. get_lang('FirstName'),
  759. get_lang('Username'),
  760. #get_lang('Profile'),
  761. get_lang('Total'),
  762. get_lang('Courses'),
  763. get_lang('LearningPaths'),
  764. get_lang('Exercises'),
  765. get_lang('Forums'),
  766. get_lang('Assignments'),
  767. get_lang('ToolWiki'),
  768. get_lang('ToolSurvey'),
  769. //Learning paths
  770. get_lang('LearnpathsTotal'),
  771. get_lang('LearnpathsDone'),
  772. get_lang('LearnpathsLeft'),
  773. get_lang('LearnpathsProgress'),
  774. //Exercises
  775. get_lang('ExercisesTotal'),
  776. get_lang('ExercisesDone'),
  777. get_lang('ExercisesLeft'),
  778. get_lang('ExercisesProgress'),
  779. //Forums
  780. get_lang('ForumsTotal'),
  781. get_lang('ForumsDone'),
  782. get_lang('ForumsLeft'),
  783. get_lang('ForumsProgress'),
  784. //Assignments
  785. get_lang('AssignmentsTotal'),
  786. get_lang('AssignmentsDone'),
  787. get_lang('AssignmentsLeft'),
  788. get_lang('AssignmentsProgress'),
  789. //Wiki
  790. get_lang('WikiTotal'),
  791. get_lang('WikiRevisions'),
  792. get_lang('WikiRead'),
  793. get_lang('WikiUnread'),
  794. get_lang('WikiProgress'),
  795. //Surveys
  796. get_lang('SurveysTotal'),
  797. get_lang('SurveysDone'),
  798. get_lang('SurveysLeft'),
  799. get_lang('SurveysProgress'),
  800. );
  801. //Column config
  802. $column_model = array(
  803. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left'),
  804. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left'),
  805. array('name'=>'username', 'index'=>'username', 'align'=>'left'),
  806. #array('name'=>'profile', 'index'=>'username', 'align'=>'left'),
  807. array('name'=>'total', 'index'=>'total', 'align'=>'left'),
  808. array('name'=>'courses', 'index'=>'courses', 'align'=>'left', 'sortable' => 'false'),
  809. array('name'=>'lessons', 'index'=>'lessons', 'align'=>'left', 'sortable' => 'false'),
  810. array('name'=>'exercises', 'index'=>'exercises', 'align'=>'left', 'sortable' => 'false'),
  811. array('name'=>'forums', 'index'=>'forums', 'align'=>'left', 'sortable' => 'false'),
  812. array('name'=>'homeworks', 'index'=>'homeworks', 'align'=>'left', 'sortable' => 'false'),
  813. array('name'=>'wikis', 'index'=>'wikis', 'align'=>'left', 'sortable' => 'false'),
  814. array('name'=>'surveys', 'index'=>'surveys', 'align'=>'left', 'sortable' => 'false'),
  815. //Lessons
  816. array('name'=>'lessons_total', 'index'=>'lessons_total', 'align'=>'center', 'sortable' => 'false'),
  817. array('name'=>'lessons_done', 'index'=>'lessons_done', 'align'=>'center', 'sortable' => 'false'),
  818. array('name'=>'lessons_left', 'index'=>'lessons_left', 'align'=>'center', 'sortable' => 'false'),
  819. array('name'=>'lessons_progress', 'index'=>'lessons_progress', 'align'=>'center', 'sortable' => 'false'),
  820. //Exercises
  821. array('name'=>'exercises_total', 'index'=>'exercises_total', 'align'=>'center', 'sortable' => 'false'),
  822. array('name'=>'exercises_done', 'index'=>'exercises_done', 'align'=>'center', 'sortable' => 'false'),
  823. array('name'=>'exercises_left', 'index'=>'exercises_left', 'align'=>'center', 'sortable' => 'false'),
  824. array('name'=>'exercises_progress', 'index'=>'exercises_progress', 'align'=>'center', 'sortable' => 'false'),
  825. //Assignments
  826. array('name'=>'forums_total', 'index'=>'forums_total', 'align'=>'center', 'sortable' => 'false'),
  827. array('name'=>'forums_done', 'index'=>'forums_done', 'align'=>'center', 'sortable' => 'false'),
  828. array('name'=>'forums_left', 'index'=>'forums_left', 'align'=>'center', 'sortable' => 'false'),
  829. array('name'=>'forums_progress', 'index'=>'forums_progress', 'align'=>'center', 'sortable' => 'false'),
  830. //Assignments
  831. array('name'=>'assigments_total', 'index'=>'assigments_total', 'align'=>'center', 'sortable' => 'false'),
  832. array('name'=>'assigments_done', 'index'=>'assigments_done', 'align'=>'center', 'sortable' => 'false'),
  833. array('name'=>'assigments_left', 'index'=>'assigments_left', 'align'=>'center', 'sortable' => 'false'),
  834. array('name'=>'assigments_progress', 'index'=>'assigments_progress', 'align'=>'center', 'sortable' => 'false'),
  835. //Assignments
  836. array('name'=>'wiki_total', 'index'=>'wiki_total', 'align'=>'center', 'sortable' => 'false'),
  837. array('name'=>'wiki_revisions', 'index'=>'wiki_revisions', 'align'=>'center', 'sortable' => 'false'),
  838. array('name'=>'wiki_read', 'index'=>'wiki_read', 'align'=>'center', 'sortable' => 'false'),
  839. array('name'=>'wiki_unread', 'index'=>'wiki_unread', 'align'=>'center', 'sortable' => 'false'),
  840. array('name'=>'wiki_progress', 'index'=>'wiki_progress', 'align'=>'center', 'sortable' => 'false'),
  841. //Surveys
  842. array('name'=>'surveys_total', 'index'=>'surveys_total', 'align'=>'center', 'sortable' => 'false'),
  843. array('name'=>'surveys_done', 'index'=>'surveys_done', 'align'=>'center', 'sortable' => 'false'),
  844. array('name'=>'surveys_left', 'index'=>'surveys_left', 'align'=>'center', 'sortable' => 'false'),
  845. array('name'=>'surveys_progress', 'index'=>'surveys_progress', 'align'=>'center', 'sortable' => 'false'),
  846. );
  847. $action_links = '';
  848. // jqgrid will use this URL to do the selects
  849. $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;
  850. //Table Id
  851. $tableId = 'progressOverview';
  852. //Autowidth
  853. $extra_params['autowidth'] = 'true';
  854. $extra_params['shrinkToFit'] = 'true';
  855. $extra_params['headertitles'] = 'true';
  856. $extra_params['groupHeaders'] = array(
  857. 'courses_detail' => array(
  858. "startColumnName" => 'courses',
  859. "numberOfColumns" => 7,
  860. "titleText" => get_lang('Global'),
  861. ),
  862. 'lessons' => array(
  863. "startColumnName" => 'lessons_total',
  864. "numberOfColumns" => 4,
  865. "titleText" => get_lang('LearningPaths'),
  866. ),
  867. 'exercises' => array(
  868. "startColumnName" => 'exercises_total',
  869. "numberOfColumns" => 4,
  870. "titleText" => get_lang('Exercises'),
  871. ),
  872. 'forums' => array(
  873. "startColumnName" => 'forums_total',
  874. "numberOfColumns" => 4,
  875. "titleText" => get_lang('Forums'),
  876. ),
  877. 'assignments' => array(
  878. "startColumnName" => 'assigments_total',
  879. "numberOfColumns" => 4,
  880. "titleText" => get_lang('Assignments'),
  881. ),
  882. 'wikis' => array(
  883. "startColumnName" => 'wiki_total',
  884. "numberOfColumns" => 5,
  885. "titleText" => get_lang('Wiki'),
  886. ),
  887. 'surveys' => array(
  888. "startColumnName" => 'surveys_total',
  889. "numberOfColumns" => 4,
  890. "titleText" => get_lang('Survey'),
  891. ),
  892. );
  893. //height auto
  894. $extra_params['height'] = 'auto';
  895. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  896. $return = '<script>$(function() {'. $table .
  897. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  898. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  899. caption:"",
  900. title:"' . get_lang('ExportExcel') . '",
  901. onClickButton : function () {
  902. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  903. }
  904. });
  905. });</script>';
  906. $return .= Display::grid_html($tableId);
  907. return $return;
  908. }
  909. /**
  910. * Display a sortable table that contains an overview off all the access to a session
  911. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  912. * @version Chamilo 1.9.6
  913. */
  914. static function display_tracking_access_overview($sessionId = 0, $courseId = 0, $studentId = '', $profile = '', $date_from, $date_to) {
  915. //The order is important you need to check the the $column variable in the model.ajax.php file
  916. $columns = array(
  917. get_lang('LoginDate'),
  918. get_lang('UserName'),
  919. get_lang('LastName'),
  920. get_lang('FirstName'),
  921. get_lang('Clicks'),
  922. get_lang('IP'),
  923. get_lang('TimeLoggedIn'),
  924. get_lang('Section'),
  925. );
  926. $column_model = array(
  927. array('name'=>'logindate', 'index'=>'loginDate', 'align'=>'left', 'search' => 'true'),
  928. array('name'=>'username', 'index'=>'username', 'align'=>'left', 'search' => 'true'),
  929. array('name'=>'firstname', 'index'=>'firstname', 'align'=>'left', 'search' => 'true'),
  930. array('name'=>'lastname', 'index'=>'lastname', 'align'=>'left', 'search' => 'true'),
  931. array('name'=>'clicks', 'index'=>'clicks', 'align'=>'left', 'search' => 'true'),
  932. array('name'=>'ip', 'index'=>'ip', 'align'=>'left', 'search' => 'true'),
  933. array('name'=>'timeloggedin', 'index'=>'timeLoggedIn', 'align'=>'left', 'search' => 'true'),
  934. array('name'=>'session', 'index'=>'session', 'align'=>'left')
  935. );
  936. $action_links = '';
  937. // jqgrid will use this URL to do the selects
  938. $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;
  939. //Table Id
  940. $tableId = 'accessOverview';
  941. //Autowidth
  942. $extra_params['autowidth'] = 'true';
  943. //height auto
  944. $extra_params['height'] = 'auto';
  945. $table = Display::grid_js($tableId, $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  946. $return = '<script>$(function() {'. $table .
  947. 'jQuery("#'.$tableId.'").jqGrid("navGrid","#'.$tableId.'_pager",{view:false, edit:false, add:false, del:false, search:false, excel:true});
  948. jQuery("#'.$tableId.'").jqGrid("navButtonAdd","#'.$tableId.'_pager",{
  949. caption:"",
  950. title:"' . get_lang('ExportExcel') . '",
  951. onClickButton : function () {
  952. jQuery("#'.$tableId.'").jqGrid("excelExport",{"url":"'.$url.'&export_format=xls"});
  953. }
  954. });
  955. });</script>';
  956. $return .= Display::grid_html($tableId);
  957. return $return;
  958. }
  959. /**
  960. * get the numer of users on track_e_course_access
  961. *
  962. * @return integer
  963. *
  964. * @author César Perales <cesar.perales@beeznest.com>, Beeznest Team
  965. * @version Chamilo 1.9.6
  966. */
  967. /**
  968. * Displays a form with all the additionally defined user fields of the profile
  969. * and give you the opportunity to include these in the CSV export
  970. *
  971. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  972. * @version Dokeos 1.8.6
  973. * @since November 2008
  974. */
  975. public static function display_user_overview_export_options()
  976. {
  977. // include the user manager and formvalidator library
  978. if ($_GET['export'] == 'options') {
  979. // get all the defined extra fields
  980. $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC', false, 1);
  981. // creating the form with all the defined extra fields
  982. $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']));
  983. if (is_array($extrafields) && count($extrafields) > 0) {
  984. foreach ($extrafields as $key => $extra) {
  985. $form->addElement('checkbox', 'extra_export_field'.$extra[0], '', $extra[3]);
  986. }
  987. $form->addElement('style_submit_button','submit', get_lang('Ok'),'class="save"' );
  988. // setting the default values for the form that contains all the extra fields
  989. if (is_array($_SESSION['additional_export_fields'])) {
  990. foreach ($_SESSION['additional_export_fields'] as $key => $value) {
  991. $defaults['extra_export_field'.$value] = 1;
  992. }
  993. }
  994. $form->setDefaults($defaults);
  995. } else {
  996. $form->addElement('html', Display::display_warning_message(get_lang('ThereAreNotExtrafieldsAvailable')));
  997. }
  998. if ($form->validate()) {
  999. // exporting the form values
  1000. $values = $form->exportValues();
  1001. // re-initialising the session that contains the additional fields that need to be exported
  1002. $_SESSION['additional_export_fields'] = array();
  1003. // adding the fields that are checked to the session
  1004. $message = '';
  1005. foreach ($values as $field_ids => $value) {
  1006. if ($value == 1 && strstr($field_ids,'extra_export_field')) {
  1007. $_SESSION['additional_export_fields'][] = str_replace('extra_export_field', '', $field_ids);
  1008. }
  1009. }
  1010. // adding the fields that will be also exported to a message string
  1011. if (is_array($_SESSION['additional_export_fields'])) {
  1012. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  1013. $message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
  1014. }
  1015. }
  1016. // Displaying a feedback message
  1017. if (!empty($_SESSION['additional_export_fields'])) {
  1018. Display::display_confirmation_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>', false);
  1019. } else {
  1020. Display::display_confirmation_message(get_lang('NoAdditionalFieldsWillBeExported'), false);
  1021. }
  1022. $message = '';
  1023. } else {
  1024. $form->display();
  1025. }
  1026. } else {
  1027. if (!empty($_SESSION['additional_export_fields'])) {
  1028. // get all the defined extra fields
  1029. $extrafields = UserManager::get_extra_fields(0, 50, 5, 'ASC');
  1030. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  1031. $message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
  1032. }
  1033. Display::display_normal_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>', false);
  1034. $message = '';
  1035. }
  1036. }
  1037. }
  1038. /**
  1039. * Display a sortable table that contains an overview of all the reporting progress of all courses
  1040. */
  1041. public static function display_tracking_course_overview() {
  1042. //MySpace::display_user_overview_export_options();
  1043. $t_head = ' <table style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  1044. //$t_head .= ' <caption>'.get_lang('CourseInformation').'</caption>';
  1045. $t_head .= '<tr>';
  1046. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).'</span></th>';
  1047. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgStudentsProgress'), 6, true).'</span></th>';
  1048. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgCourseScore'), 6, true).'</span></th>';
  1049. //$t_head .= ' <th><div style="width:40px">'.get_lang('AvgExercisesScore').'</div></th>';
  1050. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfMessages'), 6, true).'</span></th>';
  1051. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfAssignments'), 6, true).'</span></th>';
  1052. $t_head .= ' <th width="105px" style="border-bottom:0"><span>'.get_lang('TotalExercisesScoreObtained').'</span></th>';
  1053. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePossible').'</div></th>';
  1054. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalExercisesAnswered'), 6, true).'</span></th>';
  1055. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePercentage').'</div></th>';
  1056. //$t_head .= ' <th><div style="width:60px">'.get_lang('FirstLogin').'</div></th>';
  1057. $t_head .= ' <th style="padding:0;border-bottom:0;border-right:0;"><span>'.get_lang('LatestLogin').'</span></th>';
  1058. $t_head .= ' </tr></table>';
  1059. $addparams = array('view' => 'admin', 'display' => 'courseoverview');
  1060. $table = new SortableTable('tracking_session_overview', array('MySpace', 'get_total_number_courses'), array('MySpace','get_course_data_tracking_overview'), 1);
  1061. $table->additional_parameters = $addparams;
  1062. $table->set_header(0, '', false, null, array('style' => 'display: none'));
  1063. $table->set_header(1, get_lang('Course'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  1064. $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;'));
  1065. $table->set_column_filter(2, array('MySpace','course_tracking_filter'));
  1066. $table->display();
  1067. }
  1068. /**
  1069. * Get the total number of courses
  1070. *
  1071. * @return integer Total number of courses
  1072. */
  1073. public static function get_total_number_courses()
  1074. {
  1075. // database table definition
  1076. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  1077. return Database::count_rows($main_course_table);
  1078. }
  1079. /**
  1080. * Get data for the courses
  1081. *
  1082. * @param int Inferior limit
  1083. * @param int Number of items to select
  1084. * @param string Column to order on
  1085. * @param string Order direction
  1086. * @return array Results
  1087. */
  1088. public static function get_course_data_tracking_overview($from, $number_of_items, $column, $direction)
  1089. {
  1090. $main_course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
  1091. $from = intval($from);
  1092. $number_of_items = intval($number_of_items);
  1093. $sql = "SELECT code AS col0, title AS col1 FROM $main_course_table";
  1094. $sql .= " ORDER BY col$column $direction ";
  1095. $sql .= " LIMIT $from,$number_of_items";
  1096. $result = Database::query($sql);
  1097. $return = array ();
  1098. while ($course = Database::fetch_row($result)) {
  1099. $return[] = $course;
  1100. }
  1101. return $return;
  1102. }
  1103. /**
  1104. * Fills in course reporting data
  1105. *
  1106. * @param integer course code
  1107. * @param array $url_params additonal url parameters
  1108. * @param array $row the row information (the other columns)
  1109. * @return string html code
  1110. */
  1111. public static function course_tracking_filter($course_code, $url_params, $row)
  1112. {
  1113. $course_code = $row[0];
  1114. // the table header
  1115. $return = '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  1116. // database table definition
  1117. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1118. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  1119. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1120. // getting all the courses of the user
  1121. $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);";
  1122. $result = Database::query($sql);
  1123. $time_spent = 0;
  1124. $progress = 0;
  1125. $nb_progress_lp = 0;
  1126. $score = 0;
  1127. $nb_score_lp = 0;
  1128. $nb_messages = 0;
  1129. $nb_assignments = 0;
  1130. $last_login_date = false;
  1131. $total_score_obtained = 0;
  1132. $total_score_possible = 0;
  1133. $total_questions_answered = 0;
  1134. while ($row = Database::fetch_object($result)) {
  1135. // get time spent in the course and session
  1136. $time_spent += Tracking::get_time_spent_on_the_course($row->user_id, $course_code);
  1137. $progress_tmp = Tracking::get_avg_student_progress($row->user_id, $course_code, array(), null, true);
  1138. $progress += $progress_tmp[0];
  1139. $nb_progress_lp += $progress_tmp[1];
  1140. $score_tmp = Tracking :: get_avg_student_score($row->user_id, $course_code, array(), null, true);
  1141. if(is_array($score_tmp)) {
  1142. $score += $score_tmp[0];
  1143. $nb_score_lp += $score_tmp[1];
  1144. }
  1145. $nb_messages += Tracking::count_student_messages($row->user_id, $course_code);
  1146. $nb_assignments += Tracking::count_student_assignments($row->user_id, $course_code);
  1147. $last_login_date_tmp = Tracking :: get_last_connection_date_on_the_course ($row->user_id, $course_code, null, false);
  1148. if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned
  1149. $last_login_date = $last_login_date_tmp;
  1150. } else if($last_login_date_tmp != false && $last_login_date != false) { // TODO: Repeated previous condition. To be cleaned.
  1151. // Find the max and assign it to first_login_date
  1152. if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) {
  1153. $last_login_date = $last_login_date_tmp;
  1154. }
  1155. }
  1156. $exercise_results_tmp = MySpace::exercises_results($row->user_id, $course_code);
  1157. $total_score_obtained += $exercise_results_tmp['score_obtained'];
  1158. $total_score_possible += $exercise_results_tmp['score_possible'];
  1159. $total_questions_answered += $exercise_results_tmp['questions_answered'];
  1160. }
  1161. if($nb_progress_lp > 0) {
  1162. $avg_progress = round($progress / $nb_progress_lp, 2);
  1163. } else {
  1164. $avg_progress = 0;
  1165. }
  1166. if($nb_score_lp > 0) {
  1167. $avg_score = round($score / $nb_score_lp, 2);
  1168. } else {
  1169. $avg_score = '-';
  1170. }
  1171. if($last_login_date) {
  1172. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1173. } else {
  1174. $last_login_date = '-';
  1175. }
  1176. if($total_score_possible > 0) {
  1177. $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2);
  1178. } else {
  1179. $total_score_percentage = 0;
  1180. }
  1181. if($total_score_percentage > 0) {
  1182. $total_score = $total_score_obtained.'/'.$total_score_possible.' ('.$total_score_percentage.' %)';
  1183. } else {
  1184. $total_score = '-';
  1185. }
  1186. $return .= '<tr>';
  1187. // time spent in the course
  1188. $return .= ' <td style="width:164px;">'.api_time_to_hms($time_spent).'</td>';
  1189. // student progress in course
  1190. $return .= ' <td>'.$avg_progress.'</td>';
  1191. // student score
  1192. $return .= ' <td>'.$avg_score.'</td>';
  1193. // student messages
  1194. $return .= ' <td>'.$nb_messages.'</td>';
  1195. // student assignments
  1196. $return .= ' <td>'.$nb_assignments.'</td>';
  1197. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  1198. $return .= '<td width="105px;">'.$total_score.'</td>';
  1199. $return .= '<td>'.$total_questions_answered.'</td>';
  1200. // last connection
  1201. $return .= ' <td>'.$last_login_date.'</td>';
  1202. $return .= '</tr>';
  1203. $return .= '</table>';
  1204. return $return;
  1205. }
  1206. /**
  1207. * This function exports the table that we see in display_tracking_course_overview()
  1208. *
  1209. */
  1210. public static function export_tracking_course_overview()
  1211. {
  1212. // database table definition
  1213. $tbl_course_rel_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1214. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  1215. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1216. // the values of the sortable table
  1217. if ($_GET['tracking_course_overview_page_nr']) {
  1218. $from = $_GET['tracking_course_overview_page_nr'];
  1219. } else {
  1220. $from = 0;
  1221. }
  1222. if ($_GET['tracking_course_overview_column']) {
  1223. $orderby = $_GET['tracking_course_overview_column'];
  1224. } else {
  1225. $orderby = 0;
  1226. }
  1227. if ($_GET['tracking_course_overview_direction']) {
  1228. $direction = $_GET['tracking_course_overview_direction'];
  1229. } else {
  1230. $direction = 'ASC';
  1231. }
  1232. $course_data = MySpace::get_course_data_tracking_overview($from, 1000, $orderby, $direction);
  1233. $csv_content = array();
  1234. // the first line of the csv file with the column headers
  1235. $csv_row = array();
  1236. $csv_row[] = get_lang('Course', '');
  1237. $csv_row[] = get_lang('AvgTimeSpentInTheCourse', '');
  1238. $csv_row[] = get_lang('AvgStudentsProgress', '');
  1239. $csv_row[] = get_lang('AvgCourseScore', '');
  1240. $csv_row[] = get_lang('TotalNumberOfMessages', '');
  1241. $csv_row[] = get_lang('TotalNumberOfAssignments', '');
  1242. $csv_row[] = get_lang('TotalExercisesScoreObtained', '');
  1243. $csv_row[] = get_lang('TotalExercisesScorePossible', '');
  1244. $csv_row[] = get_lang('TotalExercisesAnswered', '');
  1245. $csv_row[] = get_lang('TotalExercisesScorePercentage', '');
  1246. $csv_row[] = get_lang('LatestLogin', '');
  1247. $csv_content[] = $csv_row;
  1248. // the other lines (the data)
  1249. foreach ($course_data as $key => $course) {
  1250. $course_code = $course[0];
  1251. $course_title = $course[1];
  1252. $csv_row = array();
  1253. $csv_row[] = $course_title;
  1254. // getting all the courses of the session
  1255. $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);";
  1256. $result = Database::query($sql);
  1257. $time_spent = 0;
  1258. $progress = 0;
  1259. $nb_progress_lp = 0;
  1260. $score = 0;
  1261. $nb_score_lp = 0;
  1262. $nb_messages = 0;
  1263. $nb_assignments = 0;
  1264. $last_login_date = false;
  1265. $total_score_obtained = 0;
  1266. $total_score_possible = 0;
  1267. $total_questions_answered = 0;
  1268. while ($row = Database::fetch_object($result)) {
  1269. // get time spent in the course and session
  1270. $time_spent += Tracking::get_time_spent_on_the_course($row->user_id, $course_code);
  1271. $progress_tmp = Tracking::get_avg_student_progress($row->user_id, $course_code, array(), null, true);
  1272. $progress += $progress_tmp[0];
  1273. $nb_progress_lp += $progress_tmp[1];
  1274. $score_tmp = Tracking :: get_avg_student_score($row->user_id, $course_code, array(), null, true);
  1275. if(is_array($score_tmp)) {
  1276. $score += $score_tmp[0];
  1277. $nb_score_lp += $score_tmp[1];
  1278. }
  1279. $nb_messages += Tracking::count_student_messages($row->user_id, $course_code);
  1280. $nb_assignments += Tracking::count_student_assignments($row->user_id, $course_code);
  1281. $last_login_date_tmp = Tracking :: get_last_connection_date_on_the_course ($row->user_id, $course_code, null, false);
  1282. if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned.
  1283. $last_login_date = $last_login_date_tmp;
  1284. } else if($last_login_date_tmp != false && $last_login_date == false) { // TODO: Repeated previous condition. To be cleaned.
  1285. // Find the max and assign it to first_login_date
  1286. if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) {
  1287. $last_login_date = $last_login_date_tmp;
  1288. }
  1289. }
  1290. $exercise_results_tmp = MySpace::exercises_results($row->user_id, $course_code);
  1291. $total_score_obtained += $exercise_results_tmp['score_obtained'];
  1292. $total_score_possible += $exercise_results_tmp['score_possible'];
  1293. $total_questions_answered += $exercise_results_tmp['questions_answered'];
  1294. }
  1295. if($nb_progress_lp > 0) {
  1296. $avg_progress = round($progress / $nb_progress_lp, 2);
  1297. } else {
  1298. $avg_progress = 0;
  1299. }
  1300. if($nb_score_lp > 0) {
  1301. $avg_score = round($score / $nb_score_lp, 2);
  1302. } else {
  1303. $avg_score = '-';
  1304. }
  1305. if($last_login_date) {
  1306. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1307. } else {
  1308. $last_login_date = '-';
  1309. }
  1310. if($total_score_possible > 0) {
  1311. $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2);
  1312. } else {
  1313. $total_score_percentage = 0;
  1314. }
  1315. // time spent in the course
  1316. $csv_row[] = api_time_to_hms($time_spent);
  1317. // student progress in course
  1318. $csv_row[] = $avg_progress;
  1319. // student score
  1320. $csv_row[] = $avg_score;
  1321. // student messages
  1322. $csv_row[] = $nb_messages;
  1323. // student assignments
  1324. $csv_row[] = $nb_assignments;
  1325. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  1326. $csv_row[] = $total_score_obtained;
  1327. $csv_row[] = $total_score_possible;
  1328. $csv_row[] = $total_questions_answered;
  1329. $csv_row[] = $total_score_percentage;
  1330. // last connection
  1331. $csv_row[] = $last_login_date;
  1332. $csv_content[] = $csv_row;
  1333. }
  1334. Export :: export_table_csv($csv_content, 'reporting_course_overview');
  1335. exit;
  1336. }
  1337. /**
  1338. * Display a sortable table that contains an overview of all the reporting progress of all sessions and all courses the user is subscribed to
  1339. * @author Guillaume Viguier <guillaume@viguierjust.com>
  1340. */
  1341. public static function display_tracking_session_overview()
  1342. {
  1343. //MySpace::display_user_overview_export_options();
  1344. $t_head = ' <table style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  1345. //$t_head .= ' <caption>'.get_lang('CourseInformation').'</caption>';
  1346. $t_head .= '<tr>';
  1347. $t_head .= ' <th width="155px" style="border-left:0;border-bottom:0"><span>'.get_lang('Course').'</span></th>';
  1348. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgTimeSpentInTheCourse'), 6, true).'</span></th>';
  1349. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgStudentsProgress'), 6, true).'</span></th>';
  1350. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('AvgCourseScore'), 6, true).'</span></th>';
  1351. //$t_head .= ' <th><div style="width:40px">'.get_lang('AvgExercisesScore').'</div></th>';
  1352. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfMessages'), 6, true).'</span></th>';
  1353. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalNumberOfAssignments'), 6, true).'</span></th>';
  1354. $t_head .= ' <th width="105px" style="border-bottom:0"><span>'.get_lang('TotalExercisesScoreObtained').'</span></th>';
  1355. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePossible').'</div></th>';
  1356. $t_head .= ' <th style="padding:0;border-bottom:0"><span>'.cut(get_lang('TotalExercisesAnswered'), 6, true).'</span></th>';
  1357. //$t_head .= ' <th><div>'.get_lang('TotalExercisesScorePercentage').'</div></th>';
  1358. //$t_head .= ' <th><div style="width:60px">'.get_lang('FirstLogin').'</div></th>';
  1359. $t_head .= ' <th style="padding:0;border-bottom:0;border-right:0;"><span>'.get_lang('LatestLogin').'</span></th>';
  1360. $t_head .= ' </tr></table>';
  1361. $addparams = array('view' => 'admin', 'display' => 'sessionoverview');
  1362. $table = new SortableTable('tracking_session_overview', array('MySpace','get_total_number_sessions'), array('MySpace','get_session_data_tracking_overview'), 1);
  1363. $table->additional_parameters = $addparams;
  1364. $table->set_header(0, '', false, null, array('style' => 'display: none'));
  1365. $table->set_header(1, get_lang('Session'), true, array('style' => 'font-size:8pt'), array('style' => 'font-size:8pt'));
  1366. $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;'));
  1367. $table->set_column_filter(2, array('MySpace', 'session_tracking_filter'));
  1368. $table->display();
  1369. }
  1370. /**
  1371. * Get the total number of sessions
  1372. *
  1373. * @return integer Total number of sessions
  1374. */
  1375. public static function get_total_number_sessions()
  1376. {
  1377. // database table definition
  1378. $main_session_table = Database :: get_main_table(TABLE_MAIN_SESSION);
  1379. return Database::count_rows($main_session_table);
  1380. }
  1381. /**
  1382. * Get data for the sessions
  1383. *
  1384. * @param int Inferior limit
  1385. * @param int Number of items to select
  1386. * @param string Column to order on
  1387. * @param string Order direction
  1388. * @return array Results
  1389. */
  1390. public static function get_session_data_tracking_overview($from, $number_of_items, $column, $direction)
  1391. {
  1392. //global $_configuration;
  1393. // database table definition
  1394. //$access_url_id = api_get_current_access_url_id();
  1395. //$tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  1396. $main_session_table = Database :: get_main_table(TABLE_MAIN_SESSION);
  1397. /*if ($_configuration['multiple_access_urls']) {
  1398. $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'";
  1399. }
  1400. global $export_csv;
  1401. if ($export_csv) {
  1402. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  1403. } else {
  1404. $is_western_name_order = api_is_western_name_order();
  1405. }*/
  1406. $sql = "SELECT id AS col0, name AS col1 FROM $main_session_table";
  1407. $sql .= " ORDER BY col$column $direction ";
  1408. $sql .= " LIMIT $from,$number_of_items";
  1409. $result = Database::query($sql);
  1410. $return = array ();
  1411. while ($session = Database::fetch_row($result)) {
  1412. $return[] = $session;
  1413. }
  1414. return $return;
  1415. }
  1416. /**
  1417. * Fills in session reporting data
  1418. *
  1419. * @param integer $user_id the id of the user
  1420. * @param array $url_params additonal url parameters
  1421. * @param array $row the row information (the other columns)
  1422. * @return string html code
  1423. */
  1424. public static function session_tracking_filter($session_id, $url_params, $row)
  1425. {
  1426. $session_id = $row[0];
  1427. // the table header
  1428. $return = '<table class="data_table" style="width: 100%;border:0;padding:0;border-collapse:collapse;table-layout: fixed">';
  1429. /*$return .= ' <tr>';
  1430. $return .= ' <th>'.get_lang('Course').'</th>';
  1431. $return .= ' <th>'.get_lang('AvgTimeSpentInTheCourse').'</th>';
  1432. $return .= ' <th>'.get_lang('AvgStudentsProgress').'</th>';
  1433. $return .= ' <th>'.get_lang('AvgCourseScore').'</th>';
  1434. $return .= ' <th>'.get_lang('AvgExercisesScore').'</th>';
  1435. $return .= ' <th>'.get_lang('AvgMessages').'</th>';
  1436. $return .= ' <th>'.get_lang('AvgAssignments').'</th>';
  1437. $return .= ' <th>'.get_lang('TotalExercisesScoreObtained').'</th>';
  1438. $return .= ' <th>'.get_lang('TotalExercisesScorePossible').'</th>';
  1439. $return .= ' <th>'.get_lang('TotalExercisesAnswered').'</th>';
  1440. $return .= ' <th>'.get_lang('TotalExercisesScorePercentage').'</th>';
  1441. $return .= ' <th>'.get_lang('FirstLogin').'</th>';
  1442. $return .= ' <th>'.get_lang('LatestLogin').'</th>';
  1443. $return .= ' </tr>';*/
  1444. // database table definition
  1445. $tbl_session_rel_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  1446. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  1447. $tbl_session_rel_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1448. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1449. // getting all the courses of the user
  1450. $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."';";
  1451. $result = Database::query($sql);
  1452. while ($row = Database::fetch_object($result)) {
  1453. $return .= '<tr>';
  1454. // course code
  1455. $return .= ' <td width="157px" >'.$row->title.'</td>';
  1456. // get the users in the course
  1457. $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."';";
  1458. $result_users = Database::query($sql);
  1459. $time_spent = 0;
  1460. $progress = 0;
  1461. $nb_progress_lp = 0;
  1462. $score = 0;
  1463. $nb_score_lp = 0;
  1464. $nb_messages = 0;
  1465. $nb_assignments = 0;
  1466. $last_login_date = false;
  1467. $total_score_obtained = 0;
  1468. $total_score_possible = 0;
  1469. $total_questions_answered = 0;
  1470. while($row_user = Database::fetch_object($result_users)) {
  1471. // get time spent in the course and session
  1472. $time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $row->code, $session_id);
  1473. $progress_tmp = Tracking::get_avg_student_progress($row_user->user_id, $row->code, array(), $session_id, true);
  1474. $progress += $progress_tmp[0];
  1475. $nb_progress_lp += $progress_tmp[1];
  1476. $score_tmp = Tracking :: get_avg_student_score($row_user->user_id, $row->code, array(), $session_id, true);
  1477. if(is_array($score_tmp)) {
  1478. $score += $score_tmp[0];
  1479. $nb_score_lp += $score_tmp[1];
  1480. }
  1481. $nb_messages += Tracking::count_student_messages($row_user->user_id, $row->code, $session_id);
  1482. $nb_assignments += Tracking::count_student_assignments($row_user->user_id, $row->code, $session_id);
  1483. $last_login_date_tmp = Tracking :: get_last_connection_date_on_the_course ($row_user->user_id, $row->code, $session_id, false);
  1484. if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned.
  1485. $last_login_date = $last_login_date_tmp;
  1486. } else if($last_login_date_tmp != false && $last_login_date != false) { // TODO: Repeated previous condition! To be cleaned.
  1487. // Find the max and assign it to first_login_date
  1488. if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) {
  1489. $last_login_date = $last_login_date_tmp;
  1490. }
  1491. }
  1492. $exercise_results_tmp = MySpace::exercises_results($row_user->user_id, $row->code, $session_id);
  1493. $total_score_obtained += $exercise_results_tmp['score_obtained'];
  1494. $total_score_possible += $exercise_results_tmp['score_possible'];
  1495. $total_questions_answered += $exercise_results_tmp['questions_answered'];
  1496. }
  1497. if($nb_progress_lp > 0) {
  1498. $avg_progress = round($progress / $nb_progress_lp, 2);
  1499. } else {
  1500. $avg_progress = 0;
  1501. }
  1502. if($nb_score_lp > 0) {
  1503. $avg_score = round($score / $nb_score_lp, 2);
  1504. } else {
  1505. $avg_score = '-';
  1506. }
  1507. if($last_login_date) {
  1508. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1509. } else {
  1510. $last_login_date = '-';
  1511. }
  1512. if($total_score_possible > 0) {
  1513. $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2);
  1514. } else {
  1515. $total_score_percentage = 0;
  1516. }
  1517. if($total_score_percentage > 0) {
  1518. $total_score = $total_score_obtained.'/'.$total_score_possible.' ('.$total_score_percentage.' %)';
  1519. } else {
  1520. $total_score = '-';
  1521. }
  1522. // time spent in the course
  1523. $return .= ' <td><div>'.api_time_to_hms($time_spent).'</div></td>';
  1524. // student progress in course
  1525. $return .= ' <td><div>'.$avg_progress.'</div></td>';
  1526. // student score
  1527. $return .= ' <td><div>'.$avg_score.'</div></td>';
  1528. // student messages
  1529. $return .= ' <td><div>'.$nb_messages.'</div></td>';
  1530. // student assignments
  1531. $return .= ' <td><div>'.$nb_assignments.'</div></td>';
  1532. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  1533. $return .= '<td width="105px;">'.$total_score.'</td>';
  1534. $return .= '<td>'.$total_questions_answered.'</td>';
  1535. // last connection
  1536. $return .= ' <td><div>'.$last_login_date.'</div></td>';
  1537. $return .= '<tr>';
  1538. }
  1539. $return .= '</table>';
  1540. return $return;
  1541. }
  1542. /**
  1543. * This function exports the table that we see in display_tracking_session_overview()
  1544. *
  1545. */
  1546. public static function export_tracking_session_overview()
  1547. {
  1548. // database table definition
  1549. $tbl_session_rel_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  1550. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  1551. $tbl_session_rel_course_rel_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1552. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  1553. // the values of the sortable table
  1554. if ($_GET['tracking_session_overview_page_nr']) {
  1555. $from = $_GET['tracking_session_overview_page_nr'];
  1556. } else {
  1557. $from = 0;
  1558. }
  1559. if ($_GET['tracking_session_overview_column']) {
  1560. $orderby = $_GET['tracking_session_overview_column'];
  1561. } else {
  1562. $orderby = 0;
  1563. }
  1564. if ($_GET['tracking_session_overview_direction']) {
  1565. $direction = $_GET['tracking_session_overview_direction'];
  1566. } else {
  1567. $direction = 'ASC';
  1568. }
  1569. $session_data = MySpace::get_session_data_tracking_overview($from, 1000, $orderby, $direction);
  1570. $csv_content = array();
  1571. // the first line of the csv file with the column headers
  1572. $csv_row = array();
  1573. $csv_row[] = get_lang('Session');
  1574. $csv_row[] = get_lang('Course', '');
  1575. $csv_row[] = get_lang('AvgTimeSpentInTheCourse', '');
  1576. $csv_row[] = get_lang('AvgStudentsProgress', '');
  1577. $csv_row[] = get_lang('AvgCourseScore', '');
  1578. $csv_row[] = get_lang('TotalNumberOfMessages', '');
  1579. $csv_row[] = get_lang('TotalNumberOfAssignments', '');
  1580. $csv_row[] = get_lang('TotalExercisesScoreObtained', '');
  1581. $csv_row[] = get_lang('TotalExercisesScorePossible', '');
  1582. $csv_row[] = get_lang('TotalExercisesAnswered', '');
  1583. $csv_row[] = get_lang('TotalExercisesScorePercentage', '');
  1584. $csv_row[] = get_lang('LatestLogin', '');
  1585. $csv_content[] = $csv_row;
  1586. // the other lines (the data)
  1587. foreach ($session_data as $key => $session) {
  1588. $session_id = $session[0];
  1589. $session_title = $session[1];
  1590. // getting all the courses of the session
  1591. $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."';";
  1592. $result = Database::query($sql);
  1593. while ($row = Database::fetch_object($result)) {
  1594. $csv_row = array();
  1595. $csv_row[] = $session_title;
  1596. $csv_row[] = $row->title;
  1597. // get the users in the course
  1598. $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."';";
  1599. $result_users = Database::query($sql);
  1600. $time_spent = 0;
  1601. $progress = 0;
  1602. $nb_progress_lp = 0;
  1603. $score = 0;
  1604. $nb_score_lp = 0;
  1605. $nb_messages = 0;
  1606. $nb_assignments = 0;
  1607. $last_login_date = false;
  1608. $total_score_obtained = 0;
  1609. $total_score_possible = 0;
  1610. $total_questions_answered = 0;
  1611. while($row_user = Database::fetch_object($result_users)) {
  1612. // get time spent in the course and session
  1613. $time_spent += Tracking::get_time_spent_on_the_course($row_user->user_id, $row->code, $session_id);
  1614. $progress_tmp = Tracking::get_avg_student_progress($row_user->user_id, $row->code, array(), $session_id, true);
  1615. $progress += $progress_tmp[0];
  1616. $nb_progress_lp += $progress_tmp[1];
  1617. $score_tmp = Tracking :: get_avg_student_score($row_user->user_id, $row->code, array(), $session_id, true);
  1618. if(is_array($score_tmp)) {
  1619. $score += $score_tmp[0];
  1620. $nb_score_lp += $score_tmp[1];
  1621. }
  1622. $nb_messages += Tracking::count_student_messages($row_user->user_id, $row->code, $session_id);
  1623. $nb_assignments += Tracking::count_student_assignments($row_user->user_id, $row->code, $session_id);
  1624. $last_login_date_tmp = Tracking :: get_last_connection_date_on_the_course ($row_user->user_id, $row->code, $session_id, false);
  1625. if($last_login_date_tmp != false && $last_login_date == false) { // TODO: To be cleaned.
  1626. $last_login_date = $last_login_date_tmp;
  1627. } else if($last_login_date_tmp != false && $last_login_date == false) { // TODO: Repeated previous condition. To be cleaned.
  1628. // Find the max and assign it to first_login_date
  1629. if(strtotime($last_login_date_tmp) > strtotime($last_login_date)) {
  1630. $last_login_date = $last_login_date_tmp;
  1631. }
  1632. }
  1633. $exercise_results_tmp = MySpace::exercises_results($row_user->user_id, $row->code, $session_id);
  1634. $total_score_obtained += $exercise_results_tmp['score_obtained'];
  1635. $total_score_possible += $exercise_results_tmp['score_possible'];
  1636. $total_questions_answered += $exercise_results_tmp['questions_answered'];
  1637. }
  1638. if($nb_progress_lp > 0) {
  1639. $avg_progress = round($progress / $nb_progress_lp, 2);
  1640. } else {
  1641. $avg_progress = 0;
  1642. }
  1643. if($nb_score_lp > 0) {
  1644. $avg_score = round($score / $nb_score_lp, 2);
  1645. } else {
  1646. $avg_score = '-';
  1647. }
  1648. if($last_login_date) {
  1649. $last_login_date = api_convert_and_format_date($last_login_date, DATE_FORMAT_SHORT, date_default_timezone_get());
  1650. } else {
  1651. $last_login_date = '-';
  1652. }
  1653. if($total_score_possible > 0) {
  1654. $total_score_percentage = round($total_score_obtained / $total_score_possible * 100, 2);
  1655. } else {
  1656. $total_score_percentage = 0;
  1657. }
  1658. if($total_score_percentage > 0) {
  1659. $total_score = $total_score_obtained.'/'.$total_score_possible.' ('.$total_score_percentage.' %)';
  1660. } else {
  1661. $total_score = '-';
  1662. }
  1663. // time spent in the course
  1664. $csv_row[] = api_time_to_hms($time_spent);
  1665. // student progress in course
  1666. $csv_row[] = $avg_progress;
  1667. // student score
  1668. $csv_row[] = $avg_score;
  1669. // student messages
  1670. $csv_row[] = $nb_messages;
  1671. // student assignments
  1672. $csv_row[] = $nb_assignments;
  1673. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  1674. $csv_row[] = $total_score_obtained;
  1675. $csv_row[] = $total_score_possible;
  1676. $csv_row[] = $total_questions_answered;
  1677. $csv_row[] = $total_score_percentage;
  1678. // last connection
  1679. $csv_row[] = $last_login_date;
  1680. $csv_content[] = $csv_row;
  1681. }
  1682. }
  1683. Export :: export_table_csv($csv_content, 'reporting_session_overview');
  1684. exit;
  1685. }
  1686. /**
  1687. * Get general information about the exercise performance of the user
  1688. * the total obtained score (all the score on all the questions)
  1689. * the maximum score that could be obtained
  1690. * the number of questions answered
  1691. * the success percentage
  1692. * @param integer $user_id the id of the user
  1693. * @param string $course_code the course code
  1694. * @return array
  1695. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1696. * @version Dokeos 1.8.6
  1697. * @since November 2008
  1698. */
  1699. public static function exercises_results($user_id, $course_code, $session_id = false)
  1700. {
  1701. $questions_answered = 0;
  1702. $sql = 'SELECT exe_result , exe_weighting
  1703. FROM '.Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES)."
  1704. WHERE exe_cours_id = '".Database::escape_string($course_code)."'
  1705. AND exe_user_id = '".intval($user_id)."'";
  1706. if($session_id !== false) {
  1707. $sql .= " AND session_id = '".$session_id."' ";
  1708. }
  1709. $result = Database::query($sql);
  1710. $score_obtained = 0;
  1711. $score_possible = 0;
  1712. $questions_answered = 0;
  1713. while ($row = Database::fetch_array($result)) {
  1714. $score_obtained += $row['exe_result'];
  1715. $score_possible += $row['exe_weighting'];
  1716. $questions_answered ++;
  1717. }
  1718. if ($score_possible != 0) {
  1719. $percentage = round(($score_obtained / $score_possible * 100), 2);
  1720. } else {
  1721. $percentage = null;
  1722. }
  1723. return array(
  1724. 'score_obtained' => $score_obtained,
  1725. 'score_possible' => $score_possible,
  1726. 'questions_answered' => $questions_answered,
  1727. 'percentage' => $percentage
  1728. );
  1729. }
  1730. /**
  1731. * This function exports the table that we see in display_tracking_user_overview()
  1732. *
  1733. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1734. * @version Dokeos 1.8.6
  1735. * @since October 2008
  1736. */
  1737. public static function export_tracking_user_overview()
  1738. {
  1739. // database table definitions
  1740. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1741. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  1742. $sort_by_first_name = api_sort_by_first_name();
  1743. // the values of the sortable table
  1744. if ($_GET['tracking_user_overview_page_nr']) {
  1745. $from = $_GET['tracking_user_overview_page_nr'];
  1746. } else {
  1747. $from = 0;
  1748. }
  1749. if ($_GET['tracking_user_overview_column']) {
  1750. $orderby = $_GET['tracking_user_overview_column'];
  1751. } else {
  1752. $orderby = 0;
  1753. }
  1754. if ($is_western_name_order != api_is_western_name_order() && ($orderby == 1 || $orderby == 2)) {
  1755. // Swapping the sorting column if name order for export is different than the common name order.
  1756. $orderby = 3 - $orderby;
  1757. }
  1758. if ($_GET['tracking_user_overview_direction']) {
  1759. $direction = $_GET['tracking_user_overview_direction'];
  1760. } else {
  1761. $direction = 'ASC';
  1762. }
  1763. $user_data = MySpace::get_user_data_tracking_overview($from, 1000, $orderby, $direction);
  1764. // the first line of the csv file with the column headers
  1765. $csv_row = array();
  1766. $csv_row[] = get_lang('OfficialCode');
  1767. if ($is_western_name_order) {
  1768. $csv_row[] = get_lang('FirstName', '');
  1769. $csv_row[] = get_lang('LastName', '');
  1770. } else {
  1771. $csv_row[] = get_lang('LastName', '');
  1772. $csv_row[] = get_lang('FirstName', '');
  1773. }
  1774. $csv_row[] = get_lang('LoginName');
  1775. $csv_row[] = get_lang('CourseCode');
  1776. // the additional user defined fields (only those that were selected to be exported)
  1777. $fields = UserManager::get_extra_fields(0, 50, 5, 'ASC');
  1778. if (is_array($_SESSION['additional_export_fields'])) {
  1779. foreach ($_SESSION['additional_export_fields'] as $key => $extra_field_export) {
  1780. $csv_row[] = $fields[$extra_field_export][3];
  1781. $field_names_to_be_exported[] = 'extra_'.$fields[$extra_field_export][1];
  1782. }
  1783. }
  1784. $csv_row[] = get_lang('AvgTimeSpentInTheCourse', '');
  1785. $csv_row[] = get_lang('AvgStudentsProgress', '');
  1786. $csv_row[] = get_lang('AvgCourseScore', '');
  1787. $csv_row[] = get_lang('AvgExercisesScore', '');
  1788. $csv_row[] = get_lang('AvgMessages', '');
  1789. $csv_row[] = get_lang('AvgAssignments', '');
  1790. $csv_row[] = get_lang('TotalExercisesScoreObtained', '');
  1791. $csv_row[] = get_lang('TotalExercisesScorePossible', '');
  1792. $csv_row[] = get_lang('TotalExercisesAnswered', '');
  1793. $csv_row[] = get_lang('TotalExercisesScorePercentage', '');
  1794. $csv_row[] = get_lang('FirstLogin', '');
  1795. $csv_row[] = get_lang('LatestLogin', '');
  1796. $csv_content[] = $csv_row;
  1797. // the other lines (the data)
  1798. foreach ($user_data as $key => $user) {
  1799. // getting all the courses of the user
  1800. $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".intval($user[4])."' AND relation_type<>".COURSE_RELATION_TYPE_RRHH." ";
  1801. $result = Database::query($sql);
  1802. while ($row = Database::fetch_row($result)) {
  1803. $csv_row = array();
  1804. // user official code
  1805. $csv_row[] = $user[0];
  1806. // user first|last name
  1807. $csv_row[] = $user[1];
  1808. // user last|first name
  1809. $csv_row[] = $user[2];
  1810. // user login name
  1811. $csv_row[] = $user[3];
  1812. // course code
  1813. $csv_row[] = $row[0];
  1814. // the additional defined user fields
  1815. $extra_fields = MySpace::get_user_overview_export_extra_fields($user[4]);
  1816. if (is_array($field_names_to_be_exported)) {
  1817. foreach ($field_names_to_be_exported as $key => $extra_field_export) {
  1818. $csv_row[] = $extra_fields[$extra_field_export];
  1819. }
  1820. }
  1821. // time spent in the course
  1822. $csv_row[] = api_time_to_hms(Tracking :: get_time_spent_on_the_course ($user[4], $row[0]));
  1823. // student progress in course
  1824. $csv_row[] = round(Tracking :: get_avg_student_progress ($user[4], $row[0]), 2);
  1825. // student score
  1826. $csv_row[] = round(Tracking :: get_avg_student_score ($user[4], $row[0]), 2);
  1827. // student tes score
  1828. $csv_row[] = round(Tracking :: get_avg_student_exercise_score ($user[4], $row[0]), 2);
  1829. // student messages
  1830. $csv_row[] = Tracking :: count_student_messages ($user[4], $row[0]);
  1831. // student assignments
  1832. $csv_row[] = Tracking :: count_student_assignments ($user[4], $row[0]);
  1833. // student exercises results
  1834. $exercises_results = MySpace::exercises_results($user[4], $row[0]);
  1835. $csv_row[] = $exercises_results['score_obtained'];
  1836. $csv_row[] = $exercises_results['score_possible'];
  1837. $csv_row[] = $exercises_results['questions_answered'];
  1838. $csv_row[] = $exercises_results['percentage'];
  1839. // first connection
  1840. $csv_row[] = Tracking :: get_first_connection_date_on_the_course ($user[4], $row[0]);
  1841. // last connection
  1842. $csv_row[] = strip_tags(Tracking :: get_last_connection_date_on_the_course ($user[4], $row[0]));
  1843. $csv_content[] = $csv_row;
  1844. }
  1845. }
  1846. Export :: export_table_csv($csv_content, 'reporting_user_overview');
  1847. exit;
  1848. }
  1849. /**
  1850. * Get data for courses list in sortable with pagination
  1851. * @return array
  1852. */
  1853. public static function get_course_data($from, $number_of_items, $column, $direction)
  1854. {
  1855. global $courses, $csv_content, $charset, $session_id;
  1856. // definition database tables
  1857. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  1858. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  1859. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  1860. $course_data = array();
  1861. $courses_code = array_keys($courses);
  1862. foreach ($courses_code as &$code) {
  1863. $code = "'$code'";
  1864. }
  1865. // get all courses with limit
  1866. $sql = "SELECT course.code as col1, course.title as col2
  1867. FROM $tbl_course course
  1868. WHERE course.code IN (".implode(',',$courses_code).")";
  1869. if (!in_array($direction, array('ASC','DESC'))) $direction = 'ASC';
  1870. $column = intval($column);
  1871. $from = intval($from);
  1872. $number_of_items = intval($number_of_items);
  1873. $sql .= " ORDER BY col$column $direction ";
  1874. $sql .= " LIMIT $from,$number_of_items";
  1875. $res = Database::query($sql);
  1876. while ($row_course = Database::fetch_row($res)) {
  1877. $course_code = $row_course[0];
  1878. $course_info = api_get_course_info($course_code);
  1879. $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;
  1880. // students directly subscribed to the course
  1881. if (empty($session_id)) {
  1882. $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'";
  1883. } else {
  1884. $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";
  1885. }
  1886. $rs = Database::query($sql);
  1887. $users = array();
  1888. while ($row = Database::fetch_array($rs)) { $users[] = $row['user_id']; }
  1889. if (count($users) > 0) {
  1890. $nb_students_in_course = count($users);
  1891. $avg_assignments_in_course = Tracking::count_student_assignments($users, $course_code, $session_id);
  1892. $avg_messages_in_course = Tracking::count_student_messages($users, $course_code, $session_id);
  1893. $avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code, array(), $session_id);
  1894. $avg_score_in_course = Tracking::get_avg_student_score($users, $course_code, array(), $session_id);
  1895. $avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code, 0, $session_id);
  1896. $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $course_code, $session_id);
  1897. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
  1898. if (is_numeric($avg_score_in_course)) {
  1899. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2);
  1900. }
  1901. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  1902. } else {
  1903. $avg_time_spent_in_course = null;
  1904. $avg_progress_in_course = null;
  1905. $avg_score_in_course = null;
  1906. $avg_score_in_exercise = null;
  1907. $avg_messages_in_course = null;
  1908. $avg_assignments_in_course = null;
  1909. }
  1910. $table_row = array();
  1911. $table_row[] = $row_course[1];
  1912. $table_row[] = $nb_students_in_course;
  1913. $table_row[] = $avg_time_spent_in_course;
  1914. $table_row[] = is_null($avg_progress_in_course) ? '' : $avg_progress_in_course.'%';
  1915. $table_row[] = is_null($avg_score_in_course) ? '' : $avg_score_in_course.'%';
  1916. $table_row[] = is_null($avg_score_in_exercise) ? '' : $avg_score_in_exercise.'%';
  1917. $table_row[] = $avg_messages_in_course;
  1918. $table_row[] = $avg_assignments_in_course;
  1919. //set the "from" value to know if I access the Reporting by the chamilo tab or the course link
  1920. $table_row[] = '<center><a href="../tracking/courseLog.php?cidReq='.$course_code.'&from=myspace&id_session='.$session_id.'">
  1921. <img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>
  1922. </center>';
  1923. $csv_content[] = array(
  1924. api_html_entity_decode($row_course[1], ENT_QUOTES, $charset),
  1925. $nb_students_in_course,
  1926. $avg_time_spent_in_course,
  1927. is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%',
  1928. is_null($avg_score_in_course) ? null : is_numeric($avg_score_in_course) ? $avg_score_in_course.'%' : $avg_score_in_course ,
  1929. is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%',
  1930. $avg_messages_in_course,
  1931. $avg_assignments_in_course,
  1932. );
  1933. $course_data[] = $table_row;
  1934. }
  1935. return $course_data;
  1936. }
  1937. /**
  1938. * get the numer of users of the platform
  1939. *
  1940. * @return integer
  1941. *
  1942. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1943. * @version Dokeos 1.8.6
  1944. * @since October 2008
  1945. */
  1946. public static function get_number_of_users_tracking_overview()
  1947. {
  1948. // database table definition
  1949. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  1950. return Database::count_rows($main_user_table);
  1951. }
  1952. /**
  1953. * get all the data for the sortable table of the reporting progress of all users and all the courses the user is subscribed to.
  1954. *
  1955. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1956. * @version Dokeos 1.8.6
  1957. * @since October 2008
  1958. */
  1959. public static function get_user_data_tracking_overview($from, $number_of_items, $column, $direction)
  1960. {
  1961. global $_configuration;
  1962. // database table definition
  1963. $access_url_id = api_get_current_access_url_id();
  1964. $tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  1965. $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
  1966. if ($_configuration['multiple_access_urls']) {
  1967. $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'";
  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. require_once api_get_path(LIBRARY_PATH).'pchart/pData.class.php';
  2538. require_once api_get_path(LIBRARY_PATH).'pchart/pChart.class.php';
  2539. require_once api_get_path(LIBRARY_PATH).'pchart/pCache.class.php';
  2540. if (empty($start_date)) { $start_date =""; }
  2541. if (empty($end_date)) { $end_date =""; }
  2542. if ($type == ""){ $type = 'day'; }
  2543. $main_year = $main_month_year = $main_day = array();
  2544. // get last 8 days/months
  2545. $last_days = 5;
  2546. $last_months = 3;
  2547. for ($i = $last_days; $i >= 0; $i--) {
  2548. $main_day[date ('d-m-Y', mktime () - $i * 3600 * 24)] = 0;
  2549. }
  2550. for ($i = $last_months; $i >= 0; $i--) {
  2551. $main_month_year[date ('m-Y', mktime () - $i * 30 * 3600 * 24)] = 0;
  2552. }
  2553. $i = 0;
  2554. if (is_array($sql_result) && count($sql_result) > 0) {
  2555. foreach ($sql_result as $key => $data) {
  2556. //creating the main array
  2557. $main_month_year[date('m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
  2558. $main_day[date('d-m-Y', $data['login'])] += float_format(($data['logout'] - $data['login']) / 60, 0);
  2559. if ($i > 500) {
  2560. break;
  2561. }
  2562. $i++;
  2563. }
  2564. switch ($type) {
  2565. case 'day':
  2566. $main_date = $main_day;
  2567. break;
  2568. case 'month':
  2569. $main_date = $main_month_year;
  2570. break;
  2571. case 'year':
  2572. $main_date = $main_year;
  2573. break;
  2574. }
  2575. // the nice graphics :D
  2576. $labels = array_keys($main_date);
  2577. if (count($main_date) == 1) {
  2578. $labels = $labels[0];
  2579. $main_date = $main_date[$labels];
  2580. }
  2581. $data_set = new pData();
  2582. $data_set->AddPoint($main_date, 'Q');
  2583. if (count($main_date)!= 1) {
  2584. $data_set->AddPoint($labels, 'Date');
  2585. }
  2586. $data_set->AddAllSeries();
  2587. $data_set->RemoveSerie('Date');
  2588. $data_set->SetAbsciseLabelSerie('Date');
  2589. $data_set->SetYAxisName(get_lang('Minutes', ''));
  2590. $graph_id = api_get_user_id().'AccessDetails'.api_get_course_id().$start_date.$end_date.$type;
  2591. $data_set->AddAllSeries();
  2592. $cache = new pCache();
  2593. // the graph id
  2594. $data = $data_set->GetData();
  2595. if ($cache->IsInCache($graph_id, $data_set->GetData())) {
  2596. //if (0) {
  2597. //if we already created the img
  2598. // echo 'in cache';
  2599. $img_file = $cache->GetHash($graph_id, $data_set->GetData());
  2600. } else {
  2601. // if the image does not exist in the archive/ folder
  2602. // Initialise the graph
  2603. $test = new pChart(760, 230);
  2604. //which schema of color will be used
  2605. $quant_resources = count($data[0]) - 1;
  2606. // Adding the color schemma
  2607. $test->loadColorPalette(api_get_path(LIBRARY_PATH).'pchart/palette/default.txt');
  2608. $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
  2609. $test->setGraphArea(70, 30, 680, 200);
  2610. $test->drawFilledRoundedRectangle(7, 7, 693, 223, 5, 240, 240, 240);
  2611. $test->drawRoundedRectangle(5, 5, 695, 225, 5, 230, 230, 230);
  2612. $test->drawGraphArea(255, 255, 255, TRUE);
  2613. $test->drawScale($data_set->GetData(), $data_set->GetDataDescription(), SCALE_START0, 150, 150, 150, TRUE, 0, 0);
  2614. $test->drawGrid(4, TRUE, 230, 230, 230, 50);
  2615. $test->setLineStyle(2);
  2616. // Draw the 0 line
  2617. $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 6);
  2618. $test->drawTreshold(0, 143, 55, 72, TRUE, TRUE);
  2619. if (count($main_date) == 1) {
  2620. //Draw a graph
  2621. echo '<strong>'.$labels.'</strong><br/>';
  2622. $test->drawBarGraph($data_set->GetData(), $data_set->GetDataDescription(), TRUE);
  2623. } else {
  2624. //Draw the line graph
  2625. $test->drawLineGraph($data_set->GetData(), $data_set->GetDataDescription());
  2626. $test->drawPlotGraph($data_set->GetData(), $data_set->GetDataDescription(), 3, 2, 255, 255, 255);
  2627. }
  2628. // Finish the graph
  2629. $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 8);
  2630. $test->setFontProperties(api_get_path(LIBRARY_PATH).'pchart/fonts/tahoma.ttf', 10);
  2631. $test->drawTitle(60, 22, get_lang('AccessDetails'), 50, 50, 50, 585);
  2632. //------------------
  2633. //echo 'not in cache';
  2634. $cache->WriteToCache($graph_id, $data_set->GetData(), $test);
  2635. ob_start();
  2636. $test->Stroke();
  2637. ob_end_clean();
  2638. $img_file = $cache->GetHash($graph_id, $data_set->GetData());
  2639. }
  2640. $foo_img = '<img src="'.api_get_path(WEB_ARCHIVE_PATH).$img_file.'">';
  2641. return $foo_img;
  2642. } else {
  2643. $foo_img = api_convert_encoding('<div id="messages" class="warning-message">'.get_lang('GraphicNotAvailable').'</div>','UTF-8');
  2644. return $foo_img;
  2645. }
  2646. }