Browse Source

Minor - Code style

Yannick Warnier 10 years ago
parent
commit
28757ba1a2
3 changed files with 180 additions and 203 deletions
  1. 131 148
      main/tracking/personnalLog.php
  2. 25 21
      main/tracking/userLog.php
  3. 24 34
      main/tracking/userlogCSV.php

+ 131 - 148
main/tracking/personnalLog.php

@@ -1,13 +1,13 @@
 <?php
 /* For licensing terms, see /license.txt */
 /**
-*	@author Thomas Depraetere
-*	@author Hugues Peeters
-*	@author Christophe Gesche
-*	@author Sebastien Piraux
-*
-*	@package chamilo.tracking
-*/
+ *	@author Thomas Depraetere
+ *	@author Hugues Peeters
+ *	@author Christophe Gesche
+ *	@author Sebastien Piraux
+ *
+ *	@package chamilo.tracking
+ */
 
 /**
  * Code
@@ -15,8 +15,8 @@
 // TODO: Is this file deprecated?
 
 /*
-		INIT SECTION
-*/
+ * INIT SECTION
+ */
 
 // name of the language file that needs to be included
 $language_file = "tracking";
@@ -64,7 +64,7 @@ api_display_tool_title($nameTools);
 // show all : view must be equal to the sum of all view values (1024+512+...+64)
 // show none : 0
 
-        echo "
+echo "
 <table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\" border=\"0\">
     <tr>
         <td class='minilink'>
@@ -73,16 +73,17 @@ api_display_tool_title($nameTools);
             </td>
         </tr>
         ";
-    if(empty($view)) $view ="0000000";
-
-    /***************************************************************************
-     *
-     *		Logins
-     *
-     ***************************************************************************/
-    $tempView = $view;
-    if($tempView[0] == '1')
-    {
+if (empty($view)) {
+    $view ="0000000";
+}
+
+/***************************************************************************
+ *
+ *		Logins
+ *
+ ***************************************************************************/
+$tempView = $view;
+if ($tempView[0] == '1') {
         $tempView[0] = '0';
         echo "
     <tr>
@@ -102,169 +103,151 @@ api_display_tool_title($nameTools);
         $results = StatsUtils::getManyResults1Col($sql);
         echo "
 <table width='100%' cellpadding='2' cellspacing='1' border='0' align='center'>";
-        if (is_array($results))
-        {
-
-            while ( list($key,$value) = each($results))
-            {
-                $beautifulDate = api_convert_and_format_date($value, null, date_default_timezone_get());
-                echo "
+    if (is_array($results)) {
+        while (list($key, $value) = each($results)) {
+            $beautifulDate = api_convert_and_format_date($value, null, date_default_timezone_get());
+            echo "
     <tr>
         <td class='secLine'>
             ".$beautifulDate."
         </td>
     </tr>";
 
-                if (!isset($previousDate)) {
-                    $previousDate = api_get_utc_datetime();
-                }
+            if (!isset($previousDate)) {
+                $previousDate = api_get_utc_datetime();
+            }
 
-                $sql = "SELECT access_tool, count(access_tool), c_id
-                            FROM $TABLETRACK_ACCESS
-                            WHERE
-                                access_user_id = " . $_user['user_id'] . " AND
-                                access_date > '".$value."' AND
-                                access_date < '".$previousDate."'
-                            GROUP BY access_tool, c_id
-                            ORDER BY c_id ASC";
+            $sql = "SELECT access_tool, count(access_tool), c_id
+                FROM $TABLETRACK_ACCESS
+                WHERE
+                    access_user_id = " . $_user['user_id'] . " AND
+                    access_date > '".$value."' AND
+                    access_date < '".$previousDate."'
+                GROUP BY access_tool, c_id
+                ORDER BY c_id ASC";
 
-                $results2 = StatsUtils::getManyResults3Col($sql);
+            $results2 = StatsUtils::getManyResults3Col($sql);
 
-                if (is_array($results2)) {
-                    echo "
+            if (is_array($results2)) {
+                echo "
     <tr>
         <td colspan='2'>
             <table width='50%' cellpadding='0' cellspacing='0' border='0' >";
 
-                    $previousCourse = "???";
-                    for($j = 0 ; $j < count($results2) ; $j++)
-                    {
+                $previousCourse = "???";
+                for ($j = 0; $j < count($results2); $j++) {
                         // if course is different, write the name of the course
-                        if($results2[$j][2] != $previousCourse)
-                        {
-                            echo "
-                <tr>
-                    <td colspan='2' width='100%' style='padding-left : 40px;'>
-                            ".$results2[$j][2]."
-                    </td>
-                </tr>";
-                        }
+                    if ($results2[$j][2] != $previousCourse) {
+                        echo "<tr>
+                      <td colspan='2' width='100%' style='padding-left : 40px;'>
+                              ".$results2[$j][2]."
+                        </td>
+                    </tr>";
+                    }
                         // if count != de 0 then display toolname et number of visits, else its a course visit
-                        if( $results2[$j][1] != 0 )
-                        {
+                    if ($results2[$j][1] != 0) {
                             echo "<tr>";
                             echo "<td width='70%' style='padding-left : 60px;'>".get_lang(ucfirst($results2[$j][0]))."</td>";
                             echo "<td width='30%' align='right'>".$results2[$j][1]." ".get_lang('Visits')."</td>";
                             echo "</tr>";
-                        }
-                        $previousCourse = $results2[$j][2];
                     }
-                    echo "</table>";
-                    echo "</td></tr>";
+                    $previousCourse = $results2[$j][2];
                 }
-                $previousDate = $value;
+                echo "</table>";
+                echo "</td></tr>";
             }
-
-        }
-        else
-        {
-            echo "<tr>";
-            echo "<td colspan='2' bgcolor='#eeeeee' align='center' >".get_lang('NoResult')."</td>";
-            echo"</tr>";
+            $previousDate = $value;
         }
-        echo "</table>";
-        echo "</td></tr>";
+
+    } else {
+        echo "<tr>";
+        echo "<td colspan='2' bgcolor='#eeeeee' align='center' >".get_lang('NoResult')."</td>";
+        echo"</tr>";
     }
-    else
-    {
-        $tempView[0] = '1';
-        echo "
+    echo "</table>";
+    echo "</td></tr>";
+} else {
+    $tempView[0] = '1';
+    echo "
             <tr>
                     <td valign='top'>
                     +<font color='#0000FF'>&nbsp;&nbsp;</font><a href='".api_get_self()."?view=".$tempView."' class='specialLink'>".get_lang('Logins')."</a>
                     </td>
             </tr>
         ";
-    }
-
-
-    /***************************************************************************
-     *
-     *		Exercices
-     *
-     ***************************************************************************/
-    /*
-    $tempView = $view;
-    if($view[1] == '1')
-    {
-        $tempView[1] = '0';
-        echo "
-            <tr>
-                    <td valign='top'>
-                    <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('ExercicesResults')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?view=".$tempView."'>".get_lang('Close')."</a>]
-                    </td>
-            </tr>
-        ";
-        echo " Ceci est amen  etre dplac vers la page de garde des exercices ";
-        $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, te.exe_date
-                    FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
-                    WHERE te.exe_user_id = '".$_user['user_id']."'
-                        AND te.exe_exo_id = ce.id
-                    ORDER BY te.c_id ASC, ce.title ASC, te.exe_date ASC";
+}
 
-        echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
-        $results = getManyResultsXCol($sql,4);
-        echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
-        echo "<tr>
-                <td class='secLine' width='60%'>
-                ".get_lang('ExercicesTitleExerciceColumn')."
-                </td>
-                <td class='secLine' width='20%'>
-                ".get_lang('Date')."
-                </td>
-                <td class='secLine' width='20%'>
-                ".get_lang('ExercicesTitleScoreColumn')."
-                </td>
-            </tr>";
-        if (is_array($results))
-        {
-            for($i = 0; $i < sizeof($results); $i++)
-            {
-                if( $results[$i][1] < ($results[$i][2]/2) )
-                    $scoreColor = "red";
-                elseif( $results[$i][1] > ($results[$i][2]/100*60) )
-                    $scoreColor = "green";
-                else
-                    $scoreColor = "#FF8C00";
-                echo "<tr>";
-                echo "<td class='content'>".$results[$i][0]."</td>";
-                echo "<td class='content'>".$results[$i][3]."</td>";
-                echo "<td valign='top' align='right' class='content'><font color=$scoreColor>".$results[$i][1]." / ".$results[$i][2]."</font></td>";
-                echo"</tr>";
-            }
 
-        }
-        else
-        {
+/***************************************************************************
+ *
+ *		Exercices
+ *
+ ***************************************************************************/
+/*
+$tempView = $view;
+if($view[1] == '1')
+{
+    $tempView[1] = '0';
+    echo "
+        <tr>
+            <td valign='top'>
+                <font color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('ExercicesResults')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?view=".$tempView."'>".get_lang('Close')."</a>]
+            </td>
+        </tr>
+    ";
+    echo " Ceci est amen  etre dplac vers la page de garde des exercices ";
+    $sql = "SELECT ce.title, te.exe_result , te.exe_weighting, te.exe_date
+            FROM $TABLECOURSE_EXERCICES AS ce , $TABLETRACK_EXERCICES AS te
+            WHERE te.exe_user_id = '".$_user['user_id']."'
+            AND te.exe_exo_id = ce.id
+            ORDER BY te.c_id ASC, ce.title ASC, te.exe_date ASC";
+
+    echo "<tr><td style='padding-left : 40px;padding-right : 40px;'>";
+    $results = getManyResultsXCol($sql,4);
+    echo "<table cellpadding='2' cellspacing='1' border='0' align='center'>";
+    echo "<tr>
+            <td class='secLine' width='60%'>
+            ".get_lang('ExercicesTitleExerciceColumn')."
+            </td>
+            <td class='secLine' width='20%'>
+            ".get_lang('Date')."
+            </td>
+            <td class='secLine' width='20%'>
+            ".get_lang('ExercicesTitleScoreColumn')."
+            </td>
+    </tr>";
+    if (is_array($results)) {
+        for ($i = 0; $i < sizeof($results); $i++) {
+            if ( $results[$i][1] < ($results[$i][2]/2) )
+                $scoreColor = "red";
+            elseif( $results[$i][1] > ($results[$i][2]/100*60) )
+                $scoreColor = "green";
+            else
+                $scoreColor = "#FF8C00";
             echo "<tr>";
-            echo "<td colspan='2' align='center'>".get_lang('NoResult')."</td>";
+            echo "<td class='content'>".$results[$i][0]."</td>";
+            echo "<td class='content'>".$results[$i][3]."</td>";
+            echo "<td valign='top' align='right' class='content'><font color=$scoreColor>".$results[$i][1]." / ".$results[$i][2]."</font></td>";
             echo"</tr>";
         }
-        echo "</table>";
-        echo "</td></tr>";
-
+    } else {
+        echo "<tr>";
+        echo "<td colspan='2' align='center'>".get_lang('NoResult')."</td>";
+        echo"</tr>";
     }
-    else
-    {
-        $tempView[1] = '1';
-        echo "
-            <tr>
-                    <td valign='top'>
-                    <font color='#0000FF'>+&nbsp;&nbsp;</font><a href='".api_get_self()."?view=".$tempView."' class='specialLink'>".get_lang('ExercicesResults')."</a>
-                    </td>
-            </tr>
-        ";
-    }
-    */
     echo "</table>";
+    echo "</td></tr>";
+
+} else {
+    $tempView[1] = '1';
+    echo "
+        <tr>
+                <td valign='top'>
+                <font color='#0000FF'>+&nbsp;&nbsp;</font><a href='".api_get_self()."?view=".$tempView."' class='specialLink'>".get_lang('ExercicesResults')."</a>
+                </td>
+        </tr>
+    ";
+}
+*/
+echo "</table>";
 Display::display_footer();

+ 25 - 21
main/tracking/userLog.php

@@ -117,14 +117,14 @@ $is_allowedToTrackEverybodyInCourse = $is_allowedToTrack; // allowed to track al
 <table width="100%" cellpadding="2" cellspacing="3" border="0">
 <?php
 // check if uid is tutor of this group
-if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
-    if(!$uInfo && !isset($uInfo) ) {
+if (( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
+    if (!$uInfo && !isset($uInfo)) {
         /*
         *		Display list of user of this group
          */
 
         echo "<h4>".get_lang('ListStudents')."</h4>";
-        if( $is_allowedToTrackEverybodyInCourse ) {
+        if ($is_allowedToTrackEverybodyInCourse) {
             // if user can track everybody : list user of course
 
             $sql = "SELECT count(user_id)
@@ -140,7 +140,7 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
         $userGroupNb = StatsUtils::getOneResult($sql);
         $step = 25; // number of student per page
         if ($userGroupNb > $step) {
-            if(!isset($offset)) {
+            if (!isset($offset)) {
                     $offset=0;
             }
 
@@ -169,8 +169,10 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
             $offset = 0;
         }
         echo $navLink;
-    //sanity check of integer vars
-    if (!settype($offset, 'integer') || !settype($step, 'integer')) die('Offset or step variables are not integers.');
+        //sanity check of integer vars
+        if (!settype($offset, 'integer') || !settype($step, 'integer')) {
+            die('Offset or step variables are not integers.');
+        }
         if ($is_allowedToTrackEverybodyInCourse) {
             // list of users in this course
             $sql = "SELECT u.user_id, u.firstname,u.lastname
@@ -187,11 +189,11 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
                     LIMIT $offset,$step";
         }
         $list_users = getManyResults3Col($sql);
-        echo 	"<table width='100%' cellpadding='2' cellspacing='1' border='0'>\n"
+        echo "<table width='100%' cellpadding='2' cellspacing='1' border='0'>\n"
                     ."<tr align='center' valign='top' bgcolor='#E6E6E6'>\n"
                     ."<td align='left'>",get_lang('UserName'),"</td>\n"
                     ."</tr>\n";
-        for ($i = 0 ; $i < sizeof($list_users) ; $i++) {
+        for ($i = 0; $i < sizeof($list_users); $i++) {
             echo    "<tr valign='top' align='center'>\n"
                     ."<td align='left'>"
                     ."<a href='".api_get_self()."?uInfo=",$list_users[$i][0],"'>"
@@ -205,11 +207,11 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
         // if uInfo is set
 
         /*
-        *		Informations about student uInfo
+         * Information about student uInfo
          */
         // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
         // another course, or group
-        if( $is_allowedToTrackEverybodyInCourse ) {
+        if ($is_allowedToTrackEverybodyInCourse) {
             // check if user is in this course
             $tracking_is_accepted = $is_course_member;
             $tracked_user_info = api_get_user_info($uInfo);
@@ -223,7 +225,9 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
                         AND u.user_id = '".intval($uInfo)."'";
             $query = Database::query($sql);
             $tracked_user_info = @Database::fetch_assoc($query);
-            if(is_array($tracked_user_info)) $tracking_is_accepted = true;
+            if (is_array($tracked_user_info)) {
+                $tracking_is_accepted = true;
+            }
         }
 
         if ($tracking_is_accepted) {
@@ -249,7 +253,7 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
                 </tr>
             ";
 
-            if(!isset($view)) {
+            if (!isset($view)) {
                 $view ='0000000';
             }
             //Logins
@@ -273,8 +277,8 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
         /*
          *		Scorm contents and Learning Path
          */
-        if(substr($view,5,1) == '1') {
-            $new_view = substr_replace($view,'0',5,1);
+        if (substr($view, 5, 1) == '1') {
+            $new_view = substr_replace($view, '0', 5, 1);
             echo "<tr>
                         <td valign='top'>
                         <font     color='#0000FF'>-&nbsp;&nbsp;&nbsp;</font><b>".get_lang('ScormAccess')."</b>&nbsp;&nbsp;&nbsp;[<a href='".api_get_self()."?view=".Security::remove_XSS($new_view)."&uInfo=".Security::remove_XSS($uInfo)."'>".get_lang('Close')."</a>]&nbsp;&nbsp;&nbsp;[<a href='userLogCSV.php?".api_get_cidreq()."&uInfo=".Security::remove_XSS($_GET['uInfo'])."&view=000001'>".get_lang('ExportAsCSV')."</a>]
@@ -324,12 +328,12 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
                                    </td>
                                    </tr>";
                             while ($ar3['status'] != '') {
-                            require_once '../newscorm/learnpathItem.class.php';
-                            $time = learnpathItem::getScormTimeFromParameter('php', $ar3['total_time']);
-                               echo "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>";
-                               echo "$title</td><td align=right>{$ar3['status']}</td><td align=right>{$ar3['score']}</td><td align=right>$time</td>";
-                               echo "</tr>";
-                               $ar3=Database::fetch_array($result3);
+                                require_once '../newscorm/learnpathItem.class.php';
+                                $time = learnpathItem::getScormTimeFromParameter('php', $ar3['total_time']);
+                                echo "<tr><td>&nbsp;&nbsp;&nbsp;</td><td>";
+                                echo "$title</td><td align=right>{$ar3['status']}</td><td align=right>{$ar3['score']}</td><td align=right>$time</td>";
+                                echo "</tr>";
+                                $ar3=Database::fetch_array($result3);
                             }
                         } else {
                             echo "<tr>";
@@ -351,7 +355,7 @@ if( ( $is_allowedToTrack || $is_allowedToTrackEverybodyInCourse )) {
             echo "</table>";
             echo "</td></tr>";
         } else {
-            $new_view = substr_replace($view,'1',5,1);
+            $new_view = substr_replace($view, '1', 5, 1);
             echo "
                 <tr>
                         <td valign='top'>

+ 24 - 34
main/tracking/userlogCSV.php

@@ -11,7 +11,7 @@
  * Code
  */
 
-/*	INIT SECTION */
+/* INIT SECTION */
 
 $uInfo = $_REQUEST['uInfo'];
 $view = $_REQUEST['view'];
@@ -120,7 +120,7 @@ $title_line = '';
 if (($is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) {
     if (!$uInfo && !isset($uInfo)) {
         /*
-        *		Display list of user of this group
+         * Display list of user of this group
          */
 
         if ($is_allowedToTrackEverybodyInCourse) {
@@ -158,36 +158,32 @@ if (($is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) {
 
         echo $navLink;
 
-        if (!settype($offset, 'integer') || !settype(
-                $step,
-                'integer'
-            )
-        ) {
+        if (!settype($offset, 'integer') || !settype($step, 'integer')) {
             die('Offset or step variables are not integers.');
         } //sanity check of integer vars
         if ($is_allowedToTrackEverybodyInCourse) {
             // list of users in this course
             $sql = "SELECT u.user_id, u.firstname,u.lastname
-                        FROM $TABLECOURSUSER cu , $TABLEUSER u
-                        WHERE cu.user_id = u.user_id AND cu.relation_type<>" . COURSE_RELATION_TYPE_RRHH . "
-                            AND cu.course_code = '$_cid'
-                        LIMIT $offset,$step";
+                FROM $TABLECOURSUSER cu , $TABLEUSER u
+                WHERE cu.user_id = u.user_id AND cu.relation_type<>" . COURSE_RELATION_TYPE_RRHH . "
+                AND cu.course_code = '$_cid'
+                LIMIT $offset,$step";
         } else {
             // list of users of this group
             $sql = "SELECT u.user_id, u.firstname,u.lastname
-                        FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
-                        WHERE gu.user_id = u.user_id
-                            AND gu.group_id = '$_gid'
-                        LIMIT $offset,$step";
+                FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
+                WHERE gu.user_id = u.user_id
+                AND gu.group_id = '$_gid'
+                LIMIT $offset,$step";
         }
         $list_users = getManyResults3Col($sql);
         for ($i = 0; $i < sizeof($list_users); $i++) {
+            // just sum $i up
         }
 
-    } else // if uInfo is set
-    {
+    } else { // if uInfo is set
         /*
-        *		Informations about student uInfo
+         * Informations about student uInfo
          */
         // these checks exists for security reasons, neither a prof nor a tutor can see statistics of a user from
         // another course, or group
@@ -199,10 +195,10 @@ if (($is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) {
         } else {
             // check if user is in the group of this tutor
             $sql = "SELECT u.firstname,u.lastname, u.email
-                        FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
-                        WHERE gu.user_id = u.user_id
-                            AND gu.group_id = '$_gid'
-                            AND u.user_id = '$uInfo'";
+                FROM $TABLECOURSE_GROUPSUSER gu , $TABLEUSER u
+                WHERE gu.user_id = u.user_id
+                AND gu.group_id = '$_gid'
+                AND u.user_id = '$uInfo'";
             $query = Database::query($sql);
             $tracked_user_info = @Database::fetch_assoc($query);
             if (is_array($tracked_user_info)) {
@@ -277,7 +273,7 @@ if (($is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) {
             $result=Database::query($sql);
             $ar=Database::fetch_array($result);
 
-          if (is_array($ar))
+            if (is_array($ar))
             {
                 while ($ar['id'] != '') {
                     $lp_title = stripslashes($ar['name']);
@@ -308,26 +304,21 @@ if (($is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) {
                        }
                     $ar=Database::fetch_array($result);
                 }
-
-            }
-            else
-            {
+            } else {
                 $noscorm=true;
             }
 
             if ($noscorm) {
                 $line=get_lang('NoResult');
             }
-         }
-        else
-        {
+         } else {
             $new_view = substr_replace($view,'1',5,1);
         }*/
 
     }
     /*
-    *		Export to a CSV file
-    *		force the browser to save the file instead of opening it
+     * Export to a CSV file
+     * force the browser to save the file instead of opening it
      */
 
     $len = strlen($title_line . $line);
@@ -360,7 +351,6 @@ if (($is_allowedToTrack || $is_allowedToTrackEverybodyInCourse)) {
     echo api_html_entity_decode($title_line, ENT_QUOTES, $charset);
     echo api_html_entity_decode($line, ENT_QUOTES, $charset);
     exit;
-} // not allowed
-else {
+} else { // not allowed
     api_not_allowed();
 }