Exemple #1
0
	function signin ($args) {
		$results = array();

		//check user and password

		$name = MediabirdUtility::getArgNoSlashes($args->name);
		$password = MediabirdUtility::getArgNoSlashes($args->password);
		$password=sha1(MediabirdConfig::$security_salt.$password);

		if ($userRecord = $this->db->getRecord(MediabirdConfig::tableName('User',true)," name='".$this->db->escape($name)."' AND password='******'")) {

			if ($userRecord->active == 1) {
				$user = $this->User->userFromRecord($userRecord);

				//save session time
				$_SESSION['mb_session_time'] = $user['lastLogin'];
				
				//update last login
				$time = time();
				$userRecord->last_login = $this->db->datetime($time);
				$this->db->updateRecord(MediabirdConfig::tableName('User',true),$userRecord);

				//save the session info for subsequent requests
				$this->auth->createSession($user['id']);

				$results['user'] = $user;
				$results['r'] = MediabirdConstants::processed;
			}
			else {
				$results['r'] = MediabirdConstants::disabled;
			}
		}
		else {
			$results['r'] = MediabirdConstants::wrongPass;
		}

		return $results;
	}
Exemple #2
0
	/**
	 * Determines new problems that user with user Id can answer to
	 * Returns problem object with: question, answer, questioner, card name, status date, topic name and group name 
	 * Sorts results by modification date, descending
	 * @param $userId Id of the user whose notes are to be determined
	 * @param int $fromDate Minimum date from which to return the problems
	 * @param MediabirdDbo $mediabirdDb Database connection to use
	 * @return object
	 */
	function findNewProblems($userId,$fromDate,$mediabirdDb) {
		
		//determine questions this user can access
		//and that are of question type 3
		
		$select = "question_mode=3 AND created>'".$mediabirdDb->datetime($fromDate)."' AND (user_id=$this->userId OR id IN (
			SELECT relation_id FROM ".MediabirdConfig::tableName("Relation")." WHERE relation_type='question' AND marker_id IN (
				SELECT id FROM ".MediabirdConfig::tableName("Marker")." WHERE shared=1 AND card_id IN (
					SELECT id FROM ".MediabirdConfig::tableName("Card")." WHERE topic_id IN (
						SELECT topic_id FROM ".MediabirdConfig::tableName("Right")." WHERE user_id=$this->userId AND mask>=".MediabirdTopicAccessConstants::allowViewingCards."
					)
				)
			)
		))";
		
		$problems = (array)null;
		$cards = (array)null;
		
		if($records = $mediabirdDb->getRecords(MediabirdConfig::tableName('Question',true),$selectProblem,'created DESC','id, question, user_id, modified, created')) {
			foreach ($records as $result) {
				//count answers to that question
				
				$problem = (object)null;
				$problem->id = intval($result->id);
				
				$problem->created = $problem->date = $mediabirdDb->timestamp($result->created);
				$problem->modified = $mediabirdDb->timestamp($result->modified);
				
				$problem->question = $result->question;
				
				$select = "question_id=$result->id";
				if($firstAnswerRecords = $mediabirdDb->getRecords(MediabirdConfig::tableName("Answer",true),$select,'created ASC','*', '', 1)) {
					$problem->answer = $firstAnswerRecords[0]->answer;
				
					if($resultQuestioner = $mediabirdDb->getRecord(MediabirdConfig::tableName('User',true),"id=$firstAnswerRecord->user_id")){
						$problem->questioner = $resultQuestioner->name;
					}
				}
				
				/**
				 * formerly given
				 * cardId, cardTitle, topicId, topicTitle, [groupName]
				 */
						 
				$problems[] = $problem;	
			}
					
		}	
		return $problems;
	}