Пример #1
0
        if ($userId !== false) {
            $editUserObj = MultiPort::findUser($userId);
        }
        break;
}
if (!is_null($editUserObj) && isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    $form = new UserProfileForm($languages);
    $form->fillWithPostData();
    if ($form->isValid()) {
        $user_layout = $_POST['layout'];
        $editUserObj->fillWithArrayData($_POST);
        // save extra datas if it has been forced
        if (isset($_POST['forceSaveExtra']) && $editUserObj->hasExtra()) {
            $editUserObj->setExtras($_POST);
        }
        MultiPort::setUser($editUserObj, array(), true, ADAUser::getExtraTableName());
        /**
         * Set the session user to the saved one if it's not
         * a switcher, that is not saving its own profile
         */
        if ($userObj->getType() != AMA_TYPE_SWITCHER) {
            $_SESSION['sess_userObj'] = $editUserObj;
        }
        // if registration form is saved ok and userObj is not a switcher,
        //  force a page reload to reflect the changes immediately
        $retArray = array("status" => "OK", "title" => $title, "msg" => translateFN('Scheda Anagrafica Salvata'), "reload" => true);
    } else {
        $retArray = array("status" => "ERROR", "title" => $title, "msg" => translateFN("I dati non sono validi"));
    }
} else {
    if (is_null($editUserObj)) {
Пример #2
0
 /**
  * remove_user_extraRow
  *
  * deletes a row from user extra datas
  *
  * @param int $user_id
  * @param int $extraTableId
  * @param string $extraTableClass
  * @return query result, either a PDOStatement or PDOException object
  *
  * @access public
  */
 public function remove_user_extraRow($user_id, $extraTableId, $extraTableClass)
 {
     $db =& $this->getConnection();
     if (AMA_DB::isError($db)) {
         return $db;
     }
     $tablesPrefix = ADAUser::getTablesPrefix();
     $delQry = "DELETE FROM " . $tablesPrefix . $extraTableClass . " WHERE " . $extraTableClass::getForeignKeyProperty() . "=? AND " . $extraTableClass::getKeyProperty() . "=?";
     $result = $this->queryPrepared($delQry, array($user_id, $extraTableId));
     return $result;
 }
Пример #3
0
  */
 // 		$tabsArray = array (
 // 				array (translateFN ("Anagrafica"), $form),
 // 				array (translateFN ("Sample Extra 1:1"), $extraForm),
 // 				array (translateFN ("Sample Extra 1:n"), 'oneToManyDataSample'),
 // 		);
 /**
  * If you want the $extraForm fields embedded in the $form tab instead
  * of being on its own tab, use the following:
  */
 // 		$tabsArray = array (
 // 				array (translateFN ("Anagrafica"), $form, 'withExtra'=>true),
 // 				array (translateFN ("Sample Extra 1:n"), 'oneToManyDataSample'),
 // 		);
 $data = "";
 $linkedTablesInADAUser = !is_null(ADAUser::getLinkedTables()) ? ADAUser::getLinkedTables() : array();
 for ($currTab = 0; $currTab < count($tabsArray); $currTab++) {
     // if is a subclass of FForm the it's a multirow element
     $doMultiRowTab = !is_subclass_of($tabsArray[$currTab][1], 'FForm');
     if ($doMultiRowTab === true) {
         $extraTableName = $tabsArray[$currTab][1];
         $extraTableFormClass = "User" . ucfirst($extraTableName) . "Form";
         /*
          * if extraTableName is not in the linked tables array or there's
          * no form classes for the extraTableName skip to the next iteration
          *
          * NOTE: there's no need to check for classes (data classes, not for ones)
          * existance here because if they did not existed you'd get an error while loggin in.
          */
         if (!in_array($extraTableName, $linkedTablesInADAUser) || !@(include_once ROOT_DIR . '/include/Forms/' . $extraTableFormClass . '.inc.php')) {
             continue;
Пример #4
0
 public static function findUserByUsername($username)
 {
     $common_dh = $GLOBALS['common_dh'];
     $id_user = $common_dh->find_user_from_username($username);
     if (AMA_Common_DataHandler::isError($id_user)) {
         if ($id_user->code == AMA_ERR_GET) {
             return NULL;
         }
         $errObj = new ADA_Error($user_type, 'An error occurred while retrieving user id in MultiPort::findUser');
         return NULL;
     }
     $user_type = $common_dh->get_user_type($id_user);
     if (AMA_Common_DataHandler::isError($user_type)) {
         $errObj = new ADA_Error($user_type, 'An error occurred while retrieving user type in MultiPort::findUser');
         return NULL;
     }
     /*
      * Tipi di utenti e cosa fare:
      *
      * utente di tipo autore:
      * ottieni i dati dalla tabella COMUNE.utente richiamando get_user_info()
      *
      */
     switch ($user_type) {
         case AMA_TYPE_AUTHOR:
             $user_dataAr = $common_dh->get_author($id_user);
             if (AMA_Common_DataHandler::isError($user_dataAr)) {
                 $errObj = new ADA_Error($user_dataAr, 'An error occurred while retrieving author data in MultiPort::finduser');
                 return NULL;
             }
             $userObj = new ADAAuthor($user_dataAr);
             $userObj->setUserId($id_user);
             $user_testersAr = $common_dh->get_testers_for_user($userObj->getId());
             if (AMA_Common_DataHandler::isError($user_testersAr)) {
                 $errObj = new ADA_Error($user_testersAr, 'An error occurred while retrieving user testers in MultiPort::finduser');
             }
             $userObj->setTesters($user_testersAr);
             return $userObj;
             break;
         case AMA_TYPE_ADMIN:
             $user_dataAr = $common_dh->get_user_info($id_user);
             if (AMA_Common_DataHandler::isError($user_dataAr)) {
                 $errObj = new ADA_Error($user_dataAr, 'An error occurred while retrieving admin data in MultiPort::finduser');
                 return NULL;
             }
             $userObj = new ADAAdmin($user_dataAr);
             $userObj->setUserId($id_user);
             return $userObj;
             break;
         case AMA_TYPE_STUDENT:
             $user_dataAr = $common_dh->get_student($id_user);
             if (AMA_Common_DataHandler::isError($user_dataAr)) {
                 $errObj = new ADA_Error($user_dataAr, 'An error occurred while retrieving user data in MultiPort::finduser');
                 return NULL;
             }
             $userObj = new ADAUser($user_dataAr);
             $userObj->setUserId($id_user);
             if (isset($id_course_instance) && DataValidator::is_uinteger($id_course_instance) !== FALSE) {
                 $userObj->set_course_instance_for_history($id_course_instance);
             } elseif (isset($_SESSION['sess_id_course_instance']) && DataValidator::is_uinteger($_SESSION['sess_id_course_instance']) !== FALSE) {
                 $userObj->set_course_instance_for_history($_SESSION['sess_id_course_instance']);
             }
             //return $userObj;
             // QUI DEVO VEDERE QUALI SONO I TESTER ASSOCIATI A QUESTO UTENTE.
             $user_testersAr = $common_dh->get_testers_for_user($userObj->getId());
             if (AMA_Common_DataHandler::isError($user_testersAr)) {
                 $errObj = new ADA_Error($user_testersAr, 'An error occurred while retrieving user testers in MultiPort::finduser');
             }
             $userObj->setTesters($user_testersAr);
             /**
              * get student extra data
              */
             if (!is_null($userObj) && $userObj instanceof ADAUser) {
                 /**
                  * @author giorgio 06/giu/2013
                  *
                  * load extra fields from DB, if we have some in this customization (i.e. User->hasExtra is true)
                  * Note that this MUST be done after user testers have been set.
                  *
                  */
                 if ($userObj->hasExtra()) {
                     $tester_dh = AMA_DataHandler::instance(MultiPort::getDSN($user_testersAr[0]));
                     $extraAr = $tester_dh->getExtraData($userObj);
                     if (!AMA_DB::isError($extraAr)) {
                         $userObj->setExtras($extraAr);
                     }
                     $tester_dh->disconnect();
                 }
             }
             return $userObj;
             break;
         case AMA_TYPE_SUPERTUTOR:
         case AMA_TYPE_TUTOR:
             $user_dataAr = $common_dh->get_tutor($id_user);
             if (AMA_Common_DataHandler::isError($user_dataAr)) {
                 $errObj = new ADA_Error($user_dataAr, 'An error occurred while retrieving practitioner data in MultiPort::finduser');
                 return NULL;
             }
             $userObj = new ADAPractitioner($user_dataAr);
             $userObj->setUserId($id_user);
             $user_testersAr = $common_dh->get_testers_for_user($userObj->getId());
             // TODO: here we have to read user's profile from the tester database
             if (AMA_Common_DataHandler::isError($user_testersAr)) {
                 $errObj = new ADA_Error($user_testersAr, 'An error occurred while retrieving user testers in MultiPort::finduser');
             }
             $userObj->setTesters($user_testersAr);
             //Load user profile info from default tester
             $tester = $userObj->getDefaultTester();
             $tester_dsn = self::getDSN($tester);
             if ($tester_dsn != NULL) {
                 $tester_dh = AMA_DataHandler::instance($tester_dsn);
                 $user_info = $tester_dh->get_tutor($id_user);
                 if (!AMA_DataHandler::isError($user_info)) {
                     $userObj->setProfile($user_info['profilo']);
                     $userObj->setFee($user_info['tariffa']);
                 }
                 $tester_dh->disconnect();
             }
             return $userObj;
             break;
         case AMA_TYPE_SWITCHER:
             $user_dataAr = $common_dh->get_user_info($id_user);
             if (AMA_Common_DataHandler::isError($user_dataAr)) {
                 $errObj = new ADA_Error($user_dataAr, 'An error occurred while retrieving author data in MultiPort::finduser');
                 return NULL;
             }
             $userObj = new ADASwitcher($user_dataAr);
             $userObj->setUserId($id_user);
             $user_testersAr = $common_dh->get_testers_for_user($userObj->getId());
             if (AMA_Common_DataHandler::isError($user_testersAr)) {
                 $errObj = new ADA_Error($user_testersAr, 'An error occurred while retrieving user testers in MultiPort::finduser');
             }
             $userObj->setTesters($user_testersAr);
             return $userObj;
             break;
         case AMA_TYPE_VISITOR:
         default:
             // FIXME: restituisco questo oggetto oppure alzo un errore?
             return NULL;
             break;
     }
 }
Пример #5
0
    public static function buildArrayFromPOST($className, $postData)
    {
        $retArray = array();
        $refclass = new ReflectionClass($className);
        foreach ($refclass->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
            $retArray[$property->name] = $postData[$property->name];
        }
        // force procteded property _isSaved
        if (isset($postData['_isSaved']) && $postData['_isSaved'] == 0) {
            $retArray['_isSaved'] = 0;
        }
        return empty($retArray) ? null : $retArray;
    }
    protected static function getFields($className)
    {
        $retArray = array();
        $refclass = new ReflectionClass($className);
        foreach ($refclass->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
            $retArray[] = $property->name;
        }
        return empty($retArray) ? null : $retArray;
    }
}
// include all tables as defined in ADAUser $_linkedTables array
if (is_array(ADAUser::getLinkedTables())) {
    foreach (ADAUser::getLinkedTables() as $linkedTable) {
        if (!empty($linkedTable)) {
            @(include_once ROOT_DIR . '/include/' . ucfirst($linkedTable) . '.class.inc.php');
        }
    }
}
Пример #6
0
 /**
  * adds a user whose data are coming from the login provider to the proper ADA DB
  * 
  * @param array $userArr array of user data to be added
  * @param function $successCallback callback function accepting a ADALoggableUser parameter to be called just before returning 
  * @param function $errorCallback callback function accepting no parameters to be called just before redirecting
  * 
  * @return ADALoggableUser|null (redirects if MultiPort::addUser fails)
  * 
  * @access public
  */
 public function addADAUser($userArr, $successCallback = null, $errorCallback = null)
 {
     /**
      * build user object
      */
     $userObj = new ADAUser($userArr);
     $userObj->setLayout('');
     $userObj->setType(isset($userArr['tipo']) ? $userArr['tipo'] : AMA_TYPE_STUDENT);
     $userObj->setStatus(ADA_STATUS_REGISTERED);
     $userObj->setPassword(sha1(time()));
     // force unguessable password
     /**
      * save the user in the appropriate provider
      */
     if (!MULTIPROVIDER && isset($GLOBALS['user_provider'])) {
         $regProvider = array($GLOBALS['user_provider']);
     } else {
         $regProvider = array(ADA_PUBLIC_TESTER);
     }
     $id_user = Multiport::addUser($userObj, $regProvider);
     if ($id_user < 0) {
         if (!is_null($errorCallback)) {
             call_user_func($errorCallback);
         }
         $message = translateFN('Impossibile procedere. Un utente con questi dati esiste?') . ' ' . urlencode($userObj->getEmail());
         header('Location:' . HTTP_ROOT_DIR . '/browsing/registration.php?message=' . $message);
         exit;
     } else {
         /**
          * reload user object just to double check
          */
         $retObj = MultiPort::findUserByUsername($userArr['username']);
         if (!is_null($successCallback)) {
             call_user_func($successCallback, $retObj);
         }
         return $retObj;
     }
 }
Пример #7
0
if (!isset($_SESSION['sess_user_language'])) {
    Translator::loadSupportedLanguagesInSession();
    $login_page_language_code = Translator::negotiateLoginPageLanguage();
    $_SESSION['sess_user_language'] = $login_page_language_code;
}
$supported_languages = Translator::getSupportedLanguages();
if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
    /*
     * Validate the user submitted data and proceed to the user registration.
     */
    $form = new UserRegistrationForm();
    $form->fillWithPostData();
    if ($form->isValid()) {
        $user_dataAr = $form->toArray();
        $user_dataAr['username'] = $_POST['email'];
        $userObj = new ADAUser($user_dataAr);
        $userObj->setLayout('');
        $userObj->setType(AMA_TYPE_STUDENT);
        $userObj->setStatus(ADA_STATUS_PRESUBSCRIBED);
        // Random password.
        $userObj->setPassword(sha1(time()));
        /**
         * giorgio 19/ago/2013
         * 
         * if it's not multiprovider, must register the user
         * in the selected tester only.
         * if it is multiprovider, must register the user
         * in the public tester only.
         */
        if (!MULTIPROVIDER && isset($GLOBALS['user_provider'])) {
            $regProvider = array($GLOBALS['user_provider']);
Пример #8
0
 $subscribers = count($usersToSubscribe);
 $admtypeAr = array(AMA_TYPE_ADMIN);
 $admList = $common_dh->get_users_by_type($admtypeAr);
 if (!AMA_DataHandler::isError($admList)) {
     $adm_uname = $admList[0]['username'];
 } else {
     $adm_uname = '';
     // ??? FIXME: serve un superadmin nel file di config?
 }
 $courseTitle = $courseObj->getTitle();
 foreach ($usersToSubscribe as $subscriber) {
     $canSubscribeUser = false;
     $userDataAr = explode(',', $subscriber);
     $subscriberObj = MultiPort::findUserByUsername(trim($userDataAr[2]));
     if ($subscriberObj == NULL) {
         $subscriberObj = new ADAUser(array('nome' => trim($userDataAr[0]), 'cognome' => trim($userDataAr[1]), 'email' => trim($userDataAr[2]), 'tipo' => AMA_TYPE_STUDENT, 'username' => trim($userDataAr[2]), 'stato' => ADA_STATUS_PRESUBSCRIBED, 'birthcity' => ''));
         $subscriberObj->setPassword(time());
         /**
          * @author giorgio 06/mag/2014 11:25:21
          * 
          * If it's not a multiprovider environment,
          * user must be subscribed to switcher's own
          * provider only.
          * User must be subscribed to the ADA_PUBLIC_TESTER
          * only in a multiprovider environment.
          */
         $provider_to_subscribeAr = array($sess_selected_tester);
         if (MULTIPROVIDER) {
             array_unshift($provider_to_subscribeAr, ADA_PUBLIC_TESTER);
         }
         $result = MultiPort::addUser($subscriberObj, $provider_to_subscribeAr);