/**
  * Construct user object
  *
  * This function is used to construct a user object, based on the user type.
  * Specifically, it creates an EfrontStudent, EfrontProfessor, EfrontAdministrator etc
  * An optional password verification may take place, if $password is specified
  * If $user is a login name, the function queries database. Alternatively, it may
  * use a prepared user array, which is mostly convenient when having to perform
  * multiple initializations
  * <br/>Example :
  * <code>
  * $user = EfrontUserFactory :: factory('jdoe');			//Use factory function to instantiate user object with login 'jdoe'
  * $userData = eF_getTableData("users", "*", "login='******'");
  * $user = EfrontUserFactory :: factory($userData[0]);	  //Use factory function to instantiate user object using prepared data
  * </code>
  *
  * @param mixed $user A user login or an array holding user data
  * @param string $password An optional password to check against
  * @param string $forceType Force the type to initialize the user, for example for when a professor accesses student.php as student
  * @return EfrontUser an object of a class extending EfrontUser
  * @since 3.5.0
  * @access public
  * @static
  */
 public static function factory($user, $password = false, $forceType = false)
 {
     if ((is_string($user) || is_numeric($user)) && eF_checkParameter($user, 'login')) {
         $result = eF_getTableData("users", "*", "login='******'");
         if (sizeof($result) == 0) {
             throw new EfrontUserException(_USERDOESNOTEXIST . ': ' . $user, EfrontUserException::USER_NOT_EXISTS);
         } else {
             if ($password !== false && $password != $result[0]['password']) {
                 throw new EfrontUserException(_INVALIDPASSWORDFORUSER . ': ' . $user, EfrontUserException::INVALID_PASSWORD);
             }
         }
         /*
         if (strcmp($result[0]['login'], $user) !=0){
         	throw new EfrontUserException(_USERDOESNOTEXIST.': '.$user, EfrontUserException :: USER_NOT_EXISTS);
         }
         */
         $user = $result[0];
     } elseif (!is_array($user)) {
         throw new EfrontUserException(_INVALIDLOGIN . ': ' . $user, EfrontUserException::INVALID_PARAMETER);
     }
     $forceType ? $userType = $forceType : ($userType = $user['user_type']);
     switch ($userType) {
         case 'administrator':
             $factory = new EfrontAdministrator($user, $password);
             break;
         case 'professor':
             $factory = new EfrontProfessor($user, $password);
             break;
         case 'student':
             $factory = new EfrontStudent($user, $password);
             break;
         default:
             throw new EfrontUserException(_INVALIDUSERTYPE . ': "' . $userType . '"', EfrontUserException::INVALID_TYPE);
             break;
     }
     if (G_VERSIONTYPE == 'enterprise') {
         #cpp#ifdef ENTERPRISE
         $factory->aspects['hcd'] = EfrontEmployeeFactory::factory($factory);
     }
     #cpp#endif
     return $factory;
 }
Esempio n. 2
0
             if ($currentUser->coreAccess['statistics'] != 'hidden') {
                 require_once "statistics.php";
             } else {
                 eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
             }
         }
     } elseif ($ctg == 'personal') {
         /**This part is used to display the user's personal information*/
         include "includes/personal.php";
     } elseif ($ctg == 'module_hcd') {
         include "module_hcd.php";
     } elseif ($ctg == "emails") {
         include "emails.php";
     } elseif ($ctg == 'users') {
         $_GET['op'] = "employees";
         $currentUser->aspects['hcd'] = EfrontEmployeeFactory::factory($currentUser->login);
         include "module_hcd.php";
     } elseif (sizeof($modules) > 0 && in_array($ctg, array_keys($module_ctgs))) {
         $module_mandatory = eF_getTableData("modules", "mandatory", "name = '" . $ctg . "'");
         if ($module_mandatory[0]['mandatory'] != 'false' || $GLOBALS['currentLesson']->options[$ctg]) {
             include G_MODULESPATH . $ctg . '/module.php';
             $smarty->assign("T_CTG_MODULE", $module_ctgs[$ctg]);
         }
     }
 }
 $fields_log = array('users_LOGIN' => $_SESSION['s_login'], 'timestamp' => time(), 'session_ip' => eF_encodeIP($_SERVER['REMOTE_ADDR']));
 /*
     if (isset($log_comments)) {                                         //If there is a $log_comments variable, it indicates the current action (i.e. the unit that the user saw)
         $fields_log['action']   = $ctg;
         $fields_log['comments'] = $log_comments;
         ($_SESSION['s_lessons_ID']) ? $fields_log['lessons_ID'] = $_SESSION['s_lessons_ID'] : $fields_log['lessons_ID'] = 0;
Esempio n. 3
0
$benchmark->set('init');
//Set headers in order to eliminate browser cache (especially IE's)'
header("Cache-Control: no-cache, must-revalidate");
// HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// Date in the past
require_once $path . "menu.class.php";
/*Check the user type. If the user is not valid, he cannot access this page, so exit*/
try {
    if (!isset($currentUser)) {
        $currentUser = EfrontUser::checkUserAccess();
    }
    $smarty->assign("T_CURRENT_USER", $currentUser);
    if (G_VERSIONTYPE == 'enterprise') {
        #cpp#ifdef ENTERPRISE
        $currentUser->aspects['hcd'] = EfrontEmployeeFactory::factory($_SESSION['s_login']);
        $employee = $currentUser->aspects['hcd'];
        $_SESSION['employee_type'] = $employee->getType();
    }
    #cpp#endif
    if ($_SESSION['s_lessons_ID'] && $currentUser instanceof EfrontLessonUser) {
        $userLessons = $currentUser->getLessons();
        $currentUser->applyRoleOptions($userLessons[$_SESSION['s_lessons_ID']]);
        //Initialize user's role options for this lesson
        $currentLesson = new EfrontLesson($_SESSION['s_lessons_ID']);
    } else {
        $currentUser->applyRoleOptions();
        //Initialize user's role options for this lesson
    }
} catch (Exception $e) {
    eF_redirect("index.php?ctg=expired");
     } else {
         #cpp#else
         //$result = eF_getTableData("users","*", $sql_query . " LIMIT 100");
         $result = eF_getTableData("users", "*", "users.archive=0 and " . $sql_query);
         $employees = $result;
     }
     #cpp#endif
     //pr($result);
 }
 if (G_VERSIONTYPE == 'enterprise') {
     #cpp#ifdef ENTERPRISE
     /* Get employee jobs */
     $recipients_array = array();
     foreach ($employees as $key => $employee) {
         $recipients_array[] = $employee['login'];
         $temp_employee = EfrontEmployeeFactory::factory($employee['login']);
         $employees[$key]['jobs'] = $temp_employee->getJobs();
         $employees[$key]['jobs_num'] = sizeof($employees[$key]['jobs']);
         //pr($employees[$key]['jobs']);
         // Calculate the size of the div for this employee
         $maxlen = 0;
         foreach ($employees[$key]['jobs'] as $job) {
             if (($tempsump = strlen($job['description']) + strlen($job['name'])) > $maxlen) {
                 $maxlen = $tempsum;
             }
         }
         $employees[$key]['div_size'] = ($maxlen + strlen(_ATBRANCH) + 2) * 15;
         // length of _ATBRANCH + 2 spaces - formula chars*size_per_char=20 / 2
         if ($employees[$key]['div_size'] > 400) {
             $employees[$key]['div_size'] = 400;
         }