示例#1
0
文件: model.php 项目: a2call/commsy
	function deleteGeneric($className,$condition,&$results=false) {
		if($records = $this->db->getRecords(MediabirdConfig::tableName($className,true),$condition,'','id')) {
			$affectedIds = array();
			
			foreach($records as $record) {
				$affectedIds []= intval($record->id);
			}
			
			$select = "id IN (".join(",",$affectedIds).")";
			
			//delete them
			if($this->db->deleteRecords(MediabirdConfig::tableName($className,true),$select)) {
				if($results!==false) {
					$results['removed'.$className.'Ids'] = $affectedIds;
				}
				return true;
			}
			else {
				return false;
			}
		}
		else {
			//no records affected, but that's okay
			return true;
		}
	}
示例#2
0
	function signout($args) {
		$results = array();

		//delete card locks associated with this user
		if ($this->auth->isAuthorized()) {
			$query="SELECT id,locked_by FROM ".MediabirdConfig::tableName('Content')." WHERE locked_by=$this->userId";
			if ($result = $this->db->getRecordSet($query)) {
				while($record = $this->db->fetchNextRecord($result)) {
					$record->locked_by = 0;
					$this->db->updateRecord(MediabirdConfig::tableName('Content',true),$record);
				}
			}

			if ( property_exists($args,'settings')) {
				$settings = MediabirdUtility::getArgNoSlashes($args->settings);

				if ($settingsJson = json_decode($settings)) {
					$settings = json_encode($settingsJson);

					$user = $this->db->getRecord(MediabirdConfig::tableName('User',true),"id=$this->userId");
					$user->settings = $settings;
					$this->db->updateRecord(MediabirdConfig::tableName('User',true),$user);
				}
			}

			$this->auth->restartSession();

			//notify back
			$results['r'] = MediabirdConstants::processed;
		}

		return $results;
	}
示例#3
0
文件: helper.php 项目: a2call/commsy
	/**
	 * 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;
	}
示例#4
0
	/**
	 * Send's an anonymous email to some address, preferably the Mediabird team or a user
	 * @param $to Id of user to which to deliver email
	 * @param $subject Subject of email
	 * @param $body Body of email
	 * @return bool Success
	 */
	function sendMail($to,$subject,$body) {
		if(!isset($this->db)) {
			return false;
		}
		
		if(!MediabirdConfig::$disable_mail) {
			$address=null;
			if($to==-1) {
				$address=MediabirdConfig::$webmaster_address;
			}
			else {
				$query="SELECT email FROM ".MediabirdConfig::tableName('User')." WHERE id=$to";
				if($result=$this->db->getRecordSet($query)) {
					$results=$this->db->recordToArray($this->db->fetchNextRecord($result));
					$address=$results['email'];
				}
			}
			if(isset($address)) {
				$headers = "From: ".MediabirdConfig::$no_reply_address."\r\n".
					"Reply-To: ".MediabirdConfig::$no_reply_address."\r\n".
					"X-Mailer: PHP/".phpversion();
				return mail($address, $subject, $body, $headers);	
			}
		}
		return false;
	}